零点八零 缓存

This commit is contained in:
2025-12-18 14:22:53 +08:00
parent b994ac7fcf
commit eacc864c5c

View File

@@ -1,6 +1,7 @@
package com.czg.service.account.util;
import cn.hutool.core.codec.Base64;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.symmetric.AES;
@@ -61,21 +62,21 @@ public class WechatMiniMsgUtil {
public JSONObject sendTempMsg(String tempId, String toUserOpenId, Map<String, Object> data, String note) {
log.info("开始发送" + note + "模板消息, 接收用户openId: {}, 消息数据: {}", toUserOpenId, data);
String token= getAccessToken();
String token = getAccessToken();
JSONObject object1=new JSONObject();
JSONObject object1 = new JSONObject();
object1.put("template_id", tempId);
object1.put("touser", toUserOpenId);
object1.put("data",data);
object1.put("data", data);
object1.put("miniprogram_state","trial");
object1.put("lang","zh_CN");
object1.put("miniprogram_state", "trial");
object1.put("lang", "zh_CN");
String response= HttpRequest.post("https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=".concat(token)).body(object1.toString()).execute().body();
log.info("微信模板消息发送成功,相应内容:{}",response);
JSONObject resObj= JSONObject.parseObject(response);
if(ObjectUtil.isNotEmpty(resObj)&&ObjectUtil.isNotNull(resObj)&&"0".equals(resObj.get("errcode")+"")){
String response = HttpRequest.post("https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=".concat(token)).body(object1.toString()).execute().body();
log.info("微信模板消息发送成功,相应内容:{}", response);
JSONObject resObj = JSONObject.parseObject(response);
if (ObjectUtil.isNotEmpty(resObj) && ObjectUtil.isNotNull(resObj) && "0".equals(resObj.get("errcode") + "")) {
return resObj;
}
@@ -162,6 +163,10 @@ public class WechatMiniMsgUtil {
//获取小程序token
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> wxMiniSecrete = sysParamsService.getParamsByCode("wx_mini_secrete");
String appId = wxMiniAppId.getData().getParamValue();
@@ -172,7 +177,10 @@ public class WechatMiniMsgUtil {
if (!jsonResponse.containsKey("access_token")) {
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;
}
/**