|
|
@@ -1,5 +1,6 @@
|
|
|
package com.kede.wechat.service.impl;
|
|
|
|
|
|
+import com.kede.common.dao.ChatMsgMapper;
|
|
|
import com.kede.common.model.ChatMsg;
|
|
|
import com.kede.common.model.ChatMsgUser;
|
|
|
import com.kede.common.utils.DateUtils;
|
|
|
@@ -32,6 +33,8 @@ public class ConversationContentServiceImpl implements ConversationContentServic
|
|
|
private RedisTemplate redisTemplate;
|
|
|
@Resource
|
|
|
private ChatMsgUserMapper chatMsgUserMapper;
|
|
|
+ @Resource
|
|
|
+ private ChatMsgMapper chatMsgMapper;
|
|
|
|
|
|
|
|
|
@Value(value = "${conversationContent.corpid}")
|
|
|
@@ -139,15 +142,25 @@ public class ConversationContentServiceImpl implements ConversationContentServic
|
|
|
}
|
|
|
String str = String.valueOf(Finance.GetContentFromSlice(msg));
|
|
|
com.alibaba.fastjson.JSONObject jsonObject = com.alibaba.fastjson.JSONObject.parseObject(str);
|
|
|
- System.out.println("获取slice内容======="+jsonObject);
|
|
|
String msgtype = jsonObject.getString("msgtype");
|
|
|
InputChatMsg chatMsg = new InputChatMsg(jsonObject);
|
|
|
- if(msgtype.equals("file")||msgtype.equals("image")){
|
|
|
- String url=pushFileUrl(msgtype,jsonObject);
|
|
|
- chatMsg.setContent(url);
|
|
|
+ ChatMsg chatMsg1 = chatMsgMapper.selectByMsgId(chatMsg.getMsgid());
|
|
|
+ if (chatMsg1 == null){
|
|
|
+ if(!msgtype.equals("text")){
|
|
|
+ if (msgtype.equals("mixed")){
|
|
|
+ System.out.println(jsonObject);
|
|
|
+ for (int j = 0; j < jsonObject.getJSONArray("mixed").size(); j++) {
|
|
|
+ String url=pushFileUrl(sdk,msgtype,jsonObject);
|
|
|
+ }
|
|
|
+
|
|
|
+ }else {
|
|
|
+ String url=pushFileUrl(sdk,msgtype,jsonObject);
|
|
|
+ chatMsg.setContent(url);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ list.add(chatMsg);
|
|
|
}
|
|
|
- list.add(chatMsg);
|
|
|
-
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
@@ -162,13 +175,12 @@ public class ConversationContentServiceImpl implements ConversationContentServic
|
|
|
return map;
|
|
|
}
|
|
|
|
|
|
- private String pushFileUrl( String msgtype, com.alibaba.fastjson.JSONObject jsonObject) {
|
|
|
+ private String pushFileUrl(long sdk, String msgtype, com.alibaba.fastjson.JSONObject jsonObject) {
|
|
|
String url = uploadPath;
|
|
|
String sdkfileid=null;
|
|
|
|
|
|
if (msgtype.equals("file")){
|
|
|
com.alibaba.fastjson.JSONObject file = jsonObject.getJSONObject("file");
|
|
|
-
|
|
|
try {
|
|
|
String filename = file.getString("filename");
|
|
|
sdkfileid = file.getString("sdkfileid");
|
|
|
@@ -185,9 +197,17 @@ public class ConversationContentServiceImpl implements ConversationContentServic
|
|
|
url = url +"/wechat/"+ System.currentTimeMillis()+".jpg";
|
|
|
com.alibaba.fastjson.JSONObject image = jsonObject.getJSONObject("image");
|
|
|
sdkfileid = image.getString("sdkfileid");
|
|
|
+ }else if (msgtype.equals("voice")){
|
|
|
+ url = url +"/wechat/"+ System.currentTimeMillis()+".mp3";
|
|
|
+ com.alibaba.fastjson.JSONObject image = jsonObject.getJSONObject("voice");
|
|
|
+ sdkfileid = image.getString("sdkfileid");
|
|
|
+ }else if (msgtype.equals("video")){
|
|
|
+ url = url +"/wechat/"+ System.currentTimeMillis()+".mp4";
|
|
|
+ com.alibaba.fastjson.JSONObject image = jsonObject.getJSONObject("video");
|
|
|
}
|
|
|
- //下载文件
|
|
|
-// downloadFile(sdk, sdkfileid, url);
|
|
|
+
|
|
|
+// 下载文件
|
|
|
+ downloadFile(sdk, sdkfileid, url);
|
|
|
return url;
|
|
|
}
|
|
|
|
|
|
@@ -331,7 +351,6 @@ public class ConversationContentServiceImpl implements ConversationContentServic
|
|
|
public Map<String,Object> pushGetChatName(String userId) {
|
|
|
Map<String,Object> map = new HashMap<>();
|
|
|
Integer i = 0;
|
|
|
-
|
|
|
ChatMsgUser chatMsgUser = chatMsgUserMapper.selectByUserId(userId);
|
|
|
if (chatMsgUser != null){
|
|
|
map.put("name",chatMsgUser.getName());
|
|
|
@@ -352,7 +371,11 @@ public class ConversationContentServiceImpl implements ConversationContentServic
|
|
|
type=2;
|
|
|
}
|
|
|
Map<String, Object> maps = getUserName(url, type);
|
|
|
- String userName = maps.get("name").toString();
|
|
|
+ Object o = maps.get("name");
|
|
|
+ String userName = null;
|
|
|
+ if(o!=null){
|
|
|
+ userName = o.toString();
|
|
|
+ }
|
|
|
i= (Integer) maps.get("code");
|
|
|
System.out.println(userId+"="+userName);
|
|
|
if (StringUtils.isNotBlank(userName)){
|
|
|
@@ -394,7 +417,13 @@ public class ConversationContentServiceImpl implements ConversationContentServic
|
|
|
map.put("chat_id",roomid);
|
|
|
map.put("cursor",0);
|
|
|
com.alibaba.fastjson.JSONObject jsonObject = HttpUtils.httpPost(url, map);
|
|
|
- System.out.println(jsonObject.toJSONString());
|
|
|
+ String roomname = jsonObject.getString("roomname");
|
|
|
+ if (StringUtils.isBlank(roomname)){
|
|
|
+ com.alibaba.fastjson.JSONObject groupChat = jsonObject.getJSONObject("group_chat");
|
|
|
+ if (groupChat!=null){
|
|
|
+ name = groupChat.getString("name");
|
|
|
+ }
|
|
|
+ }
|
|
|
if (jsonObject.getInteger("errcode")==0){
|
|
|
}else {
|
|
|
System.out.println("获取外部群名称失败");
|
|
|
@@ -408,7 +437,11 @@ public class ConversationContentServiceImpl implements ConversationContentServic
|
|
|
map.put("roomid",roomid);
|
|
|
com.alibaba.fastjson.JSONObject jsonObject = HttpUtils.httpPost(url, map);
|
|
|
System.out.println(jsonObject.toJSONString());
|
|
|
- name = jsonObject.getString("roomname");
|
|
|
+ String roomname = jsonObject.getString("roomname");
|
|
|
+ if (StringUtils.isBlank(roomname)){
|
|
|
+ com.alibaba.fastjson.JSONObject groupChat = jsonObject.getJSONObject("group_chat");
|
|
|
+ name = groupChat.getString("name");
|
|
|
+ }
|
|
|
if (jsonObject.getInteger("errcode")==0){
|
|
|
}else {
|
|
|
System.out.println("获取内部群名称失败");
|
|
|
@@ -434,28 +467,30 @@ public class ConversationContentServiceImpl implements ConversationContentServic
|
|
|
com.alibaba.fastjson.JSONObject result = HttpUtils.httpGet(url);
|
|
|
if (result.getInteger("errcode")==0) {
|
|
|
System.out.println(result.toJSONString());
|
|
|
+ com.alibaba.fastjson.JSONObject externalContact = result.getJSONObject("external_contact");
|
|
|
+ code = result.getInteger("errcode");
|
|
|
+ name=externalContact.getString("name");
|
|
|
}else {
|
|
|
+ code = result.getInteger("errcode");
|
|
|
System.out.println(result.toJSONString());
|
|
|
System.out.println("获取外部联系人名称失败");
|
|
|
}
|
|
|
- com.alibaba.fastjson.JSONObject externalContact = result.getJSONObject("external_contact");
|
|
|
- code = result.getInteger("errcode");
|
|
|
- name=externalContact.getString("name");
|
|
|
}else if (type==2){
|
|
|
com.alibaba.fastjson.JSONObject result = HttpUtils.httpGet(url);
|
|
|
if (result.getInteger("errcode")==0) {
|
|
|
System.out.println(result.toJSONString());
|
|
|
-
|
|
|
+ com.alibaba.fastjson.JSONObject externalContact = result.getJSONObject("external_contact");
|
|
|
+ code = result.getInteger("errcode");
|
|
|
+ name = result.getString("name");
|
|
|
}else {
|
|
|
System.out.println(result.toJSONString());
|
|
|
System.out.println("获取内部联系人名称失败");
|
|
|
+ code = result.getInteger("errcode");
|
|
|
}
|
|
|
- com.alibaba.fastjson.JSONObject externalContact = result.getJSONObject("external_contact");
|
|
|
- code = result.getInteger("errcode");
|
|
|
- name = result.getString("name");
|
|
|
+
|
|
|
}
|
|
|
- map.put("name",name);
|
|
|
- map.put("code",code);
|
|
|
+ if(name!=null)map.put("name",name);
|
|
|
+ if (code!=null)map.put("code",code);
|
|
|
return map;
|
|
|
}
|
|
|
|