diff --git a/jsowell-common/src/main/java/com/jsowell/common/constant/CacheConstants.java b/jsowell-common/src/main/java/com/jsowell/common/constant/CacheConstants.java index e05850ce0..c27012739 100644 --- a/jsowell-common/src/main/java/com/jsowell/common/constant/CacheConstants.java +++ b/jsowell-common/src/main/java/com/jsowell/common/constant/CacheConstants.java @@ -36,6 +36,9 @@ public class CacheConstants { // 缓存时间 30天 public static final int cache_expire_time_30d = cache_expire_time_1d * 30; + // 第三方平台密钥配置 + public static final String THIRD_PARTY_SECRET_INFO = "third_party_secret_info:"; + // 保存order_monitor_data public static final String INSERT_ORDER_MONITOR_DATA = "insert_order_monitor_data:"; diff --git a/jsowell-pile/src/main/java/com/jsowell/thirdparty/mapper/ThirdpartySecretInfoMapper.java b/jsowell-pile/src/main/java/com/jsowell/thirdparty/mapper/ThirdpartySecretInfoMapper.java index c6f62361f..9d03f2f19 100644 --- a/jsowell-pile/src/main/java/com/jsowell/thirdparty/mapper/ThirdpartySecretInfoMapper.java +++ b/jsowell-pile/src/main/java/com/jsowell/thirdparty/mapper/ThirdpartySecretInfoMapper.java @@ -2,6 +2,7 @@ package com.jsowell.thirdparty.mapper; import com.jsowell.pile.vo.ThirdPartySecretInfoVO; import com.jsowell.thirdparty.domain.ThirdpartySecretInfo; +import org.springframework.stereotype.Repository; import java.util.List; @@ -11,6 +12,7 @@ import java.util.List; * @author jsowell * @date 2024-04-18 */ +@Repository public interface ThirdpartySecretInfoMapper { /** * 查询对接三方平台配置 diff --git a/jsowell-pile/src/main/java/com/jsowell/thirdparty/service/impl/ThirdpartySecretInfoServiceImpl.java b/jsowell-pile/src/main/java/com/jsowell/thirdparty/service/impl/ThirdpartySecretInfoServiceImpl.java index d618c3d3a..d30ef3cac 100644 --- a/jsowell-pile/src/main/java/com/jsowell/thirdparty/service/impl/ThirdpartySecretInfoServiceImpl.java +++ b/jsowell-pile/src/main/java/com/jsowell/thirdparty/service/impl/ThirdpartySecretInfoServiceImpl.java @@ -1,5 +1,7 @@ package com.jsowell.thirdparty.service.impl; +import com.jsowell.common.constant.CacheConstants; +import com.jsowell.common.core.redis.RedisCache; import com.jsowell.common.util.DateUtils; import com.jsowell.pile.vo.ThirdPartySecretInfoVO; import com.jsowell.thirdparty.domain.ThirdpartySecretInfo; @@ -9,6 +11,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.List; +import java.util.Objects; /** * 对接三方平台配置Service业务层处理 @@ -21,6 +24,9 @@ public class ThirdpartySecretInfoServiceImpl implements ThirdpartySecretInfoServ @Autowired private ThirdpartySecretInfoMapper thirdpartySecretInfoMapper; + @Autowired + private RedisCache redisCache; + /** * 查询对接三方平台配置 * @@ -96,6 +102,15 @@ public class ThirdpartySecretInfoServiceImpl implements ThirdpartySecretInfoServ */ @Override public ThirdPartySecretInfoVO queryByOperatorId(String theirOperatorId) { - return thirdpartySecretInfoMapper.queryByOperatorId(theirOperatorId); + // 加缓存 + String redisKey = CacheConstants.THIRD_PARTY_SECRET_INFO + theirOperatorId; + ThirdPartySecretInfoVO result = redisCache.getCacheObject(redisKey); + if (Objects.isNull(result)) { + result = thirdpartySecretInfoMapper.queryByOperatorId(theirOperatorId); + if (Objects.nonNull(result)) { + redisCache.setCacheObject(redisKey, result, CacheConstants.cache_expire_time_1h); + } + } + return result; } } diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/util/ThirdPartyPlatformUtils.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/util/ThirdPartyPlatformUtils.java index 3b1c2fa6a..d559a514c 100644 --- a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/util/ThirdPartyPlatformUtils.java +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/util/ThirdPartyPlatformUtils.java @@ -3,6 +3,7 @@ package com.jsowell.thirdparty.platform.util; import com.alibaba.fastjson2.JSON; import com.google.common.collect.Maps; import com.jsowell.pile.domain.ThirdPartyPlatformConfig; +import com.jsowell.pile.vo.ThirdPartySecretInfoVO; import org.springframework.stereotype.Component; import java.util.Map; @@ -12,6 +13,16 @@ import java.util.regex.Pattern; @Component public class ThirdPartyPlatformUtils { + /** + * 生成结果集 + * @param obj 需要返回的数据 + * @param secretInfo 密钥配置信息对象 + * @return 结果集 + */ + public static Map generateResultMap(Object obj, ThirdPartySecretInfoVO secretInfo) { + return generateResultMap(obj, secretInfo.getTheirOperatorSecret(), secretInfo.getTheirDataSecretIv(), secretInfo.getTheirSigSecret()); + } + /** * 生成结果集 * @param obj 需要返回的数据 diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/zhongdianlian/service/ZhongDianLianPlatformServiceImpl.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/zhongdianlian/service/ZhongDianLianPlatformServiceImpl.java index 025b0ba09..619d97275 100644 --- a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/zhongdianlian/service/ZhongDianLianPlatformServiceImpl.java +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/zhongdianlian/service/ZhongDianLianPlatformServiceImpl.java @@ -3,13 +3,14 @@ package com.jsowell.thirdparty.platform.zhongdianlian.service; import com.alibaba.fastjson2.JSON; import com.jsowell.common.util.JWTUtils; import com.jsowell.common.util.StringUtils; -import com.jsowell.pile.domain.ThirdPartyPlatformConfig; import com.jsowell.pile.service.ThirdPartyPlatformConfigService; import com.jsowell.pile.thirdparty.CommonParamsDTO; +import com.jsowell.pile.vo.ThirdPartySecretInfoVO; import com.jsowell.thirdparty.lianlian.vo.AccessTokenVO; import com.jsowell.thirdparty.platform.ThirdPartyPlatformService; import com.jsowell.thirdparty.platform.util.Cryptos; import com.jsowell.thirdparty.platform.util.ThirdPartyPlatformUtils; +import com.jsowell.thirdparty.service.ThirdpartySecretInfoService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -21,6 +22,9 @@ public class ZhongDianLianPlatformServiceImpl implements ThirdPartyPlatformServi @Autowired private ThirdPartyPlatformConfigService thirdPartyPlatformConfigService; + @Autowired + private ThirdpartySecretInfoService thirdpartySecretInfoService; + /** * query_token 获取token,提供给第三方平台使用 * @@ -37,14 +41,15 @@ public class ZhongDianLianPlatformServiceImpl implements ThirdPartyPlatformServi String operatorId = StringUtils.isNotBlank(dto.getOperatorID()) ? dto.getOperatorID() : dto.getPlatformID(); // 通过operatorId 查出 operatorSecret - ThirdPartyPlatformConfig platformConfig = thirdPartyPlatformConfigService.getInfoByOperatorId(operatorId); - if (platformConfig == null) { + // ThirdPartyPlatformConfig platformConfig = thirdPartyPlatformConfigService.getInfoByOperatorId(operatorId); + ThirdPartySecretInfoVO thirdPartySecretInfoVO = thirdpartySecretInfoService.queryByOperatorId(operatorId); + if (thirdPartySecretInfoVO == null) { failReason = 1; succStat = 1; } else { - String operatorSecret = platformConfig.getOperatorSecret(); - String dataSecret = platformConfig.getDataSecret(); - String dataSecretIv = platformConfig.getDataSecretIv(); + String theirOperatorSecret = thirdPartySecretInfoVO.getTheirOperatorSecret(); + String dataSecret = thirdPartySecretInfoVO.getOurDataSecret(); + String dataSecretIv = thirdPartySecretInfoVO.getOurDataSecretIv(); // 解密data 获取参数中的OperatorSecret String decrypt = Cryptos.decrypt(dto.getData(), dataSecret, dataSecretIv); String inputOperatorSecret = null; @@ -52,12 +57,12 @@ public class ZhongDianLianPlatformServiceImpl implements ThirdPartyPlatformServi inputOperatorSecret = JSON.parseObject(decrypt).getString("PlatformSecret"); } // 对比密钥 - if (!StringUtils.equals(operatorSecret, inputOperatorSecret)) { + if (!StringUtils.equals(theirOperatorSecret, inputOperatorSecret)) { failReason = 1; succStat = 1; } else { // 生成token - String token = JWTUtils.createToken(operatorId, operatorSecret, JWTUtils.ttlMillis); + String token = JWTUtils.createToken(operatorId, theirOperatorSecret, JWTUtils.ttlMillis); vo.setAccessToken(token); vo.setTokenAvailableTime((int) (JWTUtils.ttlMillis / 1000)); } @@ -67,7 +72,7 @@ public class ZhongDianLianPlatformServiceImpl implements ThirdPartyPlatformServi vo.setFailReason(failReason); vo.setSuccStat(succStat); - Map resultMap = ThirdPartyPlatformUtils.generateResultMap(vo, platformConfig); + Map resultMap = ThirdPartyPlatformUtils.generateResultMap(vo, thirdPartySecretInfoVO); return resultMap; } }