mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-20 19:15:35 +08:00
深圳平台新增 查询令牌、推送站点信息接口
This commit is contained in:
@@ -196,6 +196,11 @@ public class CommonService {
|
||||
insertInfo2DataBase(dto);
|
||||
result = dto.getThirdPartyType() + ":" + "OK";
|
||||
}
|
||||
if (StringUtils.equals(ThirdPlatformTypeEnum.DIAN_XING_PLATFORM.getTypeCode(), dto.getThirdPartyType())) {
|
||||
// 宁波点行平台
|
||||
insertInfo2DataBase(dto);
|
||||
result = ThirdPlatformTypeEnum.DIAN_XING_PLATFORM.getTypeLabel() + ":" + "OK";
|
||||
}
|
||||
finalResult.append(result).append("\n");
|
||||
}
|
||||
return finalResult.toString();
|
||||
|
||||
@@ -354,4 +354,10 @@ public class StationInfo {
|
||||
@JSONField(name = "ParkingLockFlag")
|
||||
private Integer parkingLockFlag;
|
||||
|
||||
/**
|
||||
* 站点联系电话
|
||||
*/
|
||||
@JSONField(name = "StationTel")
|
||||
private String stationTel;
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,197 @@
|
||||
package com.jsowell.thirdparty.platform.service.impl;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.jsowell.common.constant.Constants;
|
||||
import com.jsowell.common.enums.thirdparty.BusinessInformationExchangeEnum;
|
||||
import com.jsowell.common.enums.thirdparty.ThirdPlatformTypeEnum;
|
||||
import com.jsowell.common.enums.ykc.ReturnCodeEnum;
|
||||
import com.jsowell.common.exception.BusinessException;
|
||||
import com.jsowell.common.util.JWTUtils;
|
||||
import com.jsowell.common.util.StringUtils;
|
||||
import com.jsowell.pile.domain.ThirdPartyPlatformConfig;
|
||||
import com.jsowell.pile.service.PileBasicInfoService;
|
||||
import com.jsowell.pile.service.PileStationInfoService;
|
||||
import com.jsowell.pile.thirdparty.CommonParamsDTO;
|
||||
import com.jsowell.pile.thirdparty.EquipmentInfo;
|
||||
import com.jsowell.pile.vo.ThirdPartySecretInfoVO;
|
||||
import com.jsowell.pile.vo.web.PileStationVO;
|
||||
import com.jsowell.thirdparty.lianlian.vo.AccessTokenVO;
|
||||
import com.jsowell.thirdparty.platform.common.StationInfo;
|
||||
import com.jsowell.thirdparty.platform.factory.ThirdPartyPlatformFactory;
|
||||
import com.jsowell.thirdparty.platform.service.ThirdPartyPlatformService;
|
||||
import com.jsowell.thirdparty.platform.util.Cryptos;
|
||||
import com.jsowell.thirdparty.platform.util.Encodes;
|
||||
import com.jsowell.thirdparty.platform.util.GBSignUtils;
|
||||
import com.jsowell.thirdparty.platform.util.HttpRequestUtil;
|
||||
import com.jsowell.thirdparty.service.ThirdpartySecretInfoService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 深圳平台 Service
|
||||
*
|
||||
* @author Lemon
|
||||
* @Date 2024/5/14 9:51:12
|
||||
*/
|
||||
@Service
|
||||
public class ShenZhenPlatformServiceImpl implements ThirdPartyPlatformService {
|
||||
|
||||
@Autowired
|
||||
private PileStationInfoService pileStationInfoService;
|
||||
|
||||
@Autowired
|
||||
private ThirdpartySecretInfoService thirdpartySecretInfoService;
|
||||
|
||||
@Autowired
|
||||
private PileBasicInfoService pileBasicInfoService;
|
||||
|
||||
Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
// 平台类型
|
||||
private final String thirdPlatformType = ThirdPlatformTypeEnum.SHEN_ZHEN_PLATFORM.getTypeCode();
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
ThirdPartyPlatformFactory.register(thirdPlatformType, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* 充电站信息变化推送 notification_stationInfo
|
||||
* @param stationId 充电站id
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String notificationStationInfo(String stationId) {
|
||||
// 根据站点id查询站点资料
|
||||
PileStationVO stationVO = pileStationInfoService.getStationInfo(stationId);
|
||||
if (stationVO == null) {
|
||||
throw new BusinessException(ReturnCodeEnum.CODE_SELECT_INFO_IS_NULL);
|
||||
}
|
||||
|
||||
StationInfo stationInfo = StationInfo.builder()
|
||||
.stationID(stationVO.getId())
|
||||
.operatorID(Constants.OPERATORID_JIANG_SU)
|
||||
// .equipmentOwnerID()
|
||||
.stationName(stationVO.getStationName())
|
||||
.countryCode(stationVO.getCountryCode())
|
||||
.areaCode(stationVO.getAreaCode())
|
||||
.address(stationVO.getAddress())
|
||||
.stationType(Integer.parseInt(stationVO.getStationType()))
|
||||
.stationStatus(stationVO.getStationStatus())
|
||||
.parkNums(0) // 默认 0:未知
|
||||
.stationLng(new BigDecimal(stationVO.getStationLng()))
|
||||
.stationLat(new BigDecimal(stationVO.getStationLat()))
|
||||
.construction(Integer.parseInt(stationVO.getConstruction()))
|
||||
|
||||
.build();
|
||||
String stationTel = stationVO.getStationTel();
|
||||
if (StringUtils.isNotBlank(stationTel)) {
|
||||
stationInfo.setStationTel(stationTel);
|
||||
stationInfo.setServiceTel(stationTel);
|
||||
}
|
||||
if (StringUtils.isNotBlank(stationVO.getPictures())) {
|
||||
stationInfo.setPictures(Lists.newArrayList(stationVO.getPictures().split(",")));
|
||||
}
|
||||
// 设备信息列表
|
||||
List<EquipmentInfo> pileList = pileBasicInfoService.getPileListForLianLian(stationId);
|
||||
stationInfo.setEquipmentInfos(pileList);
|
||||
|
||||
// 获取配置密钥信息
|
||||
ThirdPartySecretInfoVO shenZhenSecretInfo = getShenZhenSecretInfo();
|
||||
|
||||
String operatorId = shenZhenSecretInfo.getTheirOperatorId();
|
||||
String operatorSecret = shenZhenSecretInfo.getTheirOperatorSecret();
|
||||
String signSecret = shenZhenSecretInfo.getTheirSigSecret();
|
||||
String dataSecret = shenZhenSecretInfo.getTheirDataSecret();
|
||||
String dataSecretIv = shenZhenSecretInfo.getTheirDataSecretIv();
|
||||
String urlAddress = shenZhenSecretInfo.getTheirUrlPrefix();
|
||||
String url = urlAddress + BusinessInformationExchangeEnum.NOTIFICATION_STATION_INFO.getValue();
|
||||
// 发送请求
|
||||
String jsonString = JSONObject.toJSONString(stationInfo);
|
||||
// 获取令牌
|
||||
String token = getToken(urlAddress, operatorId, operatorSecret, dataSecretIv, signSecret, dataSecret);
|
||||
String result = HttpRequestUtil.sendPost(token, jsonString, url, dataSecret, dataSecretIv, operatorId, signSecret);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 请求令牌 query_token
|
||||
* @param dto
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Map<String, String> queryToken(CommonParamsDTO dto) {
|
||||
String operatorId = dto.getOperatorID();
|
||||
// 通过operatorId 查出 相关配置信息
|
||||
ThirdPartySecretInfoVO secretInfoVO = getShenZhenSecretInfo();
|
||||
if (secretInfoVO == null) {
|
||||
throw new BusinessException("1", "无此对接平台");
|
||||
}
|
||||
|
||||
String operatorSecret = secretInfoVO.getOurOperatorSecret();
|
||||
String dataSecret = secretInfoVO.getOurDataSecret();
|
||||
String dataSecretIv = secretInfoVO.getOurDataSecretIv();
|
||||
String signSecret = secretInfoVO.getOurSigSecret();
|
||||
|
||||
// 解密data 获取参数中的OperatorSecret
|
||||
try {
|
||||
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("密钥不一致");
|
||||
}
|
||||
} 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);
|
||||
|
||||
Map<String, String> resultMap = Maps.newLinkedHashMap();
|
||||
// 加密数据
|
||||
byte[] encryptText = Cryptos.aesEncrypt(JSON.toJSONString(vo).getBytes(),
|
||||
dataSecret.getBytes(), dataSecretIv.getBytes());
|
||||
String encryptData = Encodes.encodeBase64(encryptText); // data
|
||||
resultMap.put("Ret", "0");
|
||||
resultMap.put("Msg", "请求令牌成功!");
|
||||
resultMap.put("Data", encryptData);
|
||||
// 生成sig
|
||||
String resultSign = GBSignUtils.sign(resultMap, signSecret);
|
||||
resultMap.put("Sig", resultSign);
|
||||
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取深圳平台相关密钥信息
|
||||
* @return
|
||||
*/
|
||||
private ThirdPartySecretInfoVO getShenZhenSecretInfo() {
|
||||
ThirdPartySecretInfoVO thirdPartySecretInfoVO = thirdpartySecretInfoService.queryByThirdPlatformType(ThirdPlatformTypeEnum.SHEN_ZHEN_PLATFORM.getTypeCode());
|
||||
if (thirdPartySecretInfoVO == null) {
|
||||
throw new BusinessException(ReturnCodeEnum.CODE_SELECT_INFO_IS_NULL);
|
||||
}
|
||||
return thirdPartySecretInfoVO;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user