mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-05-06 19:10:20 +08:00
update 对接内蒙古平台
This commit is contained in:
@@ -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:";
|
||||
|
||||
|
||||
@@ -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 {
|
||||
/**
|
||||
* 查询对接三方平台配置
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<String, String> generateResultMap(Object obj, ThirdPartySecretInfoVO secretInfo) {
|
||||
return generateResultMap(obj, secretInfo.getTheirOperatorSecret(), secretInfo.getTheirDataSecretIv(), secretInfo.getTheirSigSecret());
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成结果集
|
||||
* @param obj 需要返回的数据
|
||||
|
||||
@@ -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<String, String> resultMap = ThirdPartyPlatformUtils.generateResultMap(vo, platformConfig);
|
||||
Map<String, String> resultMap = ThirdPartyPlatformUtils.generateResultMap(vo, thirdPartySecretInfoVO);
|
||||
return resultMap;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user