update query_token

This commit is contained in:
2024-05-08 14:41:26 +08:00
parent dd9badce30
commit 6a82341c8a
2 changed files with 35 additions and 35 deletions

View File

@@ -356,7 +356,7 @@ public class LianLianController extends BaseController {
/** /**
* 请求设备认证 * 请求设备认证
* * http://localhost:8080/LianLian/v1/query_equip_auth
* @param request * @param request
* @param dto * @param dto
* @return * @return

View File

@@ -44,6 +44,7 @@ import com.jsowell.thirdparty.platform.common.OrderInfo;
import com.jsowell.thirdparty.platform.common.StationInfo; import com.jsowell.thirdparty.platform.common.StationInfo;
import com.jsowell.thirdparty.platform.factory.ThirdPartyPlatformFactory; import com.jsowell.thirdparty.platform.factory.ThirdPartyPlatformFactory;
import com.jsowell.thirdparty.platform.util.*; import com.jsowell.thirdparty.platform.util.*;
import com.jsowell.thirdparty.service.ThirdpartySecretInfoService;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@@ -86,6 +87,9 @@ public class LianLianPlatformServiceImpl implements ThirdPartyPlatformService {
@Resource @Resource
private ThirdPartyStationRelationService thirdPartyStationRelationService; private ThirdPartyStationRelationService thirdPartyStationRelationService;
@Autowired
private ThirdpartySecretInfoService thirdpartySecretInfoService;
@Override @Override
public void afterPropertiesSet() throws Exception { public void afterPropertiesSet() throws Exception {
ThirdPartyPlatformFactory.register(thirdPlatformType, this); ThirdPartyPlatformFactory.register(thirdPlatformType, this);
@@ -120,50 +124,46 @@ public class LianLianPlatformServiceImpl implements ThirdPartyPlatformService {
@Override @Override
public Map<String, String> queryToken(CommonParamsDTO dto) { public Map<String, String> queryToken(CommonParamsDTO dto) {
String operatorId = dto.getOperatorID(); AccessTokenVO vo = new AccessTokenVO();
// 0:成功1:失败
int succStat = 0;
// 0:无1:无此对接平台2:密钥错误; 399:自定义
int failReason = 0;
String operatorId = StringUtils.isNotBlank(dto.getOperatorID()) ? dto.getOperatorID() : dto.getPlatformID();
// 通过operatorId 查出 operatorSecret // 通过operatorId 查出 operatorSecret
ThirdPartyPlatformConfig platformConfig = thirdPartyPlatformConfigService.getInfoByOperatorId(operatorId); ThirdPartySecretInfoVO thirdPartySecretInfoVO = thirdpartySecretInfoService.queryByOperatorId(operatorId);
if (platformConfig == null) { if (thirdPartySecretInfoVO == null) {
throw new BusinessException("1", "无此对接平台"); failReason = 1;
} succStat = 1;
} else {
String operatorSecret = platformConfig.getOperatorSecret(); String theirOperatorSecret = thirdPartySecretInfoVO.getTheirOperatorSecret();
String dataSecret = platformConfig.getDataSecret(); String dataSecret = thirdPartySecretInfoVO.getOurDataSecret();
String dataSecretIv = platformConfig.getDataSecretIv(); String dataSecretIv = thirdPartySecretInfoVO.getOurDataSecretIv();
String signSecret = platformConfig.getSignSecret(); // 解密data 获取参数中的OperatorSecret
// 解密data 获取参数中的OperatorSecret
try {
String decrypt = Cryptos.decrypt(dto.getData(), dataSecret, dataSecretIv); String decrypt = Cryptos.decrypt(dto.getData(), dataSecret, dataSecretIv);
String inputOperatorSecret = null; String inputOperatorSecret = null;
if (StringUtils.isNotBlank(decrypt)) { if (StringUtils.isNotBlank(decrypt)) {
inputOperatorSecret = JSON.parseObject(decrypt).getString("OperatorSecret"); inputOperatorSecret = JSON.parseObject(decrypt).getString("OperatorSecret");
} }
if (!StringUtils.equals(operatorSecret, inputOperatorSecret)) { // 对比密钥
throw new RuntimeException("密钥不一致"); List<String> operatorSecretList = Lists.newArrayList(theirOperatorSecret, thirdPartySecretInfoVO.getOurOperatorSecret());
if (!operatorSecretList.contains(inputOperatorSecret)) {
failReason = 1;
succStat = 1;
} else {
// 生成token
String token = JWTUtils.createToken(operatorId, theirOperatorSecret, JWTUtils.ttlMillis);
vo.setAccessToken(token);
vo.setTokenAvailableTime((int) (JWTUtils.ttlMillis / 1000));
} }
} catch (RuntimeException e) {
throw new BusinessException("2", "密钥错误");
} }
// 生成token
String token = JWTUtils.createToken(operatorId, operatorSecret, JWTUtils.ttlMillis);
// 组装返回参数 // 组装返回参数
AccessTokenVO vo = new AccessTokenVO(); vo.setPlatformId(operatorId);
vo.setAccessToken(token); vo.setFailReason(failReason);
vo.setOperatorID(operatorId); vo.setSuccStat(succStat);
vo.setTokenAvailableTime((int) (JWTUtils.ttlMillis / 1000));
vo.setFailReason(0);
vo.setSuccStat(0);
Map<String, String> resultMap = Maps.newLinkedHashMap(); Map<String, String> resultMap = ThirdPartyPlatformUtils.generateResultMap(vo, thirdPartySecretInfoVO);
// 加密数据
String encryptData = Cryptos.aesEncrypt(JSON.toJSONString(vo), dataSecret, dataSecretIv);
resultMap.put("Data", encryptData);
// 生成sig
String resultSign = GBSignUtils.sign(resultMap, signSecret);
resultMap.put("Sig", resultSign);
return resultMap; return resultMap;
} }