零点八零 缓存
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package com.czg.service.account.util;
|
package com.czg.service.account.util;
|
||||||
|
|
||||||
import cn.hutool.core.codec.Base64;
|
import cn.hutool.core.codec.Base64;
|
||||||
|
import cn.hutool.core.convert.Convert;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.hutool.crypto.symmetric.AES;
|
import cn.hutool.crypto.symmetric.AES;
|
||||||
@@ -162,6 +163,10 @@ public class WechatMiniMsgUtil {
|
|||||||
|
|
||||||
//获取小程序token
|
//获取小程序token
|
||||||
private String getAccessToken() {
|
private String getAccessToken() {
|
||||||
|
String accessToken = Convert.toStr(redisService.get("wx:mini:AccessToken"));
|
||||||
|
if (StrUtil.isNotEmpty(accessToken)) {
|
||||||
|
return accessToken;
|
||||||
|
}
|
||||||
CzgResult<SysParamsDTO> wxMiniAppId = sysParamsService.getParamsByCode("wx_mini_app_id");
|
CzgResult<SysParamsDTO> wxMiniAppId = sysParamsService.getParamsByCode("wx_mini_app_id");
|
||||||
CzgResult<SysParamsDTO> wxMiniSecrete = sysParamsService.getParamsByCode("wx_mini_secrete");
|
CzgResult<SysParamsDTO> wxMiniSecrete = sysParamsService.getParamsByCode("wx_mini_secrete");
|
||||||
String appId = wxMiniAppId.getData().getParamValue();
|
String appId = wxMiniAppId.getData().getParamValue();
|
||||||
@@ -172,7 +177,10 @@ public class WechatMiniMsgUtil {
|
|||||||
if (!jsonResponse.containsKey("access_token")) {
|
if (!jsonResponse.containsKey("access_token")) {
|
||||||
throw new RuntimeException("Failed to retrieve access token: " + response);
|
throw new RuntimeException("Failed to retrieve access token: " + response);
|
||||||
}
|
}
|
||||||
return jsonResponse.getString("access_token");
|
accessToken = jsonResponse.getString("access_token");
|
||||||
|
int expiresIn = jsonResponse.getInteger("expires_in");
|
||||||
|
redisService.set("wx:mini:AccessToken", accessToken, expiresIn - 10);
|
||||||
|
return accessToken;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user