|
@@ -3,7 +3,7 @@ package com.kede.wechat.service.impl;
|
|
|
import com.kede.common.utils.DateUtils;
|
|
import com.kede.common.utils.DateUtils;
|
|
|
import com.kede.common.utils.HttpUtils;
|
|
import com.kede.common.utils.HttpUtils;
|
|
|
import com.kede.common.utils.RSAEncrypt;
|
|
import com.kede.common.utils.RSAEncrypt;
|
|
|
-import com.kede.wechat.bo.ChatMsg;
|
|
|
|
|
|
|
+import com.kede.wechat.bo.InputChatMsg;
|
|
|
import com.kede.wechat.service.ConversationContentService;
|
|
import com.kede.wechat.service.ConversationContentService;
|
|
|
import com.tencent.wework.Finance;
|
|
import com.tencent.wework.Finance;
|
|
|
import org.json.JSONArray;
|
|
import org.json.JSONArray;
|
|
@@ -68,14 +68,20 @@ public class ConversationContentServiceImpl implements ConversationContentServic
|
|
|
"KQIDAQAB\n" +
|
|
"KQIDAQAB\n" +
|
|
|
"-----END PUBLIC KEY-----";
|
|
"-----END PUBLIC KEY-----";
|
|
|
@Override
|
|
@Override
|
|
|
- public List<String> getChatData() {
|
|
|
|
|
|
|
+ public Map<String,Object> getChatData(Integer pageSeq, Integer pageLimit) {
|
|
|
String message = null;
|
|
String message = null;
|
|
|
- List<String> list = new ArrayList<>();
|
|
|
|
|
|
|
+ Map<String,Object> map = new HashMap<>();
|
|
|
|
|
+ List<InputChatMsg> list = new ArrayList<>();
|
|
|
|
|
+ Integer total = 0;
|
|
|
long sdk = Finance.NewSdk();
|
|
long sdk = Finance.NewSdk();
|
|
|
System.out.println(Finance.Init(sdk, corpid, secret));
|
|
System.out.println(Finance.Init(sdk, corpid, secret));
|
|
|
long ret = 0;
|
|
long ret = 0;
|
|
|
int seq = 0;
|
|
int seq = 0;
|
|
|
int limit = 200;
|
|
int limit = 200;
|
|
|
|
|
+ if (pageSeq != null || pageLimit!=null){
|
|
|
|
|
+ seq=pageSeq;
|
|
|
|
|
+ limit = pageLimit;
|
|
|
|
|
+ }
|
|
|
long slice = Finance.NewSlice();
|
|
long slice = Finance.NewSlice();
|
|
|
ret = Finance.GetChatData(sdk, seq, limit, null, null, 3, slice);
|
|
ret = Finance.GetChatData(sdk, seq, limit, null, null, 3, slice);
|
|
|
if (ret != 0) {
|
|
if (ret != 0) {
|
|
@@ -85,8 +91,8 @@ public class ConversationContentServiceImpl implements ConversationContentServic
|
|
|
String getchatdata = Finance.GetContentFromSlice(slice);
|
|
String getchatdata = Finance.GetContentFromSlice(slice);
|
|
|
JSONObject jo = new JSONObject(getchatdata);
|
|
JSONObject jo = new JSONObject(getchatdata);
|
|
|
JSONArray chatdata = jo.getJSONArray("chatdata");
|
|
JSONArray chatdata = jo.getJSONArray("chatdata");
|
|
|
-
|
|
|
|
|
- System.out.println("消息数:" + chatdata.length());
|
|
|
|
|
|
|
+ total=chatdata.length();
|
|
|
|
|
+ System.out.println("消息数:" + total);
|
|
|
for (int i = 0; i < chatdata.length(); i++) {
|
|
for (int i = 0; i < chatdata.length(); i++) {
|
|
|
String item = chatdata.get(i).toString();
|
|
String item = chatdata.get(i).toString();
|
|
|
// item:{
|
|
// item:{
|
|
@@ -114,16 +120,19 @@ public class ConversationContentServiceImpl implements ConversationContentServic
|
|
|
// return;
|
|
// return;
|
|
|
}
|
|
}
|
|
|
String str = String.valueOf(Finance.GetContentFromSlice(msg));
|
|
String str = String.valueOf(Finance.GetContentFromSlice(msg));
|
|
|
- System.out.println("decrypt ret:" + ret + " msg:" + str);
|
|
|
|
|
|
|
+ com.alibaba.fastjson.JSONObject jsonObject = com.alibaba.fastjson.JSONObject.parseObject(str);
|
|
|
|
|
+ InputChatMsg chatMsg = new InputChatMsg(jsonObject);
|
|
|
|
|
+ list.add(chatMsg);
|
|
|
Finance.FreeSlice(msg);
|
|
Finance.FreeSlice(msg);
|
|
|
- list.add(str);
|
|
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
Finance.FreeSlice(slice);
|
|
Finance.FreeSlice(slice);
|
|
|
- return list;
|
|
|
|
|
|
|
+ map.put("list",list);
|
|
|
|
|
+ map.put("total",total);
|
|
|
|
|
+ return map;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -164,44 +173,46 @@ public class ConversationContentServiceImpl implements ConversationContentServic
|
|
|
System.out.println(result.getString("errcode"));
|
|
System.out.println(result.getString("errcode"));
|
|
|
System.out.println("获取会话内容存档成员列表失败");
|
|
System.out.println("获取会话内容存档成员列表失败");
|
|
|
}
|
|
}
|
|
|
- pushMsg(result.toJSONString());
|
|
|
|
|
|
|
+ getChatName(result.toJSONString());
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public void pushMsg(String msg){
|
|
|
|
|
- msg="{\"msgid\":\"1634016854685227651_1749628622146_external\",\"action\":\"send\"," +
|
|
|
|
|
- "\"from\":\"wopeIoCwAArS1POCA5Fiw6VidWWqkwVA\",\"tolist\":[\"KaKa\"],\"roomid\":\"\",\"msgtime\":1749628618742,\"msgtype\":\"text\",\"" +
|
|
|
|
|
- "text\":{\"content\":\"您好,请详细描述您的问题,以便更快得到解答!\"}}";
|
|
|
|
|
- com.alibaba.fastjson.JSONObject jsonObject = com.alibaba.fastjson.JSONObject.parseObject(msg);
|
|
|
|
|
- //直接转成对象
|
|
|
|
|
- ChatMsg chatMsg = new ChatMsg(jsonObject);
|
|
|
|
|
- System.out.println(chatMsg);
|
|
|
|
|
- String msgIdSub = chatMsg.getMsgid().substring(0, 2);
|
|
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public String getChatName(String msg) {
|
|
|
|
|
+// msg="{\"msgid\":\"1634016854685227651_1749628622146_external\",\"action\":\"send\"," +
|
|
|
|
|
+// "\"from\":\"wopeIoCwAArS1POCA5Fiw6VidWWqkwVA\",\"tolist\":[\"KaKa\"],\"roomid\":\"\",\"msgtime\":1749628618742,\"msgtype\":\"text\",\"" +
|
|
|
|
|
+// "text\":{\"content\":\"您好,请详细描述您的问题,以便更快得到解答!\"}}";
|
|
|
|
|
+// com.alibaba.fastjson.JSONObject jsonObject = com.alibaba.fastjson.JSONObject.parseObject(msg);
|
|
|
|
|
+// //直接转成对象
|
|
|
|
|
+// InputChatMsg chatMsg = new InputChatMsg(jsonObject);
|
|
|
|
|
+ String msgIdSub = msg.substring(0, 2);
|
|
|
String url=null;
|
|
String url=null;
|
|
|
if (msgIdSub.equals("wb")){
|
|
if (msgIdSub.equals("wb")){
|
|
|
- System.out.println("wb=机器人");
|
|
|
|
|
- url=String.format("https://qyapi.weixin.qq.com/cgi-bin/msgaudit/get_robot_info??access_token=%s&robot_id=%s",getAccessToken(),chatMsg.getFrom());
|
|
|
|
|
- }else if (msgIdSub.equals("wo")||msgIdSub.equals("wm")){
|
|
|
|
|
- System.out.println("wo=外部联系人");
|
|
|
|
|
- url=String.format("https://qyapi.weixin.qq.com/cgi-bin/externalcontact/get?access_token=%s&external_userid=%s",getAccessToken(),chatMsg.getFrom());
|
|
|
|
|
|
|
+ url=String.format("https://qyapi.weixin.qq.com/cgi-bin/msgaudit/get_robot_info??access_token=%s&robot_id=%s",getAccessToken(),msg);
|
|
|
|
|
+ }else if (msgIdSub.equals("wo")){
|
|
|
|
|
+ // https://qyapi.weixin.qq.com/cgi-bin/externalcontact/get?access_token=ACCESS_TOKEN&external_userid=EXTERNAL_USERID&cursor=CURSOR
|
|
|
|
|
+ url=String.format("https://qyapi.weixin.qq.com/cgi-bin/externalcontact/get?access_token=%s&external_userid=%s",getAccessToken(),msg);
|
|
|
|
|
+ }else if (msgIdSub.equals("wm")){
|
|
|
|
|
+ url=String.format("https://qyapi.weixin.qq.com/cgi-bin/externalcontact/get?access_token=%s&external_userid=%s",getAccessToken(),msg);
|
|
|
}else {
|
|
}else {
|
|
|
- System.out.println("=内部联系人");
|
|
|
|
|
- url=String.format("https://qyapi.weixin.qq.com/cgi-bin/user/get?access_token=%s&userid=%s",getAccessToken(),chatMsg.getFrom());
|
|
|
|
|
|
|
+ url=String.format("https://qyapi.weixin.qq.com/cgi-bin/user/get?access_token=%s&userid=%s",getAccessToken(),msg);
|
|
|
}
|
|
}
|
|
|
- getUserData(url);
|
|
|
|
|
|
|
+ String userName = getUserName(url);
|
|
|
|
|
+ System.out.println(msg+"="+userName);
|
|
|
|
|
+ return userName;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
- private void getUserData(String url){
|
|
|
|
|
- System.out.println("url="+ url);
|
|
|
|
|
|
|
+ private String getUserName(String url){
|
|
|
com.alibaba.fastjson.JSONObject result = HttpUtils.httpGet(url);
|
|
com.alibaba.fastjson.JSONObject result = HttpUtils.httpGet(url);
|
|
|
if (result.getInteger("errcode")==0){
|
|
if (result.getInteger("errcode")==0){
|
|
|
System.out.println(result.toJSONString());
|
|
System.out.println(result.toJSONString());
|
|
|
|
|
+ return result.getString("name");
|
|
|
}else {
|
|
}else {
|
|
|
System.out.println(result.toJSONString());
|
|
System.out.println(result.toJSONString());
|
|
|
System.out.println("获取会话内容存档成员列表失败");
|
|
System.out.println("获取会话内容存档成员列表失败");
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+ return null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|