|
|
@@ -143,7 +143,7 @@ public class ConversationContentServiceImpl implements ConversationContentServic
|
|
|
String msgtype = jsonObject.getString("msgtype");
|
|
|
InputChatMsg chatMsg = new InputChatMsg(jsonObject);
|
|
|
if(msgtype.equals("file")||msgtype.equals("image")){
|
|
|
- String url=pushFileUrl(sdk,msgtype,jsonObject);
|
|
|
+ String url=pushFileUrl(msgtype,jsonObject);
|
|
|
chatMsg.setContent(url);
|
|
|
}
|
|
|
list.add(chatMsg);
|
|
|
@@ -162,15 +162,16 @@ public class ConversationContentServiceImpl implements ConversationContentServic
|
|
|
return map;
|
|
|
}
|
|
|
|
|
|
- private String pushFileUrl(long sdk, String msgtype, com.alibaba.fastjson.JSONObject jsonObject) {
|
|
|
+ private String pushFileUrl( 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");
|
|
|
- String filename = file.getString("filename");
|
|
|
- sdkfileid = file.getString("sdkfileid");
|
|
|
+
|
|
|
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");
|
|
|
@@ -185,8 +186,12 @@ public class ConversationContentServiceImpl implements ConversationContentServic
|
|
|
com.alibaba.fastjson.JSONObject image = jsonObject.getJSONObject("image");
|
|
|
sdkfileid = image.getString("sdkfileid");
|
|
|
}
|
|
|
+ //下载文件
|
|
|
+// downloadFile(sdk, sdkfileid, url);
|
|
|
+ return url;
|
|
|
+ }
|
|
|
|
|
|
-
|
|
|
+ private void downloadFile(long sdk, String sdkfileid, String url) {
|
|
|
String indexbuf = "";
|
|
|
while(true){
|
|
|
//每次使用GetMediaData拉取存档前需要调用NewMediaData获取一个media_data,在使用完media_data中数据后,还需要调用FreeMediaData释放。
|
|
|
@@ -195,7 +200,7 @@ public class ConversationContentServiceImpl implements ConversationContentServic
|
|
|
if(ret!=0){
|
|
|
System.out.println("getmediadata ret:" + ret);
|
|
|
Finance.FreeMediaData(media_data);
|
|
|
- return null;
|
|
|
+ return;
|
|
|
}
|
|
|
System.out.printf("getmediadata outindex len:%d, data_len:%d, is_finis:%d\n",Finance.GetIndexLen(media_data),Finance.GetDataLen(media_data), Finance.IsMediaDataFinish(media_data));
|
|
|
try {
|
|
|
@@ -225,11 +230,9 @@ public class ConversationContentServiceImpl implements ConversationContentServic
|
|
|
Finance.FreeMediaData(media_data);
|
|
|
}
|
|
|
}
|
|
|
- return url;
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
@Override
|
|
|
public String getAccessToken() {
|
|
|
//获取redis缓存数据
|
|
|
@@ -325,10 +328,15 @@ public class ConversationContentServiceImpl implements ConversationContentServic
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public String pushGetChatName(String userId) {
|
|
|
+ public Map<String,Object> pushGetChatName(String userId) {
|
|
|
+ Map<String,Object> map = new HashMap<>();
|
|
|
+ Integer i = 0;
|
|
|
+
|
|
|
ChatMsgUser chatMsgUser = chatMsgUserMapper.selectByUserId(userId);
|
|
|
if (chatMsgUser != null){
|
|
|
- return chatMsgUser.getName();
|
|
|
+ map.put("name",chatMsgUser.getName());
|
|
|
+ map.put("code",i);
|
|
|
+ return map;
|
|
|
}else {
|
|
|
String msgIdSub = userId.substring(0, 2);
|
|
|
String url=null;
|
|
|
@@ -343,7 +351,9 @@ public class ConversationContentServiceImpl implements ConversationContentServic
|
|
|
url=String.format("https://qyapi.weixin.qq.com/cgi-bin/user/get?access_token=%s&userid=%s",getAccessToken(),userId);
|
|
|
type=2;
|
|
|
}
|
|
|
- String userName = getUserName(url,type);
|
|
|
+ Map<String, Object> maps = getUserName(url, type);
|
|
|
+ String userName = maps.get("name").toString();
|
|
|
+ i= (Integer) maps.get("code");
|
|
|
System.out.println(userId+"="+userName);
|
|
|
if (StringUtils.isNotBlank(userName)){
|
|
|
chatMsgUser = new ChatMsgUser();
|
|
|
@@ -353,7 +363,9 @@ public class ConversationContentServiceImpl implements ConversationContentServic
|
|
|
chatMsgUser.setCreateTime(new Date());
|
|
|
chatMsgUserMapper.insert(chatMsgUser);
|
|
|
}
|
|
|
- return userName;
|
|
|
+ map.put("name",userName);
|
|
|
+ map.put("code",i);
|
|
|
+ return map;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -411,25 +423,40 @@ public class ConversationContentServiceImpl implements ConversationContentServic
|
|
|
}
|
|
|
|
|
|
|
|
|
- private String getUserName(String url,Integer type){
|
|
|
- com.alibaba.fastjson.JSONObject result = HttpUtils.httpGet(url);
|
|
|
+ private Map<String,Object> getUserName(String url,Integer type){
|
|
|
String name = null;
|
|
|
- if (result.getInteger("errcode")==0){
|
|
|
- System.out.println(result.toJSONString());
|
|
|
- if (type==0){
|
|
|
-
|
|
|
- }else if (type==1){
|
|
|
+ Integer code=null;
|
|
|
+ Map<String,Object> map=new HashMap<String, Object>();
|
|
|
+ if (type==0) {
|
|
|
+ name="机器人";
|
|
|
+ code=0;
|
|
|
+ }else if (type==1){
|
|
|
+ com.alibaba.fastjson.JSONObject result = HttpUtils.httpGet(url);
|
|
|
+ if (result.getInteger("errcode")==0) {
|
|
|
+ System.out.println(result.toJSONString());
|
|
|
+ }else {
|
|
|
+ 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){
|
|
|
+ }else if (type==2){
|
|
|
+ com.alibaba.fastjson.JSONObject result = HttpUtils.httpGet(url);
|
|
|
+ if (result.getInteger("errcode")==0) {
|
|
|
+ System.out.println(result.toJSONString());
|
|
|
+
|
|
|
+ }else {
|
|
|
+ System.out.println(result.toJSONString());
|
|
|
+ System.out.println("获取内部联系人名称失败");
|
|
|
+ }
|
|
|
+ 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("获取会话内容存档成员列表失败");
|
|
|
- }
|
|
|
- return name;
|
|
|
+ map.put("name",name);
|
|
|
+ map.put("code",code);
|
|
|
+ return map;
|
|
|
}
|
|
|
|
|
|
|