From 58f5ec6bc5d4f4a9e13e5dc8f09ea08d61d5165c Mon Sep 17 00:00:00 2001 From: hurui <177768073@qq.com> Date: Mon, 13 Mar 2023 10:33:34 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/hai/config/WeChatQrcodeUtils.java | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) 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"); } /**