feat(emergency): 宣教推送IM消息改为独立方法sendGroupMsgArticle,不影响已有业务
- 新增 TencentCloudImUtil.sendGroupMsgArticle: From_Account生效、不覆盖businessID、fromAdmin动态判断 - 新增 TXController.sendGroupMsgArticle / IMHelloApi.sendGroupMsgArticle - FirstAidPushServiceImpl 推送人改为当前登录用户,调用新方法
This commit is contained in:
@@ -48,6 +48,9 @@ public interface IMHelloApi {
|
||||
@PostMapping(value = "/wnapp/sendGroupMsg")
|
||||
IMGroupMsgResDO sendGroupMsg(@RequestBody @Validated ImGroupMsgTextReqDO imGroupMsgTextReqDO);
|
||||
|
||||
@PostMapping(value = "/wnapp/sendGroupMsgArticle")
|
||||
IMGroupMsgResDO sendGroupMsgArticle(@RequestBody @Validated ImGroupMsgTextReqDO imGroupMsgTextReqDO);
|
||||
|
||||
@PostMapping(value = "/wnapp/sendGroupMsgTextNew")
|
||||
IMGroupMsgResDO sendGroupMsgTextNew(@RequestBody @Validated ImGroupMsgTextReqDO imGroupMsgTextReqDO);
|
||||
|
||||
|
||||
@@ -247,6 +247,14 @@ public class TXController {
|
||||
}
|
||||
|
||||
|
||||
@Operation(summary = "文章推送群消息(宣教推送专用)", description = "发送方由调用方指定,不覆盖businessID")
|
||||
@PostMapping("/sendGroupMsgArticle")
|
||||
public IMGroupMsgResDO sendGroupMsgArticle(@RequestBody @Validated ImGroupMsgTextReqDO imGroupMsgTextReqDO) {
|
||||
|
||||
return tencentCloudImUtil.sendGroupMsgArticle(imGroupMsgTextReqDO);
|
||||
}
|
||||
|
||||
|
||||
@Operation(summary = "用户发送群消息", description = "用户发送群消息")
|
||||
@PostMapping("/sendGroupMsgTextNew")
|
||||
public IMGroupMsgResDO sendGroupMsgTextNew(@RequestBody @Validated ImGroupMsgTextReqDO imGroupMsgTextReqDO) {
|
||||
|
||||
@@ -239,7 +239,7 @@ public class TencentCloudImUtil {
|
||||
param.put("GroupId", imGroupMsgTextReqVO.getGroupId());
|
||||
param.put("MsgPriority", "High");
|
||||
param.put("Random", this.getRandom());
|
||||
param.put("From_Account", imGroupMsgTextReqVO.getFromUserId());
|
||||
// param.put("From_Account", imGroupMsgTextReqVO.getFromUserId());
|
||||
param.put("MsgRandom", this.getRandomNum(8));
|
||||
param.put("MsgTimeStamp", DateUtils.dateToUnixLong(new Date()));
|
||||
param.put("CloudCustomData", new JSONObject().fluentPut("fromAdmin", true).toJSONString());
|
||||
@@ -272,6 +272,58 @@ public class TencentCloudImUtil {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 发送文章推送群消息(宣教推送专用)
|
||||
* <p>
|
||||
* 与 sendGroupMsgText 的区别:
|
||||
* 1. From_Account 由调用方指定,不写死为 administrator
|
||||
* 2. 不覆盖 businessID,保留调用方传入的业务标识
|
||||
* 3. CloudCustomData.fromAdmin 根据实际发送人动态设置
|
||||
*
|
||||
* @param req 消息请求
|
||||
* @return IMGroupMsgResDO
|
||||
*/
|
||||
public IMGroupMsgResDO sendGroupMsgArticle(ImGroupMsgTextReqDO req) {
|
||||
IMGroupMsgResDO res = new IMGroupMsgResDO();
|
||||
String url = HTTPS_URL_PREFIX + "v4/group_open_http_svc/send_group_msg";
|
||||
|
||||
String fromUserId = req.getFromUserId();
|
||||
boolean isAdmin = "administrator".equals(fromUserId);
|
||||
|
||||
JSONObject param = new JSONObject();
|
||||
param.put("GroupId", req.getGroupId());
|
||||
param.put("MsgPriority", "High");
|
||||
param.put("Random", this.getRandom());
|
||||
param.put("From_Account", fromUserId);
|
||||
param.put("MsgRandom", this.getRandomNum(8));
|
||||
param.put("MsgTimeStamp", DateUtils.dateToUnixLong(new Date()));
|
||||
param.put("CloudCustomData", new JSONObject().fluentPut("fromAdmin", isAdmin).toJSONString());
|
||||
|
||||
JSONObject jj = JSONObject.parseObject(req.getContent());
|
||||
try {
|
||||
JSONObject item = new JSONObject();
|
||||
JSONObject msgContentData = new JSONObject();
|
||||
msgContentData.put("Data", jj.toString());
|
||||
item.put("MsgType", ImSendEnum.TIMCustomElem.getValue());
|
||||
item.put("MsgContent", msgContentData);
|
||||
JSONArray msgBody = new JSONArray();
|
||||
msgBody.add(item);
|
||||
param.put("MsgBody", msgBody);
|
||||
String jsonStr = HttpUtil.doPost(buildRequestUrl(url), param.toString());
|
||||
if (StringUtils.isNotEmpty(jsonStr)) {
|
||||
JSONObject jsonObj = JSONObject.parseObject(jsonStr);
|
||||
if (jsonObj.containsKey("ErrorCode") && jsonObj.getInteger("ErrorCode") == 0) {
|
||||
log.info("=========={}==========", "文章推送发送成功!");
|
||||
}
|
||||
res = JsonUtil.toObject(jsonStr, IMGroupMsgResDO.class);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 默认单发发群文本消息
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user