From 6a82341c8a4e30581ef945f63cdd41df0c19ae24 Mon Sep 17 00:00:00 2001 From: Guoqs Date: Wed, 8 May 2024 14:41:26 +0800 Subject: [PATCH] update query_token --- .../lianlian/LianLianController.java | 2 +- .../service/LianLianPlatformServiceImpl.java | 68 +++++++++---------- 2 files changed, 35 insertions(+), 35 deletions(-) diff --git a/jsowell-admin/src/main/java/com/jsowell/web/controller/thirdparty/lianlian/LianLianController.java b/jsowell-admin/src/main/java/com/jsowell/web/controller/thirdparty/lianlian/LianLianController.java index 3de5919b9..b897d7d13 100644 --- a/jsowell-admin/src/main/java/com/jsowell/web/controller/thirdparty/lianlian/LianLianController.java +++ b/jsowell-admin/src/main/java/com/jsowell/web/controller/thirdparty/lianlian/LianLianController.java @@ -356,7 +356,7 @@ public class LianLianController extends BaseController { /** * 请求设备认证 - * + * http://localhost:8080/LianLian/v1/query_equip_auth * @param request * @param dto * @return diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/lianlian/service/LianLianPlatformServiceImpl.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/lianlian/service/LianLianPlatformServiceImpl.java index e5212e9a6..9dfd87f67 100644 --- a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/lianlian/service/LianLianPlatformServiceImpl.java +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/lianlian/service/LianLianPlatformServiceImpl.java @@ -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 queryToken(CommonParamsDTO dto) { - String operatorId = dto.getOperatorID(); + AccessTokenVO vo = new AccessTokenVO(); + // 0:成功;1:失败 + int succStat = 0; + // 0:无;1:无此对接平台;2:密钥错误; 3~99:自定义 + 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 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 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 resultMap = ThirdPartyPlatformUtils.generateResultMap(vo, thirdPartySecretInfoVO); return resultMap; }