|
@@ -64,6 +64,7 @@ public class WxGzhServiceImpl implements IWxGzhService {
|
|
|
|
|
|
private final WxService wxService;
|
|
|
|
|
|
+
|
|
|
@Value("${app.appid}")
|
|
|
private String appid;
|
|
|
|
|
@@ -82,7 +83,7 @@ public class WxGzhServiceImpl implements IWxGzhService {
|
|
|
if (redisTemplate.hasKey(Constants.GZH_MESSAGE_TOKEN)){
|
|
|
token = (String)redisTemplate.opsForValue().get(Constants.GZH_MESSAGE_TOKEN);
|
|
|
}
|
|
|
- if (StringUtils.isEmpty(token)){
|
|
|
+ if (StringUtils.isEmpty(token)|| notEffect(token)){
|
|
|
String result = wxSendService.getAccessToken("client_credential",appid,secret);
|
|
|
JSONObject json = JSONObject.parseObject(result);
|
|
|
token = json.getString("access_token");
|
|
@@ -98,6 +99,13 @@ public class WxGzhServiceImpl implements IWxGzhService {
|
|
|
return token;
|
|
|
}
|
|
|
|
|
|
+ //判定是否失效
|
|
|
+ private boolean notEffect(String token) {
|
|
|
+ String res = wxSendService.userInfo( token, "ovKTX5-FKLF6_sgTtCIXpG_lz3PY", "zh_CN");
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(res);
|
|
|
+ return jsonObject.getString("unionid") ==null;
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
|
|
|
/**
|
|
@@ -176,9 +184,13 @@ public class WxGzhServiceImpl implements IWxGzhService {
|
|
|
String event = jsonObjectData.getStr("Event");
|
|
|
if (MessageUtil.MESSAGE_SUBSCRIBE.equals(event)) { // 关注事件 或 扫描二维码关注事件
|
|
|
log.info("3.1...");
|
|
|
- UserInfo user = userService.getStudentByOpenId(fromUserName);
|
|
|
+ String res = wxSendService.userInfo( this.getGzhToken(), fromUserName, "zh_CN");
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(res);
|
|
|
+ String unionId = jsonObject.getString("unionid");
|
|
|
+ UserInfo user = userService.getStudentByUnionid(unionId);
|
|
|
UserInfo userInfo = new UserInfo();
|
|
|
userInfo.setOpenid(fromUserName);
|
|
|
+ userInfo.setUnionId(unionId);
|
|
|
|
|
|
//存在Ticket为扫码关注
|
|
|
if (org.apache.commons.lang3.StringUtils.isNotEmpty(jsonObjectData.getStr("Ticket"))){
|