微信 获取token
This commit is contained in:
@@ -1,17 +1,13 @@
|
|||||||
package com.czg.service.account.util;
|
package com.czg.service.account.util;
|
||||||
|
|
||||||
import cn.hutool.core.convert.Convert;
|
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.hutool.http.HttpUtil;
|
import cn.hutool.http.HttpUtil;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.czg.constants.ParamCodeCst;
|
import com.czg.constants.ParamCodeCst;
|
||||||
import com.czg.service.RedisService;
|
|
||||||
import com.czg.system.service.SysParamsService;
|
import com.czg.system.service.SysParamsService;
|
||||||
import jakarta.annotation.Resource;
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.dubbo.config.annotation.DubboReference;
|
import org.apache.dubbo.config.annotation.DubboReference;
|
||||||
import org.springframework.context.annotation.Lazy;
|
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
@@ -26,9 +22,7 @@ import java.util.Map;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
@Component
|
@Component
|
||||||
public class AcAccountUtil {
|
public class AcAccountUtil {
|
||||||
@Resource
|
|
||||||
@Lazy
|
|
||||||
private RedisService redisService;
|
|
||||||
@DubboReference
|
@DubboReference
|
||||||
private SysParamsService paramsService;
|
private SysParamsService paramsService;
|
||||||
|
|
||||||
@@ -54,7 +48,7 @@ public class AcAccountUtil {
|
|||||||
String accessToken = getAccessToken();
|
String accessToken = getAccessToken();
|
||||||
// String accessToken = "97_HZVThQrtvOiCZGrr23ZHN0cVpHBJHc18RSFHU6dvkQDMAme4GsG0NU-Dax1HP5Wx-aGa1l35KaqiMVv61TCj0Qk8DK1LC6kQ8uKLDfgRYVJjX3QjcelmIjp4PCkERBeABAUHR";
|
// String accessToken = "97_HZVThQrtvOiCZGrr23ZHN0cVpHBJHc18RSFHU6dvkQDMAme4GsG0NU-Dax1HP5Wx-aGa1l35KaqiMVv61TCj0Qk8DK1LC6kQ8uKLDfgRYVJjX3QjcelmIjp4PCkERBeABAUHR";
|
||||||
if (StrUtil.isBlank(accessToken)) {
|
if (StrUtil.isBlank(accessToken)) {
|
||||||
log.error("获取 access_token 失败");
|
log.error("银收客czg 公众号获取 access_token 失败");
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
String bodyJson = "{\"action_info\":{\"scene\":{\"scene_str\":\"" + userId + "\"}},\"action_name\":\"QR_STR_SCENE\",\"expire_seconds\":\"2592000\"}";
|
String bodyJson = "{\"action_info\":{\"scene\":{\"scene_str\":\"" + userId + "\"}},\"action_name\":\"QR_STR_SCENE\",\"expire_seconds\":\"2592000\"}";
|
||||||
@@ -87,23 +81,24 @@ public class AcAccountUtil {
|
|||||||
|
|
||||||
|
|
||||||
public String getAccessToken() {
|
public String getAccessToken() {
|
||||||
String accessToken = Convert.toStr(redisService.get("wx:ac:AccessToken"));
|
|
||||||
if (StrUtil.isNotEmpty(accessToken)) {
|
|
||||||
return accessToken;
|
|
||||||
}
|
|
||||||
Map<String, String> userAc = paramsService.getParamsByMap("user_ac_key_set", ParamCodeCst.USER_AC_KEY_SET);
|
Map<String, String> userAc = paramsService.getParamsByMap("user_ac_key_set", ParamCodeCst.USER_AC_KEY_SET);
|
||||||
// 用户小程序参数
|
// 用户小程序参数
|
||||||
String acAppId = userAc.get(ParamCodeCst.Wechat.Ac.USER_WX_AC_APP_ID);
|
String acAppId = userAc.get(ParamCodeCst.Wechat.Ac.USER_WX_AC_APP_ID);
|
||||||
String acSecrete = userAc.get(ParamCodeCst.Wechat.Ac.USER_WX_AC_SECRETE);
|
String acSecrete = userAc.get(ParamCodeCst.Wechat.Ac.USER_WX_AC_SECRETE);
|
||||||
String resp = HttpUtil.get(StrUtil.format("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={}&secret={}", acAppId, acSecrete));
|
|
||||||
JSONObject respInfo = JSONObject.parseObject(resp);
|
String resp = HttpUtil.get(StrUtil.format("https://access-token.sxczgkj.com/accessToken?appId={}&appSecret={}", acAppId, acSecrete));
|
||||||
if (!respInfo.containsKey("access_token")) {
|
// 响应 {"accessToken":"100_6C_jltHANT1y2Fot5PXKFDzPXTyWumCsao0oMoNRvJUTuxS0IOVO4nBmjdmx5dZfYItShFVSAKYzNDf7ZGLPlx52ii1Y1qerrbbSmIiLWCrec5qjBY4gV5Tfv8YKKTdABAEEN","appId":"wx212769170d2c6b2a"}
|
||||||
log.warn("公众号获取token失败, 响应内容: {}", resp);
|
if (StrUtil.isNotBlank(resp)) {
|
||||||
return "";
|
JSONObject respInfo = JSONObject.parseObject(resp);
|
||||||
|
return respInfo.getString("accessToken");
|
||||||
|
} else {
|
||||||
|
String resp2 = HttpUtil.get(StrUtil.format("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={}&secret={}", acAppId, acSecrete));
|
||||||
|
JSONObject respInfo = JSONObject.parseObject(resp2);
|
||||||
|
if (!respInfo.containsKey("access_token")) {
|
||||||
|
log.warn("银收客czg 公众号获取token失败, 响应内容: {}", resp2);
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
return respInfo.getString("access_token");
|
||||||
}
|
}
|
||||||
accessToken = respInfo.getString("access_token");
|
|
||||||
int expiresIn = respInfo.getInteger("expires_in");
|
|
||||||
redisService.set("wx:ac:AccessToken", accessToken, expiresIn - 10);
|
|
||||||
return accessToken;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
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;
|
||||||
@@ -11,6 +10,7 @@ import com.alibaba.fastjson2.JSON;
|
|||||||
import com.alibaba.fastjson2.JSONObject;
|
import com.alibaba.fastjson2.JSONObject;
|
||||||
import com.czg.config.RedisCst;
|
import com.czg.config.RedisCst;
|
||||||
import com.czg.constants.ParamCodeCst;
|
import com.czg.constants.ParamCodeCst;
|
||||||
|
import com.czg.exception.CzgException;
|
||||||
import com.czg.resp.CzgResult;
|
import com.czg.resp.CzgResult;
|
||||||
import com.czg.service.RedisService;
|
import com.czg.service.RedisService;
|
||||||
import com.czg.system.dto.SysParamsDTO;
|
import com.czg.system.dto.SysParamsDTO;
|
||||||
@@ -140,7 +140,7 @@ public class WechatMiniMsgUtil {
|
|||||||
|
|
||||||
public String getAccountOpenId(String code) {
|
public String getAccountOpenId(String code) {
|
||||||
Map<String, String> shopAc = sysParamsService.getParamsByMap("shop_ac_key_set", ParamCodeCst.SHOP_AC_KEY_SET);
|
Map<String, String> shopAc = sysParamsService.getParamsByMap("shop_ac_key_set", ParamCodeCst.SHOP_AC_KEY_SET);
|
||||||
String accountAppId = shopAc.get(ParamCodeCst.Wechat.Ac.SHOP_WX_AC_APP_ID);
|
String accountAppId = shopAc.get(ParamCodeCst.Wechat.Ac.SHOP_WX_AC_APP_ID);
|
||||||
String accountSecrete = shopAc.get(ParamCodeCst.Wechat.Ac.SHOP_WX_AC_SECRETE);
|
String accountSecrete = shopAc.get(ParamCodeCst.Wechat.Ac.SHOP_WX_AC_SECRETE);
|
||||||
String requestUrl = "https://api.weixin.qq.com/sns/oauth2/access_token?";
|
String requestUrl = "https://api.weixin.qq.com/sns/oauth2/access_token?";
|
||||||
Map<String, Object> requestUrlParam = new HashMap<>();
|
Map<String, Object> requestUrlParam = new HashMap<>();
|
||||||
@@ -162,25 +162,23 @@ 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;
|
|
||||||
}
|
|
||||||
// 商户小程序参数
|
// 商户小程序参数
|
||||||
Map<String, String> shopMiniKeyMap = sysParamsService.getParamsByMap("shop_mini_key_set", ParamCodeCst.SHOP_MINI_KEY_SET);
|
Map<String, String> shopMiniKeyMap = sysParamsService.getParamsByMap("shop_mini_key_set", ParamCodeCst.SHOP_MINI_KEY_SET);
|
||||||
String appId = shopMiniKeyMap.get(ParamCodeCst.Wechat.Mini.SHOP_WX_APP_ID);
|
String appId = shopMiniKeyMap.get(ParamCodeCst.Wechat.Mini.SHOP_WX_APP_ID);
|
||||||
String secrete = shopMiniKeyMap.get(ParamCodeCst.Wechat.Mini.SHOP_WX_SECRETE);
|
String secrete = shopMiniKeyMap.get(ParamCodeCst.Wechat.Mini.SHOP_WX_SECRETE);
|
||||||
|
|
||||||
String url = String.format("%s?grant_type=client_credential&appid=%s&secret=%s", TOKEN_URL, appId, secrete);
|
String resp = HttpUtil.get(StrUtil.format("https://access-token.sxczgkj.com/accessToken?appId={}&appSecret={}", appId, secrete));
|
||||||
String response = HttpUtil.get(url);
|
if (StrUtil.isNotBlank(resp)) {
|
||||||
JSONObject jsonResponse = JSONObject.parseObject(response);
|
JSONObject respInfo = JSONObject.parseObject(resp);
|
||||||
if (!jsonResponse.containsKey("access_token")) {
|
return respInfo.getString("accessToken");
|
||||||
throw new RuntimeException("Failed to retrieve access token: " + response);
|
} else {
|
||||||
|
String response = HttpUtil.get(String.format("%s?grant_type=client_credential&appid=%s&secret=%s", TOKEN_URL, appId, secrete));
|
||||||
|
JSONObject jsonResponse = JSONObject.parseObject(response);
|
||||||
|
if (!jsonResponse.containsKey("access_token")) {
|
||||||
|
throw new CzgException("零点八零商户端 获取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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,15 +1,14 @@
|
|||||||
package com.czg.service.market.service.impl;
|
package com.czg.service.market.service.impl;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.hutool.crypto.SecureUtil;
|
import cn.hutool.crypto.SecureUtil;
|
||||||
import cn.hutool.http.HttpUtil;
|
import cn.hutool.http.HttpUtil;
|
||||||
import com.alibaba.fastjson2.JSONObject;
|
import com.alibaba.fastjson2.JSONObject;
|
||||||
import com.czg.constants.ParamCodeCst;
|
import com.czg.constants.ParamCodeCst;
|
||||||
import com.czg.exception.CzgException;
|
import com.czg.exception.CzgException;
|
||||||
import com.czg.service.RedisService;
|
|
||||||
import com.czg.system.service.SysParamsService;
|
import com.czg.system.service.SysParamsService;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.dubbo.config.annotation.DubboReference;
|
import org.apache.dubbo.config.annotation.DubboReference;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.context.annotation.Primary;
|
import org.springframework.context.annotation.Primary;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
@@ -17,6 +16,7 @@ import java.util.Map;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 微信支付service
|
* 微信支付service
|
||||||
|
*
|
||||||
* @author Administrator
|
* @author Administrator
|
||||||
*/
|
*/
|
||||||
@Component
|
@Component
|
||||||
@@ -27,35 +27,26 @@ public class AppWxServiceImpl extends BaseWx {
|
|||||||
@DubboReference
|
@DubboReference
|
||||||
private SysParamsService paramsService;
|
private SysParamsService paramsService;
|
||||||
|
|
||||||
public AppWxServiceImpl(@Autowired RedisService autoRedisService) {
|
public AppWxServiceImpl() {
|
||||||
this.redisService = autoRedisService;
|
|
||||||
config = new Config();
|
config = new Config();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getAccessToken(boolean refresh) {
|
public String getAccessToken(boolean refresh) {
|
||||||
init();
|
init();
|
||||||
Object token = redisService.get("wx:user:access_token");
|
|
||||||
if (!refresh && token instanceof String) {
|
|
||||||
return (String) token;
|
|
||||||
}
|
|
||||||
|
|
||||||
String response = HttpUtil.get(WX_ACCESS_TOKEN_URL,
|
String resp = HttpUtil.get(StrUtil.format("https://access-token.sxczgkj.com/accessToken?appId={}&appSecret={}", config.appId, config.appSecret));
|
||||||
Map.of("grant_type", "client_credential", "appid", config.appId, "secret", config.appSecret)
|
// 响应 {"accessToken":"100_6C_jltHANT1y2Fot5PXKFDzPXTyWumCsao0oMoNRvJUTuxS0IOVO4nBmjdmx5dZfYItShFVSAKYzNDf7ZGLPlx52ii1Y1qerrbbSmIiLWCrec5qjBY4gV5Tfv8YKKTdABAEEN","appId":"wx212769170d2c6b2a"}
|
||||||
);
|
if (StrUtil.isNotBlank(resp)) {
|
||||||
|
JSONObject respInfo = JSONObject.parseObject(resp);
|
||||||
log.info("获取access_token响应: {}", response);
|
return respInfo.getString("accessToken");
|
||||||
JSONObject jsonObject = JSONObject.parseObject(response);
|
} else {
|
||||||
String accessToken = jsonObject.getString("access_token");
|
String response = HttpUtil.get(WX_ACCESS_TOKEN_URL,
|
||||||
if (accessToken == null) {
|
Map.of("grant_type", "client_credential", "appid", config.appId, "secret", config.appSecret)
|
||||||
throw new RuntimeException("获取access_token失败");
|
);
|
||||||
|
JSONObject jsonObject = JSONObject.parseObject(response);
|
||||||
|
return jsonObject.getString("access_token");
|
||||||
}
|
}
|
||||||
Long expiresIn = jsonObject.getLong("expires_in");
|
|
||||||
if (expiresIn == null) {
|
|
||||||
expiresIn = DEFAULT_EXPIRES_IN;
|
|
||||||
}
|
|
||||||
redisService.set("wx:user:access_token", accessToken, expiresIn - EXPIRES_OFFSET);
|
|
||||||
return accessToken;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -65,7 +56,7 @@ public class AppWxServiceImpl extends BaseWx {
|
|||||||
|
|
||||||
// 微信支付参数
|
// 微信支付参数
|
||||||
Map<String, String> payKeyMap = paramsService.getParamsByMap("pay_key_set", ParamCodeCst.PAY_KEY_SET);
|
Map<String, String> payKeyMap = paramsService.getParamsByMap("pay_key_set", ParamCodeCst.PAY_KEY_SET);
|
||||||
|
|
||||||
// 小程序id
|
// 小程序id
|
||||||
config.appId = userMiniKeyMap.get(ParamCodeCst.Wechat.Mini.USER_WX_APP_ID);
|
config.appId = userMiniKeyMap.get(ParamCodeCst.Wechat.Mini.USER_WX_APP_ID);
|
||||||
// 小程序secrete
|
// 小程序secrete
|
||||||
|
|||||||
@@ -1,18 +1,16 @@
|
|||||||
package com.czg.service.market.service.impl;
|
package com.czg.service.market.service.impl;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.hutool.http.HttpUtil;
|
import cn.hutool.http.HttpUtil;
|
||||||
import com.alibaba.fastjson2.JSONObject;
|
import com.alibaba.fastjson2.JSONObject;
|
||||||
import com.czg.constants.ParamCodeCst;
|
import com.czg.constants.ParamCodeCst;
|
||||||
import com.czg.service.RedisService;
|
|
||||||
import com.czg.system.service.SysParamsService;
|
import com.czg.system.service.SysParamsService;
|
||||||
import com.ijpay.core.kit.RsaKit;
|
import com.ijpay.core.kit.RsaKit;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.dubbo.config.annotation.DubboReference;
|
import org.apache.dubbo.config.annotation.DubboReference;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -27,38 +25,25 @@ public class WxServiceImpl extends BaseWx {
|
|||||||
@DubboReference
|
@DubboReference
|
||||||
private SysParamsService paramsService;
|
private SysParamsService paramsService;
|
||||||
|
|
||||||
private final Set<String> shopMiniKeys = Set.of(ParamCodeCst.Wechat.Mini.SHOP_WX_APP_ID, ParamCodeCst.Wechat.Mini.SHOP_WX_SECRETE);
|
public WxServiceImpl() {
|
||||||
|
|
||||||
|
|
||||||
public WxServiceImpl(@Autowired RedisService redisService) {
|
|
||||||
this.redisService = redisService;
|
|
||||||
config = new Config();
|
config = new Config();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getAccessToken(boolean refresh) {
|
public String getAccessToken(boolean refresh) {
|
||||||
init();
|
init();
|
||||||
Object token = redisService.get("wx:shop:access_token");
|
|
||||||
if (!refresh && token instanceof String) {
|
|
||||||
return (String) token;
|
|
||||||
}
|
|
||||||
|
|
||||||
String response = HttpUtil.get(WX_ACCESS_TOKEN_URL,
|
String resp = HttpUtil.get(StrUtil.format("https://access-token.sxczgkj.com/accessToken?appId={}&appSecret={}", config.appId, config.appSecret));
|
||||||
Map.of("grant_type", "client_credential", "appid", config.appId, "secret", config.appSecret)
|
if (StrUtil.isNotBlank(resp)) {
|
||||||
);
|
JSONObject respInfo = JSONObject.parseObject(resp);
|
||||||
|
return respInfo.getString("accessToken");
|
||||||
log.info("获取access_token响应: {}", response);
|
} else {
|
||||||
JSONObject jsonObject = JSONObject.parseObject(response);
|
String response = HttpUtil.get(WX_ACCESS_TOKEN_URL,
|
||||||
String accessToken = jsonObject.getString("access_token");
|
Map.of("grant_type", "client_credential", "appid", config.appId, "secret", config.appSecret)
|
||||||
if (accessToken == null) {
|
);
|
||||||
throw new RuntimeException("获取access_token失败");
|
JSONObject jsonObject = JSONObject.parseObject(response);
|
||||||
|
return jsonObject.getString("access_token");
|
||||||
}
|
}
|
||||||
Long expiresIn = jsonObject.getLong("expires_in");
|
|
||||||
if (expiresIn == null) {
|
|
||||||
expiresIn = DEFAULT_EXPIRES_IN;
|
|
||||||
}
|
|
||||||
redisService.set("wx:shop:access_token", accessToken, expiresIn - EXPIRES_OFFSET);
|
|
||||||
return accessToken;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -7,12 +7,9 @@ import cn.hutool.http.HttpRequest;
|
|||||||
import cn.hutool.http.HttpUtil;
|
import cn.hutool.http.HttpUtil;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.czg.exception.CzgException;
|
import com.czg.exception.CzgException;
|
||||||
import com.czg.service.RedisService;
|
|
||||||
import jakarta.annotation.Resource;
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.context.annotation.Lazy;
|
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
@@ -41,9 +38,6 @@ public class WxAccountUtil {
|
|||||||
@Value("${wx.ysk.warnMsgTmpId}")
|
@Value("${wx.ysk.warnMsgTmpId}")
|
||||||
private String warnMsgTmpId;
|
private String warnMsgTmpId;
|
||||||
|
|
||||||
@Resource
|
|
||||||
@Lazy
|
|
||||||
private RedisService redisService;
|
|
||||||
|
|
||||||
static LinkedHashMap<String, String> linkedHashMap = new LinkedHashMap<>();
|
static LinkedHashMap<String, String> linkedHashMap = new LinkedHashMap<>();
|
||||||
|
|
||||||
@@ -97,16 +91,20 @@ public class WxAccountUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getAccessToken() {
|
public String getAccessToken() {
|
||||||
String resp = HttpUtil.get(StrUtil.format("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={}&secret={}", appId, secrete));
|
String resp = HttpUtil.get(StrUtil.format("https://access-token.sxczgkj.com/accessToken?appId={}&appSecret={}", appId, secrete));
|
||||||
JSONObject respInfo = JSONObject.parseObject(resp);
|
// 响应 {"accessToken":"100_6C_jltHANT1y2Fot5PXKFDzPXTyWumCsao0oMoNRvJUTuxS0IOVO4nBmjdmx5dZfYItShFVSAKYzNDf7ZGLPlx52ii1Y1qerrbbSmIiLWCrec5qjBY4gV5Tfv8YKKTdABAEEN","appId":"wx212769170d2c6b2a"}
|
||||||
if (!respInfo.containsKey("access_token")) {
|
if(StrUtil.isNotBlank(resp)){
|
||||||
log.warn("公众号获取token失败, 响应内容: {}", resp);
|
JSONObject respInfo = JSONObject.parseObject(resp);
|
||||||
throw new RuntimeException(resp);
|
return respInfo.getString("accessToken");
|
||||||
|
}else {
|
||||||
|
String resp1 = HttpUtil.get(StrUtil.format("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={}&secret={}", appId, secrete));
|
||||||
|
JSONObject respInfo = JSONObject.parseObject(resp1);
|
||||||
|
if (!respInfo.containsKey("access_token")) {
|
||||||
|
log.warn("银收客 公众号获取token失败, 响应内容: {}", resp1);
|
||||||
|
throw new CzgException(resp);
|
||||||
|
}
|
||||||
|
return respInfo.getString("access_token");
|
||||||
}
|
}
|
||||||
String accessToken = respInfo.getString("access_token");
|
|
||||||
// int expiresIn = respInfo.getInteger("expires_in");
|
|
||||||
// redisService.set("accessToken", accessToken, expiresIn - 10);
|
|
||||||
return accessToken;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public JSONObject sendTemplateMsg(String detail, String templateId, String toUserOpenId, Map<String, Object> data) {
|
public JSONObject sendTemplateMsg(String detail, String templateId, String toUserOpenId, Map<String, Object> data) {
|
||||||
|
|||||||
Reference in New Issue
Block a user