|
@@ -1,4 +1,4 @@
|
|
|
-package com.kede.wechat.service.impl;
|
|
|
|
|
|
|
+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;
|
|
@@ -15,7 +15,6 @@ import org.springframework.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
|
-import java.sql.SQLOutput;
|
|
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
|
|
|
|
@Service("ConversationContentService")
|
|
@Service("ConversationContentService")
|
|
@@ -25,6 +24,7 @@ public class ConversationContentServiceImpl implements ConversationContentServic
|
|
|
@Resource
|
|
@Resource
|
|
|
private RedisTemplate redisTemplate;
|
|
private RedisTemplate redisTemplate;
|
|
|
|
|
|
|
|
|
|
+
|
|
|
@Value(value = "${conversationContent.corpid}")
|
|
@Value(value = "${conversationContent.corpid}")
|
|
|
private String corpid;
|
|
private String corpid;
|
|
|
@Value(value = "${conversationContent.secret}")
|
|
@Value(value = "${conversationContent.secret}")
|
|
@@ -141,8 +141,6 @@ public class ConversationContentServiceImpl implements ConversationContentServic
|
|
|
logger.debug("getAccessToken有缓存从缓存获取");
|
|
logger.debug("getAccessToken有缓存从缓存获取");
|
|
|
accessToken = accessMap.get("accessToken");
|
|
accessToken = accessMap.get("accessToken");
|
|
|
Long expireDate = Long.valueOf(accessMap.get("expireDate"));
|
|
Long expireDate = Long.valueOf(accessMap.get("expireDate"));
|
|
|
- System.out.println(expireDate);
|
|
|
|
|
- System.out.println(System.currentTimeMillis());
|
|
|
|
|
if (expireDate < System.currentTimeMillis()){
|
|
if (expireDate < System.currentTimeMillis()){
|
|
|
logger.debug("getAccessToken缓存已过期从接口获取");
|
|
logger.debug("getAccessToken缓存已过期从接口获取");
|
|
|
Map<String, String> map = getAccessMap();
|
|
Map<String, String> map = getAccessMap();
|
|
@@ -176,8 +174,34 @@ public class ConversationContentServiceImpl implements ConversationContentServic
|
|
|
"text\":{\"content\":\"您好,请详细描述您的问题,以便更快得到解答!\"}}";
|
|
"text\":{\"content\":\"您好,请详细描述您的问题,以便更快得到解答!\"}}";
|
|
|
com.alibaba.fastjson.JSONObject jsonObject = com.alibaba.fastjson.JSONObject.parseObject(msg);
|
|
com.alibaba.fastjson.JSONObject jsonObject = com.alibaba.fastjson.JSONObject.parseObject(msg);
|
|
|
//直接转成对象
|
|
//直接转成对象
|
|
|
- ChatMsg chatMsg = com.alibaba.fastjson.JSONObject.toJavaObject(jsonObject, ChatMsg.class);
|
|
|
|
|
|
|
+ ChatMsg chatMsg = new ChatMsg(jsonObject);
|
|
|
System.out.println(chatMsg);
|
|
System.out.println(chatMsg);
|
|
|
|
|
+ String msgIdSub = chatMsg.getMsgid().substring(0, 2);
|
|
|
|
|
+ String url=null;
|
|
|
|
|
+ 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());
|
|
|
|
|
+ }else {
|
|
|
|
|
+ System.out.println("=内部联系人");
|
|
|
|
|
+ url=String.format("https://qyapi.weixin.qq.com/cgi-bin/user/get?access_token=%s&userid=%s",getAccessToken(),chatMsg.getFrom());
|
|
|
|
|
+ }
|
|
|
|
|
+ getUserData(url);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ private void getUserData(String url){
|
|
|
|
|
+ System.out.println("url="+ url);
|
|
|
|
|
+ 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("获取会话内容存档成员列表失败");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|