Ver código fonte

对公众号token 增加有效性判定

Althars123 3 anos atrás
pai
commit
ff7694535a

+ 8 - 1
twzd-service/src/main/java/com/miaxis/wx/service/impl/WxGzhServiceImpl.java

@@ -83,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");
@@ -99,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;
+
+    }
 
 
     /**