推送绑定唯一值修改

This commit is contained in:
Jack 2025-07-19 22:25:26 +08:00
parent 341342c8b9
commit 5644324252
4 changed files with 49 additions and 28 deletions

View File

@ -36,20 +36,21 @@ public class AccountUserBindGeTuiServiceImpl extends BaseServiceImpl<UserDeviceB
return false;
}
// 获取操作系统类型默认为0
Integer osType = accountUserBindGeTui.getOsType() != null ? accountUserBindGeTui.getOsType() : 0;
// 获取操作系统类型默认为1 手机系统类型 1-Android2-iOS3-微信小程序
Integer osType = accountUserBindGeTui.getOsType() != null ? accountUserBindGeTui.getOsType() : 1;
String cid = accountUserBindGeTui.getCid();
// 构建查询条件
QueryWrapper<AccountUserBindGeTui> wrapper = new QueryWrapper<AccountUserBindGeTui>()
.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<UserDeviceB
@Override
public List<AccountUserBindGeTui> getActive(AccountUserBindGeTui accountUserBindGeTui) {
QueryWrapper<AccountUserBindGeTui> wrapper = new QueryWrapper<>();
wrapper.eq("user_id", accountUserBindGeTui.getUserId()).orderByDesc("updated_at");
wrapper.eq("user_id", accountUserBindGeTui.getUserId()).orderByDesc("id");
return list(wrapper);
}

View File

@ -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<Boolean, String> processPushResponse(ResponseEntity<String> 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, "推送请求失败: 响应解析异常");
}
}
}

View File

@ -78,8 +78,8 @@ public class LakalaController extends BaseControllerImpl {
@PostMapping(value = "/unipush/testcase")
public Object pushMessageTestCase(@RequestBody JSONObject paramsJSON) {
// 测试推送消息
List<String> clientIds = JSONUtil.toList(paramsJSON.getJSONArray("clientIds"), String.class);
return pushMessageService.sendMessage(clientIds, paramsJSON.getStr("title"), paramsJSON.getStr("content"), paramsJSON.getJSONObject("payload"));
List<String> pushClientid = JSONUtil.toList(paramsJSON.getJSONArray("push_clientid"), String.class);
return pushMessageService.sendMessage(pushClientid, paramsJSON.getStr("title"), paramsJSON.getStr("content"), paramsJSON.getJSONObject("payload"));
}

View File

@ -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<Pair < Boolean, String>>
* - Boolean: 发送是否成功
* - String: 成功为"", 失败为错误信息
*/
@Async("asyncExecutor")
@Override
public CompletableFuture<Pair<Boolean, String>> sendMessage(List<String> clientIds, String title, String content, JSONObject payload) {
public CompletableFuture<Pair<Boolean, String>> sendMessage(List<String> 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<Boolean, String> result = uniCloudPushService.sendPushMessageBatch(clientIds, title, content, payload);
log.debug("开始发送推送消息 - push_clientid:{}, title:{}, content:{}, payload:{}", pushClientId, title, content, payload);
Pair<Boolean, String> 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));
}
}