|
|
@@ -303,10 +303,16 @@ public class QwMsgController {
|
|
|
break;
|
|
|
case 102000:
|
|
|
WxWorkMessageDTO wxWorkMessageDTO = JSON.parseObject(wxWorkMsgResp.getJson(), WxWorkMessageDTO.class);
|
|
|
- if (wxWorkMessageDTO.getIs_room()!=0){
|
|
|
+ if (wxWorkMessageDTO.getReferid()!=0){
|
|
|
break;
|
|
|
}
|
|
|
- if (wxWorkMessageDTO.getReferid()!=0){
|
|
|
+ if (wxWorkMessageDTO.getIs_room()!=0){
|
|
|
+ try {
|
|
|
+ // 接收处理群消息
|
|
|
+ processRoomMessage(wxWorkMsgResp, wxWorkMessageDTO, id, serverId);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("接收处理群消息失败 err: {}", e.getMessage(), e);
|
|
|
+ }
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
@@ -423,23 +429,23 @@ public class QwMsgController {
|
|
|
|
|
|
// 处理文本消息
|
|
|
if (wxWorkMessageDTO.getMsgtype() == 2 || wxWorkMessageDTO.getMsgtype() == 0) {
|
|
|
- processTextMessage(id, userId, wxWorkMessageDTO.getContent(), wxWorkMsgResp, sendType);
|
|
|
+ processTextMessage(id, userId, wxWorkMessageDTO.getContent(), wxWorkMsgResp, sendType, false, null, null);
|
|
|
}
|
|
|
// 语音消息
|
|
|
if (wxWorkMessageDTO.getMsgtype() == 16) {
|
|
|
- processVoiceMessage(serverId, wxWorkMessageDTO.getContent(), wxWorkMessageDTO, wxWorkMsgResp, id, userId, sendType);
|
|
|
+ processVoiceMessage(serverId, wxWorkMessageDTO.getContent(), wxWorkMessageDTO, wxWorkMsgResp, id, userId, sendType, false, null, null);
|
|
|
}
|
|
|
// 图片消息
|
|
|
if (wxWorkMessageDTO.getMsgtype() == 101){
|
|
|
- processImageMessage(serverId, wxWorkMessageDTO, wxWorkMsgResp, id, userId, sendType);
|
|
|
+ processImageMessage(serverId, wxWorkMessageDTO, wxWorkMsgResp, id, userId, sendType, false, null, null);
|
|
|
}
|
|
|
// gif 表情消息
|
|
|
if (wxWorkMessageDTO.getMsgtype() == 104){
|
|
|
- processEmotionDynamicMessage(wxWorkMessageDTO, wxWorkMsgResp, id, userId, sendType);
|
|
|
+ processEmotionDynamicMessage(wxWorkMessageDTO, wxWorkMsgResp, id, userId, sendType, false, null, null);
|
|
|
}
|
|
|
// 小程序消息
|
|
|
if (wxWorkMessageDTO.getMsgtype() == 78) {
|
|
|
- processMiniAppMessage(serverId, wxWorkMessageDTO, wxWorkMsgResp, id, userId, sendType);
|
|
|
+ processMiniAppMessage(serverId, wxWorkMessageDTO, wxWorkMsgResp, id, userId, sendType, false, null, null);
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
@@ -573,10 +579,13 @@ public class QwMsgController {
|
|
|
* @param content 消息内容
|
|
|
* @param wxWorkMsgResp 回调信息对象
|
|
|
* @param sendType 发送者类型 1客户 2销售
|
|
|
+ * @param isRoom 是否群聊
|
|
|
+ * @param chatId 会话ID(群聊才有)
|
|
|
+ * @param chatAvatar 群头像(群聊才有)
|
|
|
*/
|
|
|
- private void processTextMessage(Long id, Long userId, String content, WxWorkMsgResp wxWorkMsgResp, Integer sendType) {
|
|
|
+ private void processTextMessage(Long id, Long userId, String content, WxWorkMsgResp wxWorkMsgResp, Integer sendType, boolean isRoom, String chatId, String chatAvatar) {
|
|
|
// 保存聊天消息
|
|
|
- QwMessageListVO message = aiHookService.saveQwMsg(id, userId, content, wxWorkMsgResp.getUuid(), sendType, wxWorkMsgResp.getJson(), 1);
|
|
|
+ QwMessageListVO message = aiHookService.saveQwMsg(id, userId, content, wxWorkMsgResp.getUuid(), sendType, wxWorkMsgResp.getJson(), 1, isRoom, chatId, chatAvatar);
|
|
|
QwImSocket.broadcast(message);
|
|
|
}
|
|
|
|
|
|
@@ -589,8 +598,11 @@ public class QwMsgController {
|
|
|
* @param id 企微用户ID
|
|
|
* @param userId 消息发送者ID
|
|
|
* @param sendType 发送者类型 1客户 2销售
|
|
|
+ * @param isRoom 是否群聊
|
|
|
+ * @param chatId 会话ID(群聊才有)
|
|
|
+ * @param chatAvatar 群头像(群聊才有)
|
|
|
*/
|
|
|
- private void processVoiceMessage(Long serverId, String content, WxWorkMessageDTO wxWorkMessageDTO, WxWorkMsgResp wxWorkMsgResp, Long id, Long userId, Integer sendType) {
|
|
|
+ private void processVoiceMessage(Long serverId, String content, WxWorkMessageDTO wxWorkMessageDTO, WxWorkMsgResp wxWorkMsgResp, Long id, Long userId, Integer sendType, boolean isRoom, String chatId, String chatAvatar) {
|
|
|
String voiceFileName = IdUtils.fastSimpleUUID() + ".silk";
|
|
|
WxWorkResponseDTO<String> fileUrlResp =
|
|
|
aiHookService.getFileUrl(wxWorkMsgResp.getUuid(), wxWorkMessageDTO.getVoice_id(), wxWorkMessageDTO.getAes_key(), 5, voiceFileName, wxWorkMessageDTO.getVoice_size(), serverId);
|
|
|
@@ -620,7 +632,7 @@ public class QwMsgController {
|
|
|
json.put("content", content);
|
|
|
|
|
|
// 保存聊天消息
|
|
|
- QwMessageListVO message = aiHookService.saveQwMsg(id, userId, json.toString(), wxWorkMsgResp.getUuid(), sendType, wxWorkMsgResp.getJson(), 4);
|
|
|
+ QwMessageListVO message = aiHookService.saveQwMsg(id, userId, json.toString(), wxWorkMsgResp.getUuid(), sendType, wxWorkMsgResp.getJson(), 4, isRoom, chatId, chatAvatar);
|
|
|
QwImSocket.broadcast(message);
|
|
|
}
|
|
|
|
|
|
@@ -632,8 +644,11 @@ public class QwMsgController {
|
|
|
* @param id 企微用户ID
|
|
|
* @param userId 消息发送者ID
|
|
|
* @param sendType 发送者类型 1客户 2销售
|
|
|
+ * @param isRoom 是否群聊
|
|
|
+ * @param chatId 会话ID(群聊才有)
|
|
|
+ * @param chatAvatar 群头像(群聊才有)
|
|
|
*/
|
|
|
- private void processImageMessage(Long serverId, WxWorkMessageDTO wxWorkMessageDTO, WxWorkMsgResp wxWorkMsgResp, Long id, Long userId, Integer sendType) {
|
|
|
+ private void processImageMessage(Long serverId, WxWorkMessageDTO wxWorkMessageDTO, WxWorkMsgResp wxWorkMsgResp, Long id, Long userId, Integer sendType, boolean isRoom, String chatId, String chatAvatar) {
|
|
|
String fileName = IdUtils.fastSimpleUUID() + ".jpg";
|
|
|
WxWorkResponseDTO<String> fileUrlResp =
|
|
|
aiHookService.getFileUrl(wxWorkMsgResp.getUuid(), wxWorkMessageDTO.getFile_id(), wxWorkMessageDTO.getAes_key(), wxWorkMessageDTO.getOpenim_cdn_authkey(), fileName, wxWorkMessageDTO.getFile_size(), serverId);
|
|
|
@@ -644,7 +659,7 @@ public class QwMsgController {
|
|
|
|
|
|
String content = fileUrlResp.getData();
|
|
|
// 保存聊天消息
|
|
|
- QwMessageListVO message = aiHookService.saveQwMsg(id, userId, content, wxWorkMsgResp.getUuid(), sendType, wxWorkMsgResp.getJson(), 2);
|
|
|
+ QwMessageListVO message = aiHookService.saveQwMsg(id, userId, content, wxWorkMsgResp.getUuid(), sendType, wxWorkMsgResp.getJson(), 2, isRoom, chatId, chatAvatar);
|
|
|
QwImSocket.broadcast(message);
|
|
|
}
|
|
|
|
|
|
@@ -655,11 +670,14 @@ public class QwMsgController {
|
|
|
* @param id 企微用户ID
|
|
|
* @param userId 消息发送者ID
|
|
|
* @param sendType 发送者类型 1客户 2销售
|
|
|
+ * @param isRoom 是否群聊
|
|
|
+ * @param chatId 会话ID(群聊才有)
|
|
|
+ * @param chatAvatar 群头像(群聊才有)
|
|
|
*/
|
|
|
- private void processEmotionDynamicMessage(WxWorkMessageDTO wxWorkMessageDTO, WxWorkMsgResp wxWorkMsgResp, Long id, Long userId, int sendType) {
|
|
|
+ private void processEmotionDynamicMessage(WxWorkMessageDTO wxWorkMessageDTO, WxWorkMsgResp wxWorkMsgResp, Long id, Long userId, int sendType, boolean isRoom, String chatId, String chatAvatar) {
|
|
|
String content = wxWorkMessageDTO.getUrl();
|
|
|
// 保存聊天消息
|
|
|
- QwMessageListVO message = aiHookService.saveQwMsg(id, userId, content, wxWorkMsgResp.getUuid(), sendType, wxWorkMsgResp.getJson(), 3);
|
|
|
+ QwMessageListVO message = aiHookService.saveQwMsg(id, userId, content, wxWorkMsgResp.getUuid(), sendType, wxWorkMsgResp.getJson(), 3, isRoom, chatId, chatAvatar);
|
|
|
QwImSocket.broadcast(message);
|
|
|
}
|
|
|
|
|
|
@@ -671,8 +689,11 @@ public class QwMsgController {
|
|
|
* @param id 企微用户ID
|
|
|
* @param userId 消息发送者ID
|
|
|
* @param sendType 发送者类型 1客户 2销售
|
|
|
+ * @param isRoom 是否群聊
|
|
|
+ * @param chatId 会话ID(群聊才有)
|
|
|
+ * @param chatAvatar 群头像(群聊才有)
|
|
|
*/
|
|
|
- private void processMiniAppMessage(Long serverId, WxWorkMessageDTO wxWorkMessageDTO, WxWorkMsgResp wxWorkMsgResp, Long id, Long userId, int sendType) {
|
|
|
+ private void processMiniAppMessage(Long serverId, WxWorkMessageDTO wxWorkMessageDTO, WxWorkMsgResp wxWorkMsgResp, Long id, Long userId, int sendType, boolean isRoom, String chatId, String chatAvatar) {
|
|
|
String thumbName = IdUtils.fastSimpleUUID() + ".jpg";
|
|
|
WxWorkResponseDTO<String> fileUrlResp =
|
|
|
aiHookService.getFileUrl(wxWorkMsgResp.getUuid(), wxWorkMessageDTO.getThumbFileId(), wxWorkMessageDTO.getThumbAESKey(), 1, thumbName, wxWorkMessageDTO.getSize(), serverId);
|
|
|
@@ -691,8 +712,67 @@ public class QwMsgController {
|
|
|
json.put("thumbnail", fileUrlResp.getData());
|
|
|
|
|
|
// 保存聊天消息
|
|
|
- QwMessageListVO message = aiHookService.saveQwMsg(id, userId, json.toString(), wxWorkMsgResp.getUuid(), sendType, wxWorkMsgResp.getJson(), 5);
|
|
|
+ QwMessageListVO message = aiHookService.saveQwMsg(id, userId, json.toString(), wxWorkMsgResp.getUuid(), sendType, wxWorkMsgResp.getJson(), 5, isRoom, chatId, chatAvatar);
|
|
|
QwImSocket.broadcast(message);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 处理群消息
|
|
|
+ */
|
|
|
+ private void processRoomMessage(WxWorkMsgResp wxWorkMsgResp, WxWorkMessageDTO wxWorkMessageDTO, Long qwUserId, Long serverId) {
|
|
|
+ log.debug("接收群消息 msg: {}", JSON.toJSONString(wxWorkMessageDTO));
|
|
|
+ Long receiver = wxWorkMessageDTO.getReceiver();
|
|
|
+ Long sender = wxWorkMessageDTO.getSender();
|
|
|
+
|
|
|
+ // 1客户 2销售
|
|
|
+ int sendType = 2;
|
|
|
+
|
|
|
+ // 消息发送者用户ID
|
|
|
+ Long userId = receiver;
|
|
|
+ if (receiver != 0 && 2000000000000000L - receiver > 0){
|
|
|
+ sendType = 1;
|
|
|
+ userId = sender;
|
|
|
+ }
|
|
|
+
|
|
|
+ WxWorkRoomId2ChatIdDTO roomId2ChatIdDTO = new WxWorkRoomId2ChatIdDTO();
|
|
|
+ roomId2ChatIdDTO.setUuid(wxWorkMsgResp.getUuid());
|
|
|
+ roomId2ChatIdDTO.setRoom_id(wxWorkMessageDTO.getRoom_conversation_id());
|
|
|
+ WxWorkResponseDTO<WxWorkChatId2RoomIdResp> roomId2ChatIdResp = wxWorkService.roomId2ChatId(roomId2ChatIdDTO, serverId);
|
|
|
+ if (roomId2ChatIdResp.getErrcode() != 0) {
|
|
|
+ log.warn("接收群消息 rooId2ChatId失败: {}", roomId2ChatIdResp.getErrmsg());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String chatId = roomId2ChatIdResp.getData().getChatid();
|
|
|
+
|
|
|
+ String chatAvatar = "";
|
|
|
+ WxRoomHeaderDTO roomHeaderDTO = new WxRoomHeaderDTO();
|
|
|
+ roomHeaderDTO.setRoomid(roomId2ChatIdResp.getData().getRoom_id());
|
|
|
+ roomHeaderDTO.setUuid(wxWorkMsgResp.getUuid());
|
|
|
+ WxWorkResponseDTO<WxRoomHeaderResp> roomHeaderResp = wxWorkService.wxRoomHeader(roomHeaderDTO, serverId);
|
|
|
+ if (roomHeaderResp.getErrcode() == 0) {
|
|
|
+ chatAvatar = roomHeaderResp.getData().getImage_url();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理文本消息
|
|
|
+ if (wxWorkMessageDTO.getMsgtype() == 2 || wxWorkMessageDTO.getMsgtype() == 0) {
|
|
|
+ processTextMessage(qwUserId, userId, wxWorkMessageDTO.getContent(), wxWorkMsgResp, sendType, true, chatId, chatAvatar);
|
|
|
+ }
|
|
|
+ // 语音消息
|
|
|
+ if (wxWorkMessageDTO.getMsgtype() == 16) {
|
|
|
+ processVoiceMessage(serverId, wxWorkMessageDTO.getContent(), wxWorkMessageDTO, wxWorkMsgResp, qwUserId, userId, sendType, true, chatId, chatAvatar);
|
|
|
+ }
|
|
|
+ // 图片消息
|
|
|
+ if (wxWorkMessageDTO.getMsgtype() == 101){
|
|
|
+ processImageMessage(serverId, wxWorkMessageDTO, wxWorkMsgResp, qwUserId, userId, sendType, true, chatId, chatAvatar);
|
|
|
+ }
|
|
|
+ // gif 表情消息
|
|
|
+ if (wxWorkMessageDTO.getMsgtype() == 104){
|
|
|
+ processEmotionDynamicMessage(wxWorkMessageDTO, wxWorkMsgResp, qwUserId, userId, sendType, true, chatId, chatAvatar);
|
|
|
+ }
|
|
|
+ // 小程序消息
|
|
|
+ if (wxWorkMessageDTO.getMsgtype() == 78) {
|
|
|
+ processMiniAppMessage(serverId, wxWorkMessageDTO, wxWorkMsgResp, qwUserId, userId, sendType, true, chatId, chatAvatar);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|