mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-20 02:55:04 +08:00
update query_token
This commit is contained in:
@@ -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
|
||||||
|
|||||||
@@ -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:密钥错误; 3~99:自定义
|
||||||
|
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)) {
|
||||||
} catch (RuntimeException e) {
|
failReason = 1;
|
||||||
throw new BusinessException("2", "密钥错误");
|
succStat = 1;
|
||||||
}
|
} else {
|
||||||
|
|
||||||
// 生成token
|
// 生成token
|
||||||
String token = JWTUtils.createToken(operatorId, operatorSecret, JWTUtils.ttlMillis);
|
String token = JWTUtils.createToken(operatorId, theirOperatorSecret, JWTUtils.ttlMillis);
|
||||||
|
|
||||||
// 组装返回参数
|
|
||||||
AccessTokenVO vo = new AccessTokenVO();
|
|
||||||
vo.setAccessToken(token);
|
vo.setAccessToken(token);
|
||||||
vo.setOperatorID(operatorId);
|
|
||||||
vo.setTokenAvailableTime((int) (JWTUtils.ttlMillis / 1000));
|
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();
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user