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 dto
* @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.factory.ThirdPartyPlatformFactory;
import com.jsowell.thirdparty.platform.util.*;
import com.jsowell.thirdparty.service.ThirdpartySecretInfoService;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -86,6 +87,9 @@ public class LianLianPlatformServiceImpl implements ThirdPartyPlatformService {
@Resource
private ThirdPartyStationRelationService thirdPartyStationRelationService;
@Autowired
private ThirdpartySecretInfoService thirdpartySecretInfoService;
@Override
public void afterPropertiesSet() throws Exception {
ThirdPartyPlatformFactory.register(thirdPlatformType, this);
@@ -120,50 +124,46 @@ public class LianLianPlatformServiceImpl implements ThirdPartyPlatformService {
@Override
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
ThirdPartyPlatformConfig platformConfig = thirdPartyPlatformConfigService.getInfoByOperatorId(operatorId);
if (platformConfig == null) {
throw new BusinessException("1", "无此对接平台");
}
String operatorSecret = platformConfig.getOperatorSecret();
String dataSecret = platformConfig.getDataSecret();
String dataSecretIv = platformConfig.getDataSecretIv();
String signSecret = platformConfig.getSignSecret();
// 解密data 获取参数中的OperatorSecret
try {
ThirdPartySecretInfoVO thirdPartySecretInfoVO = thirdpartySecretInfoService.queryByOperatorId(operatorId);
if (thirdPartySecretInfoVO == null) {
failReason = 1;
succStat = 1;
} else {
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;
if (StringUtils.isNotBlank(decrypt)) {
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.setAccessToken(token);
vo.setOperatorID(operatorId);
vo.setTokenAvailableTime((int) (JWTUtils.ttlMillis / 1000));
vo.setFailReason(0);
vo.setSuccStat(0);
vo.setPlatformId(operatorId);
vo.setFailReason(failReason);
vo.setSuccStat(succStat);
Map<String, String> resultMap = Maps.newLinkedHashMap();
// 加密数据
String encryptData = Cryptos.aesEncrypt(JSON.toJSONString(vo), dataSecret, dataSecretIv);
resultMap.put("Data", encryptData);
// 生成sig
String resultSign = GBSignUtils.sign(resultMap, signSecret);
resultMap.put("Sig", resultSign);
Map<String, String> resultMap = ThirdPartyPlatformUtils.generateResultMap(vo, thirdPartySecretInfoVO);
return resultMap;
}