Prechádzať zdrojové kódy

fix:
修复消息通讯

18339543638 2 rokov pred
rodič
commit
6ead30b01d

+ 11 - 1
nb-im/src/main/java/com/nb/im/ws/PubMsgRequestHandler.java

@@ -2,6 +2,7 @@ package com.nb.im.ws;
 
 import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.collection.CollectionUtil;
+import cn.hutool.json.JSONObject;
 import cn.hutool.json.JSONUtil;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.fasterxml.jackson.core.JsonProcessingException;
@@ -66,7 +67,16 @@ public class PubMsgRequestHandler implements IMsgRequestHandler {
                     .allMatch(filter -> filter.doFilter(channelContext, message));
             if(result){
                 try {
-                    PubMsgInfo pubMsgInfo = objectMapper.readerFor(PubMsgInfo.class).readValue(String.valueOf(message.getPayload()));
+                    PubMsgInfo pubMsgInfo=null;
+                    String key=null;
+                    if (message.getPayload() instanceof JSONObject) {
+                        JSONObject obj= (JSONObject) message.getPayload();
+                        key=obj.getStr("key");
+                    }else {
+                        key=JSONUtil.parseObj(message.getPayload()).getStr("key");
+                    }
+                    pubMsgInfo= objectMapper.readerFor(PubMsgInfo.class).readValue(String.valueOf(message.getPayload()));
+                    pubMsgInfo.setKey(key);
                     pubMsgInfo.setOperationType(MsgEnum.NORMAL);
                     imUtils.send(param,topicWrapper,pubMsgInfo,channelContext,false);
                 }catch (Exception e){

+ 10 - 0
nb-im/src/main/java/com/nb/im/ws/filter/MsgFormatFilter.java

@@ -1,6 +1,8 @@
 package com.nb.im.ws.filter;
 
 import cn.hutool.core.util.ObjectUtil;
+import cn.hutool.json.JSON;
+import cn.hutool.json.JSONObject;
 import cn.hutool.json.JSONUtil;
 import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.databind.ObjectMapper;
@@ -46,7 +48,15 @@ public class MsgFormatFilter implements PubMsgFilter {
             }
             PubMsgInfo pubMsgInfo =null;
             try {
+                String key=null;
+                if (source.getPayload() instanceof JSONObject) {
+                    JSONObject obj= (JSONObject) source.getPayload();
+                    key=obj.getStr("key");
+                }else {
+                    key=JSONUtil.parseObj(source.getPayload()).getStr("key");
+                }
                 pubMsgInfo = objectMapper.readerFor(PubMsgInfo.class).readValue(String.valueOf(source.getPayload()));
+                pubMsgInfo.setKey(key);
                 pubMsgInfo.validate();
             }catch (Exception e){
 //                Tio.send(channelContext,WsResponse.fromText(JSONUtil.toJsonStr(PubResponse.fail(pubMsgInfo!=null?pubMsgInfo.getKey():"",e.getMessage())),WsPacket.CHARSET_NAME));