diff --git a/mall-account/src/main/java/com/suisung/mall/account/service/impl/AccountUserBindGeTuiServiceImpl.java b/mall-account/src/main/java/com/suisung/mall/account/service/impl/AccountUserBindGeTuiServiceImpl.java index f687d011..ea4e71f2 100644 --- a/mall-account/src/main/java/com/suisung/mall/account/service/impl/AccountUserBindGeTuiServiceImpl.java +++ b/mall-account/src/main/java/com/suisung/mall/account/service/impl/AccountUserBindGeTuiServiceImpl.java @@ -36,20 +36,21 @@ public class AccountUserBindGeTuiServiceImpl extends BaseServiceImpl wrapper = new QueryWrapper() .eq("user_id", accountUserBindGeTui.getUserId()) - .eq("cid", cid) - .eq("os_type", osType); + .eq("os_type", osType) + .eq("status", CommonConstant.Enable) + .orderByDesc("id"); // 查询是否存在记录 - AccountUserBindGeTui existAccountUserBindGeTui = getOne(wrapper); + AccountUserBindGeTui existAccountUserBindGeTui = findOne(wrapper); if (existAccountUserBindGeTui == null) { - return this.add(accountUserBindGeTui); + return add(accountUserBindGeTui); } // 更新记录 @@ -65,7 +66,7 @@ public class AccountUserBindGeTuiServiceImpl extends BaseServiceImpl getActive(AccountUserBindGeTui accountUserBindGeTui) { QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq("user_id", accountUserBindGeTui.getUserId()).orderByDesc("updated_at"); + wrapper.eq("user_id", accountUserBindGeTui.getUserId()).orderByDesc("id"); return list(wrapper); } diff --git a/mall-common/src/main/java/com/suisung/mall/common/service/impl/UniCloudPushServiceImpl.java b/mall-common/src/main/java/com/suisung/mall/common/service/impl/UniCloudPushServiceImpl.java index 37bf2d33..0e1e7ccd 100644 --- a/mall-common/src/main/java/com/suisung/mall/common/service/impl/UniCloudPushServiceImpl.java +++ b/mall-common/src/main/java/com/suisung/mall/common/service/impl/UniCloudPushServiceImpl.java @@ -125,6 +125,9 @@ public class UniCloudPushServiceImpl implements UniCloudPushService { private HttpHeaders buildHeaders() { HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); + headers.add("Cookie", "aliyungf_tc=3a871d6048f74707aa0ac71c13f654c4d0fba0471c40625f4c120b6aca248dcf; acw_tc=ac11000117529234975193385ec4f96c1ae4ef16d52f0cde7fce5a0a95eb92"); // 新增:应用标识 + headers.add("Host", "fc-mp-39e3d50a-2d2b-415a-9664-2e48974bcfbd.next.bspapp.com"); // 新增:请求唯一标识 + return headers; } @@ -158,6 +161,7 @@ public class UniCloudPushServiceImpl implements UniCloudPushService { request.put("platform", platforms) .put("settings", new JSONObject().set("ttl", DEFAULT_TTL)); + log.debug("[推送服务] 请求参数: {}", request); return request; } @@ -168,23 +172,39 @@ public class UniCloudPushServiceImpl implements UniCloudPushService { private Pair processPushResponse(ResponseEntity response) { if (response.getStatusCode() != HttpStatus.OK) { log.error("[推送服务] 请求失败, 状态码: {}", response.getStatusCodeValue()); - return Pair.of(false, "推送请求失败"); + return Pair.of(false, "推送请求失败: 状态码异常"); } String body = response.getBody(); if (StrUtil.isBlank(body)) { log.warn("[推送服务] 响应体为空"); - return Pair.of(false, "推送响应为空"); + return Pair.of(false, "推送请求失败: 响应体为空"); } try { JSONObject json = JSONUtil.parseObj(body); - log.info("[推送服务] 推送成功, 响应: {}", json.toStringPretty()); + log.info("[推送服务] 原始响应: {}", json.toStringPretty()); - return Pair.of(true, json.getJSONObject("data").toString()); + // 解析标准响应字段 + Integer errCode = json.getInt("errCode", -1); + String errMsg = json.getStr("errMsg", "未知错误"); + JSONObject data = json.getJSONObject("data"); + + if (errCode != 0) { + log.error("[推送服务] 业务失败 - code:{}, msg:{}", errCode, errMsg); + return Pair.of(false, String.format("推送失败: %s [code-%d]", errMsg, errCode)); + } + + if (data == null) { + log.warn("[推送服务] 成功但data为空"); + return Pair.of(true, "推送成功"); + } + + log.info("[推送服务] 推送成功 - data:{}", data); + return Pair.of(true, "推送成功"); } catch (Exception e) { - log.error("[推送服务] 响应解析异常: {}", e.getMessage(), e); - return Pair.of(false, "响应解析失败"); + log.error("[推送服务] 响应解析异常 - raw:{}, error:{}", body, e.getMessage(), e); + return Pair.of(false, "推送请求失败: 响应解析异常"); } } } diff --git a/mall-shop/src/main/java/com/suisung/mall/shop/lakala/controller/mobile/LakalaController.java b/mall-shop/src/main/java/com/suisung/mall/shop/lakala/controller/mobile/LakalaController.java index 976b13cc..03e09861 100644 --- a/mall-shop/src/main/java/com/suisung/mall/shop/lakala/controller/mobile/LakalaController.java +++ b/mall-shop/src/main/java/com/suisung/mall/shop/lakala/controller/mobile/LakalaController.java @@ -78,8 +78,8 @@ public class LakalaController extends BaseControllerImpl { @PostMapping(value = "/unipush/testcase") public Object pushMessageTestCase(@RequestBody JSONObject paramsJSON) { // 测试推送消息 - List clientIds = JSONUtil.toList(paramsJSON.getJSONArray("clientIds"), String.class); - return pushMessageService.sendMessage(clientIds, paramsJSON.getStr("title"), paramsJSON.getStr("content"), paramsJSON.getJSONObject("payload")); + List pushClientid = JSONUtil.toList(paramsJSON.getJSONArray("push_clientid"), String.class); + return pushMessageService.sendMessage(pushClientid, paramsJSON.getStr("title"), paramsJSON.getStr("content"), paramsJSON.getJSONObject("payload")); } diff --git a/mall-shop/src/main/java/com/suisung/mall/shop/message/service/impl/PushMessageServiceImpl.java b/mall-shop/src/main/java/com/suisung/mall/shop/message/service/impl/PushMessageServiceImpl.java index f924a5b2..7fe28e85 100644 --- a/mall-shop/src/main/java/com/suisung/mall/shop/message/service/impl/PushMessageServiceImpl.java +++ b/mall-shop/src/main/java/com/suisung/mall/shop/message/service/impl/PushMessageServiceImpl.java @@ -56,20 +56,20 @@ public class PushMessageServiceImpl implements PushMessageService { * - 通过uniCloudPushService批量发送 * - 记录详细日志便于问题追踪 * - * @param clientIds 客户端ID列表 (必填) - * @param title 消息标题 (可选) - * @param content 消息内容 (必填) - * @param payload 附加数据 (可为空) + * @param pushClientId 客户端ID列表 (必填) + * @param title 消息标题 (可选) + * @param content 消息内容 (必填) + * @param payload 附加数据 (可为空) * @return CompletableFuture> * - Boolean: 发送是否成功 * - String: 成功为"", 失败为错误信息 */ @Async("asyncExecutor") @Override - public CompletableFuture> sendMessage(List clientIds, String title, String content, JSONObject payload) { + public CompletableFuture> sendMessage(List pushClientId, String title, String content, JSONObject payload) { // 参数校验 - if (CollectionUtils.isEmpty(clientIds) || StrUtil.isBlank(content)) { - log.warn("推送消息参数无效 - clientIds:{}, title:{}, content:{}", clientIds, title, content); + if (CollectionUtils.isEmpty(pushClientId) || StrUtil.isBlank(content)) { + log.warn("推送消息参数无效 - push_clientid:{}, title:{}, content:{}", pushClientId, title, content); return CompletableFuture.completedFuture(Pair.of(false, "推送消息参数无效")); } @@ -78,21 +78,21 @@ public class PushMessageServiceImpl implements PushMessageService { title = "小发同城:您有新的消息"; } - log.debug("开始发送推送消息 - clientIds:{}, title:{}", clientIds, title); - Pair result = uniCloudPushService.sendPushMessageBatch(clientIds, title, content, payload); + log.debug("开始发送推送消息 - push_clientid:{}, title:{}, content:{}, payload:{}", pushClientId, title, content, payload); + Pair result = uniCloudPushService.sendPushMessageBatch(pushClientId, title, content, payload); if (!result.getFirst()) { - log.error("推送消息失败 - clientIds:{}, error:{}", clientIds, result.getSecond()); + log.error("推送消息失败 - push_clientid:{}, error:{}", pushClientId, result.getSecond()); } else { - log.debug("推送消息成功 - clientIds:{}", clientIds); + log.debug("推送消息成功 - push_clientid:{}", pushClientId); } return CompletableFuture.completedFuture(result); } catch (Exception e) { String errorMsg = "推送消息系统异常"; - log.error("{} - clientIds:{}, title:{}, content:{}, payload:{}", - errorMsg, clientIds, title, content, payload, e); + log.error("{} - push_clientid:{}, title:{}, content:{}, payload:{}", + errorMsg, pushClientId, title, content, payload, e); return CompletableFuture.completedFuture(Pair.of(false, errorMsg)); } }