|
@@ -2,7 +2,9 @@ package com.fs.app.controller;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.fs.app.socket.QwImSocket;
|
|
import com.fs.app.socket.QwImSocket;
|
|
|
|
+import com.fs.app.util.AudioUtils;
|
|
import com.fs.common.core.redis.RedisCache;
|
|
import com.fs.common.core.redis.RedisCache;
|
|
|
|
+import com.fs.common.utils.StringUtils;
|
|
import com.fs.common.utils.uuid.IdUtils;
|
|
import com.fs.common.utils.uuid.IdUtils;
|
|
import com.fs.fastGpt.service.AiHookService;
|
|
import com.fs.fastGpt.service.AiHookService;
|
|
import com.fs.qw.domain.QwUser;
|
|
import com.fs.qw.domain.QwUser;
|
|
@@ -143,14 +145,27 @@ public class QwMsgController {
|
|
if (wxWorkMessageDTO.getReferid()!=0){
|
|
if (wxWorkMessageDTO.getReferid()!=0){
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ Long receiver = wxWorkMessageDTO.getReceiver();
|
|
|
|
+ Long sender = wxWorkMessageDTO.getSender();
|
|
|
|
+
|
|
|
|
+ // 1客户 2销售
|
|
|
|
+ int sendType = 2;
|
|
|
|
+
|
|
|
|
+ // 消息发送者用户ID
|
|
|
|
+ Long userId = receiver;
|
|
|
|
+ if (2000000000000000L - receiver > 0){
|
|
|
|
+ sendType = 1;
|
|
|
|
+ userId = sender;
|
|
|
|
+ }
|
|
|
|
+
|
|
if (wxWorkMessageDTO.getMsgtype()==2||wxWorkMessageDTO.getMsgtype()==0||wxWorkMessageDTO.getMsgtype()==16){
|
|
if (wxWorkMessageDTO.getMsgtype()==2||wxWorkMessageDTO.getMsgtype()==0||wxWorkMessageDTO.getMsgtype()==16){
|
|
|
|
|
|
String content = wxWorkMessageDTO.getContent();
|
|
String content = wxWorkMessageDTO.getContent();
|
|
System.out.println("接收人:"+wxWorkMessageDTO.getReceiver());
|
|
System.out.println("接收人:"+wxWorkMessageDTO.getReceiver());
|
|
System.out.println("发送人:"+wxWorkMessageDTO.getSender());
|
|
System.out.println("发送人:"+wxWorkMessageDTO.getSender());
|
|
System.out.println("内容:"+content);
|
|
System.out.println("内容:"+content);
|
|
- Long receiver = wxWorkMessageDTO.getReceiver();
|
|
|
|
- Long sender = wxWorkMessageDTO.getSender();
|
|
|
|
|
|
+
|
|
if(wxWorkMessageDTO.getMsgtype()==16){
|
|
if(wxWorkMessageDTO.getMsgtype()==16){
|
|
WxwSpeechToTextEntityDTO ste = new WxwSpeechToTextEntityDTO();
|
|
WxwSpeechToTextEntityDTO ste = new WxwSpeechToTextEntityDTO();
|
|
ste.setMsgid(wxWorkMessageDTO.getMsg_id());
|
|
ste.setMsgid(wxWorkMessageDTO.getMsg_id());
|
|
@@ -164,26 +179,25 @@ public class QwMsgController {
|
|
if (2000000000000000L-receiver>0){
|
|
if (2000000000000000L-receiver>0){
|
|
System.out.println("客户发送");
|
|
System.out.println("客户发送");
|
|
aiHookService.qwHookNotifyAiReply(id,sender,content,wxWorkMsgResp.getUuid(),wxWorkMessageDTO.getMsgtype());
|
|
aiHookService.qwHookNotifyAiReply(id,sender,content,wxWorkMsgResp.getUuid(),wxWorkMessageDTO.getMsgtype());
|
|
-
|
|
|
|
- // 保存聊天消息
|
|
|
|
- QwMessageListVO message = aiHookService.saveQwMsg(id, sender, content, wxWorkMsgResp.getUuid(), 1, wxWorkMsgResp.getJson(), 1);
|
|
|
|
- QwImSocket.broadcast(message);
|
|
|
|
}else {
|
|
}else {
|
|
System.out.println("销售发送");
|
|
System.out.println("销售发送");
|
|
aiHookService.qwHookNotifyAddMsg(id,receiver,content,wxWorkMsgResp.getUuid());
|
|
aiHookService.qwHookNotifyAddMsg(id,receiver,content,wxWorkMsgResp.getUuid());
|
|
-
|
|
|
|
- // 保存聊天消息
|
|
|
|
- QwMessageListVO message = aiHookService.saveQwMsg(id, receiver, content, wxWorkMsgResp.getUuid(), 2, wxWorkMsgResp.getJson(), 1);
|
|
|
|
- QwImSocket.broadcast(message);
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ // 处理文本消息
|
|
|
|
+ if (wxWorkMessageDTO.getMsgtype() == 2 || wxWorkMessageDTO.getMsgtype() == 0) {
|
|
|
|
+ processTextMessage(id, userId, content, wxWorkMsgResp, sendType);
|
|
|
|
+ }
|
|
|
|
+ // 语音消息
|
|
|
|
+ if (wxWorkMessageDTO.getMsgtype() == 16) {
|
|
|
|
+ processVoiceMessage(serverId, content, wxWorkMessageDTO, wxWorkMsgResp, id, userId, sendType);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
//语音通话
|
|
//语音通话
|
|
if (wxWorkMessageDTO.getMsgtype()==40){
|
|
if (wxWorkMessageDTO.getMsgtype()==40){
|
|
if (wxWorkMessageDTO.getRecordtype()==null){
|
|
if (wxWorkMessageDTO.getRecordtype()==null){
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
- Long receiver = wxWorkMessageDTO.getReceiver();
|
|
|
|
Long extId=null;
|
|
Long extId=null;
|
|
Integer totalSeconds=0;
|
|
Integer totalSeconds=0;
|
|
if (2000000000000000L-receiver>0){
|
|
if (2000000000000000L-receiver>0){
|
|
@@ -217,35 +231,11 @@ public class QwMsgController {
|
|
}
|
|
}
|
|
// 图片消息
|
|
// 图片消息
|
|
else if (wxWorkMessageDTO.getMsgtype() == 101){
|
|
else if (wxWorkMessageDTO.getMsgtype() == 101){
|
|
- System.out.println(json);
|
|
|
|
- System.out.println(wxWorkMsgResp.getJson());
|
|
|
|
- Long receiver = wxWorkMessageDTO.getReceiver();
|
|
|
|
- Long sender = wxWorkMessageDTO.getSender();
|
|
|
|
-
|
|
|
|
- long userId;
|
|
|
|
- int sendType;
|
|
|
|
- if (2000000000000000L - receiver > 0){
|
|
|
|
- System.out.println("客户发起");
|
|
|
|
- userId = sender;
|
|
|
|
- sendType= 1;
|
|
|
|
- }else {
|
|
|
|
- System.out.println("销售发起");
|
|
|
|
- userId = receiver;
|
|
|
|
- sendType= 2;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- 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);
|
|
|
|
- if (fileUrlResp.getErrcode() != 0) {
|
|
|
|
- log.warn("获取图片地址失败: {}", fileUrlResp.getErrmsg());
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- String content = fileUrlResp.getData();
|
|
|
|
- // 保存聊天消息
|
|
|
|
- QwMessageListVO message = aiHookService.saveQwMsg(id, userId, content, wxWorkMsgResp.getUuid(), sendType, wxWorkMsgResp.getJson(), 2);
|
|
|
|
- QwImSocket.broadcast(message);
|
|
|
|
|
|
+ processImageMessage(serverId, wxWorkMessageDTO, wxWorkMsgResp, id, userId, sendType);
|
|
|
|
+ }
|
|
|
|
+ // gif 表情消息
|
|
|
|
+ else if (wxWorkMessageDTO.getMsgtype() == 104){
|
|
|
|
+ processEmotionDynamicMessage(wxWorkMessageDTO, wxWorkMsgResp, id, userId, sendType);
|
|
}
|
|
}
|
|
|
|
|
|
break;
|
|
break;
|
|
@@ -258,6 +248,103 @@ public class QwMsgController {
|
|
return map;
|
|
return map;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 处理文本消息
|
|
|
|
+ * @param id 企微用户ID
|
|
|
|
+ * @param userId 消息发送者ID
|
|
|
|
+ * @param content 消息内容
|
|
|
|
+ * @param wxWorkMsgResp 回调信息对象
|
|
|
|
+ * @param sendType 发送者类型 1客户 2销售
|
|
|
|
+ */
|
|
|
|
+ private void processTextMessage(Long id, Long userId, String content, WxWorkMsgResp wxWorkMsgResp, Integer sendType) {
|
|
|
|
+ // 保存聊天消息
|
|
|
|
+ QwMessageListVO message = aiHookService.saveQwMsg(id, userId, content, wxWorkMsgResp.getUuid(), sendType, wxWorkMsgResp.getJson(), 1);
|
|
|
|
+ QwImSocket.broadcast(message);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 处理语音消息
|
|
|
|
+ * @param serverId 服务器ID
|
|
|
|
+ * @param wxWorkMessageDTO 消息DTO
|
|
|
|
+ * @param content 翻译后的内容
|
|
|
|
+ * @param wxWorkMsgResp 回调信息对象
|
|
|
|
+ * @param id 企微用户ID
|
|
|
|
+ * @param userId 消息发送者ID
|
|
|
|
+ * @param sendType 发送者类型 1客户 2销售
|
|
|
|
+ */
|
|
|
|
+ private void processVoiceMessage(Long serverId, String content, WxWorkMessageDTO wxWorkMessageDTO, WxWorkMsgResp wxWorkMsgResp, Long id, Long userId, Integer sendType) {
|
|
|
|
+ String voiceFileName = IdUtils.fastSimpleUUID() + ".silk";
|
|
|
|
+ WxWorkResponseDTO<String> fileUrlResp =
|
|
|
|
+ aiHookService.getFileUrl(wxWorkMsgResp.getUuid(), wxWorkMessageDTO.getVoice_id(), wxWorkMessageDTO.getAes_key(), 5, voiceFileName, wxWorkMessageDTO.getVoice_size(), serverId);
|
|
|
|
+ if (fileUrlResp.getErrcode() != 0) {
|
|
|
|
+ log.warn("获取语音地址失败: {}", fileUrlResp.getErrmsg());
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // silk转map3
|
|
|
|
+ String url = AudioUtils.convertSilk2Mp3(fileUrlResp.getData());
|
|
|
|
+ if (StringUtils.isBlank(url)) {
|
|
|
|
+ log.warn("转换silk语音格式失败");
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 转换内容为空时再尝试一次
|
|
|
|
+ if (StringUtils.isBlank(content)) {
|
|
|
|
+ WxwSpeechToTextEntityDTO ste = new WxwSpeechToTextEntityDTO();
|
|
|
|
+ ste.setMsgid(wxWorkMessageDTO.getMsg_id());
|
|
|
|
+ ste.setUuid(wxWorkMsgResp.getUuid());
|
|
|
|
+ WxWorkResponseDTO<WxwSpeechToTextEntityRespDTO> dto = wxWorkService.SpeechToTextEntity(ste, serverId);
|
|
|
|
+ content = dto.getData().getText();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ JSONObject json = new JSONObject();
|
|
|
|
+ json.put("url", url);
|
|
|
|
+ json.put("content", content);
|
|
|
|
+
|
|
|
|
+ // 保存聊天消息
|
|
|
|
+ QwMessageListVO message = aiHookService.saveQwMsg(id, userId, json.toString(), wxWorkMsgResp.getUuid(), sendType, wxWorkMsgResp.getJson(), 4);
|
|
|
|
+ QwImSocket.broadcast(message);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 处理图片消息
|
|
|
|
+ * @param serverId 服务器ID
|
|
|
|
+ * @param wxWorkMessageDTO 消息DTO
|
|
|
|
+ * @param wxWorkMsgResp 回调信息对象
|
|
|
|
+ * @param id 企微用户ID
|
|
|
|
+ * @param userId 消息发送者ID
|
|
|
|
+ * @param sendType 发送者类型 1客户 2销售
|
|
|
|
+ */
|
|
|
|
+ private void processImageMessage(Long serverId, WxWorkMessageDTO wxWorkMessageDTO, WxWorkMsgResp wxWorkMsgResp, Long id, Long userId, Integer sendType) {
|
|
|
|
+ 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);
|
|
|
|
+ if (fileUrlResp.getErrcode() != 0) {
|
|
|
|
+ log.warn("获取图片地址失败: {}", fileUrlResp.getErrmsg());
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ String content = fileUrlResp.getData();
|
|
|
|
+ // 保存聊天消息
|
|
|
|
+ QwMessageListVO message = aiHookService.saveQwMsg(id, userId, content, wxWorkMsgResp.getUuid(), sendType, wxWorkMsgResp.getJson(), 2);
|
|
|
|
+ QwImSocket.broadcast(message);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 处理动态表情消息
|
|
|
|
+ * @param wxWorkMessageDTO 消息DTO
|
|
|
|
+ * @param wxWorkMsgResp 回调信息对象
|
|
|
|
+ * @param id 企微用户ID
|
|
|
|
+ * @param userId 消息发送者ID
|
|
|
|
+ * @param sendType 发送者类型 1客户 2销售
|
|
|
|
+ */
|
|
|
|
+ private void processEmotionDynamicMessage(WxWorkMessageDTO wxWorkMessageDTO, WxWorkMsgResp wxWorkMsgResp, Long id, Long userId, int sendType) {
|
|
|
|
+ String content = wxWorkMessageDTO.getUrl();
|
|
|
|
+ // 保存聊天消息
|
|
|
|
+ QwMessageListVO message = aiHookService.saveQwMsg(id, userId, content, wxWorkMsgResp.getUuid(), sendType, wxWorkMsgResp.getJson(), 3);
|
|
|
|
+ QwImSocket.broadcast(message);
|
|
|
|
+ }
|
|
|
|
+
|
|
void qwUserStatus(String uid,Integer status){
|
|
void qwUserStatus(String uid,Integer status){
|
|
Long id = redisCache.getCacheObject("qrCode:uuid:"+uid);
|
|
Long id = redisCache.getCacheObject("qrCode:uuid:"+uid);
|
|
QwUser qwUser = new QwUser();
|
|
QwUser qwUser = new QwUser();
|