perf:移除TimedCacheService、TimedCacheHelper,新增TsCacheService,同时实现了内存缓存、Redis缓存
This commit is contained in:
@@ -10,8 +10,8 @@ import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import cn.hutool.log.LogFactory;
|
||||
import com.tiesheng.platform.config.ding.bean.*;
|
||||
import com.tiesheng.util.TimedCacheHelper;
|
||||
import com.tiesheng.util.exception.ApiException;
|
||||
import com.tiesheng.util.service.TsCacheService;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@@ -94,7 +94,7 @@ public class PlatformDingConfig {
|
||||
*/
|
||||
private String getAccessToken(String service) {
|
||||
DingConfigBean dingConfigBean = getConfigBean(service);
|
||||
String accessToken = TimedCacheHelper.getTimedCache().get(CACHE_ACCESS_TOKEN + dingConfigBean.getAppKey(), false);
|
||||
String accessToken = TsCacheService.of().get(CACHE_ACCESS_TOKEN + dingConfigBean.getAppKey(), -1);
|
||||
if (!StrUtil.isEmpty(accessToken)) {
|
||||
return accessToken;
|
||||
}
|
||||
@@ -106,7 +106,8 @@ public class PlatformDingConfig {
|
||||
String response = HttpUtil.get("https://oapi.dingtalk.com/gettoken", query);
|
||||
JSONObject respJson = JSONUtil.parseObj(response);
|
||||
accessToken = respJson.getStr("access_token");
|
||||
TimedCacheHelper.getTimedCache().put(CACHE_ACCESS_TOKEN + dingConfigBean.getAppKey(), accessToken, respJson.getLong("expires_in"));
|
||||
TsCacheService.of().put(CACHE_ACCESS_TOKEN + dingConfigBean.getAppKey(),
|
||||
accessToken, respJson.getLong("expires_in"));
|
||||
|
||||
return accessToken;
|
||||
}
|
||||
@@ -120,7 +121,7 @@ public class PlatformDingConfig {
|
||||
*/
|
||||
private String getJsapiTicket(String service) {
|
||||
DingConfigBean dingConfigBean = getConfigBean(service);
|
||||
String jsapiTicket = TimedCacheHelper.getTimedCache().get(CACHE_JSAPI_TICKET + dingConfigBean.getAppKey(), false);
|
||||
String jsapiTicket = TsCacheService.of().get(CACHE_JSAPI_TICKET + dingConfigBean.getAppKey(), -1);
|
||||
if (StrUtil.isEmpty(jsapiTicket)) {
|
||||
DingResponse<String> respJson = doRequest(service, "https://oapi.dingtalk.com/get_jsapi_ticket", null,
|
||||
new TypeReference<DingResponse<String>>() {
|
||||
@@ -129,7 +130,7 @@ public class PlatformDingConfig {
|
||||
throw new ApiException(respJson.getErrmsg());
|
||||
}
|
||||
jsapiTicket = respJson.getTicket();
|
||||
TimedCacheHelper.getTimedCache().put(CACHE_JSAPI_TICKET + dingConfigBean.getAppKey(),
|
||||
TsCacheService.of().put(CACHE_JSAPI_TICKET + dingConfigBean.getAppKey(),
|
||||
jsapiTicket, respJson.getExpiresIn());
|
||||
}
|
||||
return jsapiTicket;
|
||||
|
||||
@@ -12,8 +12,8 @@ import com.tiesheng.platform.config.wxmp.bean.WxConfigBean;
|
||||
import com.tiesheng.platform.config.wxmp.bean.WxJsapiSignature;
|
||||
import com.tiesheng.platform.config.wxmp.bean.WxOAuth2AccessToken;
|
||||
import com.tiesheng.platform.config.wxmp.bean.WxUserInfo;
|
||||
import com.tiesheng.util.TimedCacheHelper;
|
||||
import com.tiesheng.util.exception.ApiException;
|
||||
import com.tiesheng.util.service.TsCacheService;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@@ -63,17 +63,17 @@ public class PlatformWxmpConfig {
|
||||
*/
|
||||
private String getAccessToken(String service) {
|
||||
WxConfigBean configBean = getConfigBean(service);
|
||||
String accessToken = TimedCacheHelper.getTimedCache().get(CACHE_ACCESS_TOKEN + configBean.getAppId(), false);
|
||||
String accessToken = TsCacheService.of().get(CACHE_ACCESS_TOKEN + configBean.getAppId(), -1);
|
||||
if (StrUtil.isEmpty(accessToken)) {
|
||||
Map<String, Object> query = new HashMap<>(10);
|
||||
query.put("grant_type", "client_credential");
|
||||
query.put("appid", configBean.getAppId());
|
||||
query.put("secret", configBean.getAppSecret());
|
||||
String response = HttpUtil.get("https://api.weixin.qq.com/cgi-bin/token", query);
|
||||
LogFactory.get().info("getAccessToken: " + response);
|
||||
JSONObject respJson = JSONUtil.parseObj(response);
|
||||
accessToken = respJson.getStr("access_token");
|
||||
TimedCacheHelper.getTimedCache().put(CACHE_ACCESS_TOKEN + configBean.getAppId(), accessToken, respJson.getLong("expires_in"));
|
||||
TsCacheService.of().put(CACHE_ACCESS_TOKEN + configBean.getAppId(), accessToken,
|
||||
respJson.getLong("expires_in"));
|
||||
}
|
||||
return accessToken;
|
||||
}
|
||||
@@ -86,7 +86,7 @@ public class PlatformWxmpConfig {
|
||||
*/
|
||||
private String getJsapiTicket(String service) {
|
||||
WxConfigBean configBean = getConfigBean(service);
|
||||
String jsapiTicket = TimedCacheHelper.getTimedCache().get(CACHE_JSAPI_TICKET + configBean.getAppId(), false);
|
||||
String jsapiTicket = TsCacheService.of().get(CACHE_JSAPI_TICKET + configBean.getAppId(), -1);
|
||||
if (StrUtil.isEmpty(jsapiTicket)) {
|
||||
Map<String, Object> query = new HashMap<>(10);
|
||||
query.put("access_token", getAccessToken(service));
|
||||
@@ -95,7 +95,8 @@ public class PlatformWxmpConfig {
|
||||
LogFactory.get().info("getJsapiTicket: " + response);
|
||||
JSONObject respJson = JSONUtil.parseObj(response);
|
||||
jsapiTicket = respJson.getStr("ticket");
|
||||
TimedCacheHelper.getTimedCache().put(CACHE_JSAPI_TICKET + configBean.getAppId(), jsapiTicket, respJson.getLong("expires_in"));
|
||||
TsCacheService.of().put(CACHE_JSAPI_TICKET + configBean.getAppId(), jsapiTicket,
|
||||
respJson.getLong("expires_in"));
|
||||
}
|
||||
return jsapiTicket;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user