提交代码

dev-discount
胡锐 2 years ago
parent ff0c2b148f
commit 58f5ec6bc5
  1. 20
      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("action_name" , "QR_STR_SCENE");
object.put("expire_seconds" , 2592000); object.put("expire_seconds" , 2592000);
object.put("action_info" , objectActionInfo); object.put("action_info" , objectActionInfo);
return HttpsUtils.doPost("https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=" + getWxToken(), object);
if (redisUtil.get("WxToken") == null) {
getWxToken();
}
return HttpsUtils.doPost("https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=" + redisUtil.get("WxToken"), object);
} }
// 获取微信Token存入redis // 获取微信Token存入redis
public void getWxToken() { public String getWxToken() {
Object token = redisUtil.get("WxToken");
if (null != token) {
return token.toString();
};
// 获取access_token // 获取access_token
Map<String, Object> params = new HashMap<>(); Map<String, Object> params = new HashMap<>();
params.put("appid", CommonSysConst.getSysConfig().getWxH5AppId()); params.put("appid", CommonSysConst.getSysConfig().getWxH5AppId());
params.put("secret", CommonSysConst.getSysConfig().getWxH5AppSecret()); params.put("secret", CommonSysConst.getSysConfig().getWxH5AppSecret());
params.put("grant_type", "client_credential"); params.put("grant_type", "client_credential");
JSONObject accessTokenObject = HttpsUtils.doGet("https://api.weixin.qq.com/cgi-bin/token", params); JSONObject accessTokenObject = HttpsUtils.doGet("https://api.weixin.qq.com/cgi-bin/token", params);
redisUtil.set("WxToken" , accessTokenObject.getString("access_token") , 7000);
if (accessTokenObject != null && accessTokenObject.getString("access_token") != null) { return accessTokenObject.getString("access_token");
redisUtil.set("WxToken" , accessTokenObject.getString("access_token") , 7000);
}
} }
/** /**

Loading…
Cancel
Save