Browse Source

微信会话内容切换日志存档BUG修复

anderx 6 months ago
parent
commit
6da5a21a88

+ 9 - 1
src/main/java/com/kede/wechat/bo/InputChatMsg.java

@@ -41,7 +41,15 @@ public class InputChatMsg {
     public InputChatMsg(JSONObject jsonObject) {
         this.msgid = jsonObject.getString("msgid");
         this.action = jsonObject.getString("action");
-        this.from = jsonObject.getString("from");
+        String from1 = jsonObject.getString("from");
+        if (from1!=null){
+            this.from = from1;
+        }else {
+            String user = jsonObject.getString("user");
+            if (user!=null){
+                this.from = user;
+            }
+        }
         JSONArray tolist1 = jsonObject.getJSONArray("tolist");
         if (tolist1!=null){
             StringJoiner tolist = new StringJoiner(",");

+ 58 - 56
src/main/java/com/kede/wechat/service/impl/ConversationContentServiceImpl.java

@@ -196,68 +196,70 @@ public class ConversationContentServiceImpl extends BaseMybatisDao<ChatMsgUserMa
     }
 
     private void pushSmgType(String msgtype, com.alibaba.fastjson.JSONObject jsonObject, long sdk, InputChatMsg chatMsg) {
-        if (msgtype!=null&&msgtype.equals("text"))
-        {
-            //文档
-            com.alibaba.fastjson.JSONObject text = jsonObject.getJSONObject("text");
-            if (text!=null){
-                String content1 = text.getString("content");
+        if (msgtype!=null){
+            if (msgtype.equals("text"))
+            {
+                //文档
+                com.alibaba.fastjson.JSONObject text = jsonObject.getJSONObject("text");
+                if (text!=null){
+                    String content1 = text.getString("content");
 //                chatMsg.setContent(pushCharset(content1));
-                chatMsg.setContent(content1);
-            }
-        }else if (msgtype.equals("link"))
-        {
-            //链接
-            com.alibaba.fastjson.JSONObject link = jsonObject.getJSONObject("link");
-            chatMsg.setMsgurl(link.getString("link_url"));
-            chatMsg.setContent(pushCharset(link.getString("title")));
-        }else if (msgtype.equals("mixed"))
-        {
-            //混合
-            System.out.println("=+++++++++++++++++++++++++++++++++++++"+jsonObject);
-            com.alibaba.fastjson.JSONObject mixed = jsonObject.getJSONObject("mixed");
-            com.alibaba.fastjson.JSONArray item = mixed.getJSONArray("item");
-            for (int j = 0; j < item.size(); j++) {
-                com.alibaba.fastjson.JSONObject e = item.getJSONObject(j);
-                String type = e.getString("type");
-                if (type.equals("text")){
-                    com.alibaba.fastjson.JSONObject contentJson = e.getJSONObject("content");
-                    String content = contentJson.getString("content");
-                    chatMsg.setContent(content);
-                }else {
-                    String url ="";
-                    com.alibaba.fastjson.JSONObject content = e.getJSONObject("content");
-                    String sdkfileid=content.getString("sdkfileid");
-                    if (type.equals("file")){
-                        String filename = content.getString("filename");
-                        String osname = System.getProperties().getProperty("os.name");
-                        if (osname.contains("Windows")) {
+                    chatMsg.setContent(content1);
+                }
+            }else if (msgtype.equals("link"))
+            {
+                //链接
+                com.alibaba.fastjson.JSONObject link = jsonObject.getJSONObject("link");
+                chatMsg.setMsgurl(link.getString("link_url"));
+                chatMsg.setContent(pushCharset(link.getString("title")));
+            }else if (msgtype.equals("mixed"))
+            {
+                //混合
+                System.out.println("=+++++++++++++++++++++++++++++++++++++"+jsonObject);
+                com.alibaba.fastjson.JSONObject mixed = jsonObject.getJSONObject("mixed");
+                com.alibaba.fastjson.JSONArray item = mixed.getJSONArray("item");
+                for (int j = 0; j < item.size(); j++) {
+                    com.alibaba.fastjson.JSONObject e = item.getJSONObject(j);
+                    String type = e.getString("type");
+                    if (type.equals("text")){
+                        com.alibaba.fastjson.JSONObject contentJson = e.getJSONObject("content");
+                        String content = contentJson.getString("content");
+                        chatMsg.setContent(content);
+                    }else {
+                        String url ="";
+                        com.alibaba.fastjson.JSONObject content = e.getJSONObject("content");
+                        String sdkfileid=content.getString("sdkfileid");
+                        if (type.equals("file")){
+                            String filename = content.getString("filename");
+                            String osname = System.getProperties().getProperty("os.name");
+                            if (osname.contains("Windows")) {
 //                                filename = new String(filename.getBytes("GBK"),"UTF-8");
-                            String safeName=filename.replaceAll("[<>:\"/\\\\|?*,、]", "_");
-                            url="/wechat/"+ safeName;
+                                String safeName=filename.replaceAll("[<>:\"/\\\\|?*,、]", "_");
+                                url="/wechat/"+ safeName;
+                            }
+                        }else if (type.equals("image")) {
+                            url="/wechat/" + System.currentTimeMillis() + ".jpg";
+                            com.alibaba.fastjson.JSONObject image = jsonObject.getJSONObject("image");
+                        }else {
+                            chatMsg.setContent(chatMsg.getContent()+"[附件="+e+"]");
                         }
-                    }else if (type.equals("image")) {
-                        url="/wechat/" + System.currentTimeMillis() + ".jpg";
-                        com.alibaba.fastjson.JSONObject image = jsonObject.getJSONObject("image");
-                    }else {
-                        chatMsg.setContent(chatMsg.getContent()+"[附件="+e+"]");
+                        downloadFile(sdk, sdkfileid, uploadPath+ url);
+                        chatMsg.setMsgurl(url);
                     }
-                    downloadFile(sdk, sdkfileid, uploadPath+ url);
-                    chatMsg.setMsgurl(url);
                 }
-            }
-        } else if (msgtype.equals("sphfeed"))
-        {
-            chatMsg.setContent(jsonObject.getString("sphfeed"));
-        } else if (msgtype.equals("file")||msgtype.equals("image")||msgtype.equals("video")||msgtype.equals("voice"))
-        {
-            String url=pushFileUrl(sdk, msgtype, jsonObject);
-            chatMsg.setMsgurl(url);
-        } else {
-            if (!jsonObject.getString("action").equals("switch")&&!jsonObject.getString("action").equals("recall")) {
-                chatMsg.setContent(jsonObject.toJSONString());
-            }
+            } else if (msgtype.equals("sphfeed"))
+            {
+                chatMsg.setContent(jsonObject.getString("sphfeed"));
+            } else if (msgtype.equals("file")||msgtype.equals("image")||msgtype.equals("video")||msgtype.equals("voice"))
+            {
+                String url=pushFileUrl(sdk, msgtype, jsonObject);
+                chatMsg.setMsgurl(url);
+            } else {
+                if (!jsonObject.getString("action").equals("switch")&&!jsonObject.getString("action").equals("recall")) {
+                    chatMsg.setContent(jsonObject.toJSONString());
+                }
 
+            }
         }
     }