|
|
@@ -1978,4 +1978,74 @@ public class OpenIMServiceImpl implements OpenIMService {
|
|
|
OpenImResponseDTO responseDTO= JSONUtil.toBean(body,OpenImResponseDTO.class);
|
|
|
return responseDTO;
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 批量发送纯文本消息(不存库,仅发送)
|
|
|
+ * @param senderId 发送人ID
|
|
|
+ * @param receiverIds 接收人ID列表
|
|
|
+ * @param textContent 文本内容
|
|
|
+ * @param pushTitle 离线推送标题(可选)
|
|
|
+ * @param pushDesc 离线推送描述(可选)
|
|
|
+ * @param ex 扩展字段(可选)
|
|
|
+ * @return 发送结果
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public OpenImResponseDTO batchSendTextMessage(String senderId, List<String> receiverIds, String textContent,
|
|
|
+ String pushTitle, String pushDesc, String ex) {
|
|
|
+ try {
|
|
|
+ log.info("批量发送文本消息 - 发送人: {}, 接收人数: {}, 内容: {}", senderId, receiverIds.size(), textContent);
|
|
|
+
|
|
|
+ // 构建批量发送消息DTO
|
|
|
+ OpenImBatchMsgDTO batchMsgDTO = new OpenImBatchMsgDTO();
|
|
|
+
|
|
|
+ // 必填字段
|
|
|
+ batchMsgDTO.setSendID(senderId);
|
|
|
+ batchMsgDTO.setRecvIDs(receiverIds);
|
|
|
+ batchMsgDTO.setContentType(101); // 101表示文本消息
|
|
|
+ batchMsgDTO.setSessionType(1); // 1表示单聊
|
|
|
+
|
|
|
+ // 设置消息内容
|
|
|
+ OpenImBatchMsgDTO.Content content = new OpenImBatchMsgDTO.Content();
|
|
|
+ content.setContent(textContent);
|
|
|
+ batchMsgDTO.setContent(content);
|
|
|
+
|
|
|
+
|
|
|
+ // 可选字段 - 离线推送
|
|
|
+ if (StringUtils.isNotEmpty(pushTitle) || StringUtils.isNotEmpty(pushDesc)) {
|
|
|
+ OpenImBatchMsgDTO.OfflinePushInfo pushInfo = new OpenImBatchMsgDTO.OfflinePushInfo();
|
|
|
+ pushInfo.setTitle(StringUtils.isNotEmpty(pushTitle) ? pushTitle : "新消息");
|
|
|
+ pushInfo.setDesc(StringUtils.isNotEmpty(pushDesc) ? pushDesc : textContent);
|
|
|
+ batchMsgDTO.setOfflinePushInfo(pushInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 可选字段 - 扩展信息
|
|
|
+ if (StringUtils.isNotEmpty(ex)) {
|
|
|
+ batchMsgDTO.setEx(ex);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 设置默认值
|
|
|
+ batchMsgDTO.setIsOnlineOnly(false); // 非仅在线发送
|
|
|
+ batchMsgDTO.setNotOfflinePush(false); // 允许离线推送
|
|
|
+ batchMsgDTO.setSendTime(System.currentTimeMillis()); // 当前时间
|
|
|
+
|
|
|
+ log.info("批量发送文本消息请求: {}", JSON.toJSONString(batchMsgDTO));
|
|
|
+
|
|
|
+ // 调用批量发送接口
|
|
|
+ OpenImResponseDTO response = this.openIMBatchSendMsg(batchMsgDTO);
|
|
|
+
|
|
|
+ log.info("批量发送文本消息结果 - errCode: {}, errMsg: {}",
|
|
|
+ response != null ? response.getErrCode() : "null",
|
|
|
+ response != null ? response.getErrMsg() : "null");
|
|
|
+
|
|
|
+ return response;
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("批量发送文本消息异常 - 发送人: {}, 接收人数: {}", senderId, receiverIds.size(), e);
|
|
|
+ OpenImResponseDTO errorResponse = new OpenImResponseDTO();
|
|
|
+ errorResponse.setErrCode(500);
|
|
|
+ errorResponse.setErrMsg("发送失败: " + e.getMessage());
|
|
|
+ return errorResponse;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|