diff --git a/hai-service/src/main/java/com/hai/config/WeChatQrcodeUtils.java b/hai-service/src/main/java/com/hai/config/WeChatQrcodeUtils.java index b515d2ca..b3da3b39 100644 --- a/hai-service/src/main/java/com/hai/config/WeChatQrcodeUtils.java +++ b/hai-service/src/main/java/com/hai/config/WeChatQrcodeUtils.java @@ -113,28 +113,24 @@ public class WeChatQrcodeUtils { object.put("action_name" , "QR_STR_SCENE"); object.put("expire_seconds" , 2592000); object.put("action_info" , objectActionInfo); - - if (redisUtil.get("WxToken") == null) { - getWxToken(); - } - - return HttpsUtils.doPost("https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=" + redisUtil.get("WxToken"), object); + return HttpsUtils.doPost("https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=" + getWxToken(), object); } // 获取微信Token存入redis - public void getWxToken() { + public String getWxToken() { + Object token = redisUtil.get("WxToken"); + if (null != token) { + return token.toString(); + }; // 获取access_token Map params = new HashMap<>(); params.put("appid", CommonSysConst.getSysConfig().getWxH5AppId()); params.put("secret", CommonSysConst.getSysConfig().getWxH5AppSecret()); params.put("grant_type", "client_credential"); JSONObject accessTokenObject = HttpsUtils.doGet("https://api.weixin.qq.com/cgi-bin/token", params); - - if (accessTokenObject != null && accessTokenObject.getString("access_token") != null) { - redisUtil.set("WxToken" , accessTokenObject.getString("access_token") , 7000); - } - + redisUtil.set("WxToken" , accessTokenObject.getString("access_token") , 7000); + return accessTokenObject.getString("access_token"); } /**