Explorar o código

微信会话内容存储获取优化

anderx hai 6 meses
pai
achega
1d7f1dab3e

+ 17 - 25
src/main/java/com/kede/wechat/service/impl/ConversationContentServiceImpl.java

@@ -179,8 +179,8 @@ public class ConversationContentServiceImpl extends BaseMybatisDao<ChatMsgUserMa
             com.alibaba.fastjson.JSONObject text = jsonObject.getJSONObject("text");
             if (text!=null){
                 String content1 = text.getString("content");
-                chatMsg.setContent(pushCharset(content1));
-//                chatMsg.setContent(content1);
+//                chatMsg.setContent(pushCharset(content1));
+                chatMsg.setContent(content1);
             }
         }else if (msgtype.equals("link"))
         {
@@ -191,7 +191,7 @@ public class ConversationContentServiceImpl extends BaseMybatisDao<ChatMsgUserMa
         }else if (msgtype.equals("mixed"))
         {
             //混合
-            System.out.println(jsonObject);
+            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++) {
@@ -200,22 +200,18 @@ public class ConversationContentServiceImpl extends BaseMybatisDao<ChatMsgUserMa
                 if (type.equals("text")){
                     com.alibaba.fastjson.JSONObject contentJson = e.getJSONObject("content");
                     String content = contentJson.getString("content");
-                    chatMsg.setContent(pushCharset(content));
+                    chatMsg.setContent(content);
                 }else {
                     String url =uploadPath;
                     com.alibaba.fastjson.JSONObject content = e.getJSONObject("content");
                     String sdkfileid=content.getString("sdkfileid");
                     if (type.equals("file")){
-                        try {
-                            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 = url +"/wechat/"+ safeName;
-                            }
-                        } catch (UnsupportedEncodingException ex) {
-                            throw new RuntimeException(ex);
+                        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 = url +"/wechat/"+ safeName;
                         }
                     }else if (type.equals("image")) {
                         url = url + "/wechat/" + System.currentTimeMillis() + ".jpg";
@@ -261,17 +257,13 @@ public class ConversationContentServiceImpl extends BaseMybatisDao<ChatMsgUserMa
 
         if (msgtype.equals("file")){
             com.alibaba.fastjson.JSONObject file = jsonObject.getJSONObject("file");
-            try {
-                String filename = file.getString("filename");
-                sdkfileid = file.getString("sdkfileid");
-                String osname = System.getProperties().getProperty("os.name");
-                if (osname.contains("Windows")) {
-                    filename = new String(filename.getBytes("GBK"),"UTF-8");
-                    String safeName=filename.replaceAll("[<>:\"/\\\\|?*,、]", "_");
-                    url = url +"/wechat/"+ safeName;
-                }
-            } catch (UnsupportedEncodingException e) {
-                throw new RuntimeException(e);
+            String filename = file.getString("filename");
+            sdkfileid = file.getString("sdkfileid");
+            String osname = System.getProperties().getProperty("os.name");
+            if (osname.contains("Windows")) {
+//                    filename = new String(filename.getBytes("GBK"),"UTF-8");
+                String safeName=filename.replaceAll("[<>:\"/\\\\|?*,、]", "_");
+                url = url +"/wechat/"+ safeName;
             }
         }else if (msgtype.equals("image")){
             url = url +"/wechat/"+ System.currentTimeMillis()+".jpg";