|
|
@@ -1,6 +1,7 @@
|
|
|
package com.sqx.modules.utils;
|
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
+import cn.hutool.http.HttpUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.google.common.collect.Maps;
|
|
|
@@ -8,12 +9,16 @@ import com.sqx.common.constant.RedisKey;
|
|
|
import com.sqx.common.utils.RedisUtils;
|
|
|
import com.sqx.modules.common.entity.CommonInfo;
|
|
|
import com.sqx.modules.common.service.CommonInfoService;
|
|
|
+import icu.xuyijie.secureapi.cipher.CipherAlgorithmEnum;
|
|
|
+import icu.xuyijie.secureapi.cipher.CipherUtils;
|
|
|
+import icu.xuyijie.secureapi.model.SecureApiPropertiesConfig;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.io.IOUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
@@ -42,25 +47,33 @@ public class SenInfoCheckUtil {
|
|
|
|
|
|
private static RedisUtils redisUtils;
|
|
|
|
|
|
+ private static boolean GET_MP_TOKEN_FROM_TEMP;
|
|
|
+ private static SecureApiPropertiesConfig SECUREAPIPROPERTIESCONFIG;
|
|
|
+
|
|
|
// 注入的时候,给类的 service 注入
|
|
|
@Autowired
|
|
|
- public void setWxChatContentService(CommonInfoService commonInfoService, RedisUtils redisUtils) {
|
|
|
+ public void setWxChatContentService(CommonInfoService commonInfoService, RedisUtils redisUtils, @Value("${mp.temp:false}") boolean isTemp, SecureApiPropertiesConfig secureApiPropertiesConfig) {
|
|
|
SenInfoCheckUtil.commonInfoService = commonInfoService;
|
|
|
SenInfoCheckUtil.redisUtils = redisUtils;
|
|
|
+ SenInfoCheckUtil.GET_MP_TOKEN_FROM_TEMP = isTemp;
|
|
|
+ SenInfoCheckUtil.SECUREAPIPROPERTIESCONFIG = secureApiPropertiesConfig;
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 获取Token 小程序
|
|
|
- * @param
|
|
|
- * @param
|
|
|
* @return AccessToken
|
|
|
*/
|
|
|
public static String getMpToken(){
|
|
|
String token = (String) redisUtils.get(RedisKey.MP_TOKEN_CACHE_KEY);
|
|
|
if (StrUtil.isBlank(token)) {
|
|
|
- token = getMpAccessToken();
|
|
|
-
|
|
|
+ if (!GET_MP_TOKEN_FROM_TEMP) {
|
|
|
+ token = getMpAccessToken();
|
|
|
+ } else {
|
|
|
+ try {
|
|
|
+ token = doDecrypt(HttpUtil.get("https://mxys.chuanghai-tech.com/sqx_fast/app/wxPay/temp/token/1"));
|
|
|
+ } catch (Exception e) {}
|
|
|
+ }
|
|
|
redisUtils.set(RedisKey.MP_TOKEN_CACHE_KEY, token, RedisUtils.HOUR_ONE_EXPIRE);
|
|
|
}
|
|
|
return token;
|
|
|
@@ -68,30 +81,46 @@ public class SenInfoCheckUtil {
|
|
|
|
|
|
/**
|
|
|
* 获取Token 小程序
|
|
|
- * @param
|
|
|
- * @param
|
|
|
* @return AccessToken
|
|
|
*/
|
|
|
- public static String getRiderMpToken(){
|
|
|
+ public static String getRiderMpToken() {
|
|
|
String token = (String) redisUtils.get(RedisKey.MP_OF_RIDER_TOKEN_CACHE_KEY);
|
|
|
if (StrUtil.isBlank(token)) {
|
|
|
- token = getRiderMpAccessToken();
|
|
|
+ if (!GET_MP_TOKEN_FROM_TEMP) {
|
|
|
+ token = getRiderMpAccessToken();
|
|
|
+ } else {
|
|
|
+ try {
|
|
|
+ token = doDecrypt(HttpUtil.get("https://mxys.chuanghai-tech.com/sqx_fast/app/wxPay/temp/token/1"));
|
|
|
+ } catch (Exception e) {}
|
|
|
+ }
|
|
|
|
|
|
redisUtils.set(RedisKey.MP_OF_RIDER_TOKEN_CACHE_KEY, token, RedisUtils.HOUR_ONE_EXPIRE);
|
|
|
}
|
|
|
return token;
|
|
|
}
|
|
|
|
|
|
- public static String getShopMpToken(){
|
|
|
+ public static String getShopMpToken() {
|
|
|
String token = (String) redisUtils.get(RedisKey.MP_OF_SHOP_TOKEN_CACHE_KEY);
|
|
|
if (StrUtil.isBlank(token)) {
|
|
|
- token = getShopMpAccessToken();
|
|
|
+ if (!GET_MP_TOKEN_FROM_TEMP) {
|
|
|
+ token = getShopMpAccessToken();
|
|
|
+ } else {
|
|
|
+ try {
|
|
|
+ token = doDecrypt(HttpUtil.get("https://mxys.chuanghai-tech.com/sqx_fast/app/wxPay/temp/token/1"));
|
|
|
+ } catch (Exception e) {}
|
|
|
+ }
|
|
|
|
|
|
redisUtils.set(RedisKey.MP_OF_SHOP_TOKEN_CACHE_KEY, token, RedisUtils.HOUR_ONE_EXPIRE);
|
|
|
}
|
|
|
return token;
|
|
|
}
|
|
|
|
|
|
+ private static String doDecrypt(String text) {
|
|
|
+ CipherUtils cipherUtils = new CipherUtils(CipherAlgorithmEnum.AES_CBC_PKCS5);
|
|
|
+ String key = SECUREAPIPROPERTIESCONFIG.getKey();
|
|
|
+ String iv = SECUREAPIPROPERTIESCONFIG.getIv();
|
|
|
+ return cipherUtils.decrypt(text, key, iv);
|
|
|
+ }
|
|
|
|
|
|
public static void getImg(String relation,String goodsId,String type, String page,HttpServletResponse response){
|
|
|
String mpToken = getMpToken();
|