update 第三方平台相关方法

This commit is contained in:
Lemon
2025-02-25 14:49:04 +08:00
parent 382622e187
commit ee0414e2b0
26 changed files with 1381 additions and 1687 deletions

View File

@@ -30,13 +30,13 @@ public interface HuaWeiService {
* @param dto
* @return
*/
Map<String, String> generateToken(CommonParamsDTO dto) throws UnsupportedEncodingException;
// Map<String, String> generateToken(CommonParamsDTO dto) throws UnsupportedEncodingException;
/**
* 校验签名
* @param dto
*/
Map<String, String> checkoutSign(CommonParamsDTO dto);
// Map<String, String> checkoutSign(CommonParamsDTO dto);
/**
* 查询站点信息

View File

@@ -17,7 +17,9 @@ import com.jsowell.common.enums.thirdparty.huawei.StartFailedReasonEnum;
import com.jsowell.common.enums.thirdparty.huawei.StopFailedReasonEnum;
import com.jsowell.common.enums.ykc.OrderStatusEnum;
import com.jsowell.common.enums.ykc.PileConnectorDataBaseStatusEnum;
import com.jsowell.common.enums.ykc.ReturnCodeEnum;
import com.jsowell.common.enums.ykc.StartModeEnum;
import com.jsowell.common.exception.BusinessException;
import com.jsowell.common.util.DateUtils;
import com.jsowell.common.util.StringUtils;
import com.jsowell.common.util.Threads;
@@ -33,6 +35,7 @@ import com.jsowell.pile.service.*;
import com.jsowell.pile.service.programlogic.AbstractProgramLogic;
import com.jsowell.pile.service.programlogic.ProgramLogicFactory;
import com.jsowell.pile.thirdparty.CommonParamsDTO;
import com.jsowell.pile.vo.ThirdPartySecretInfoVO;
import com.jsowell.pile.vo.huawei.QueryChargeStatusVO;
import com.jsowell.pile.vo.huawei.QueryEquipAuthVO;
import com.jsowell.pile.vo.huawei.QueryStartChargeVO;
@@ -44,6 +47,8 @@ import com.jsowell.thirdparty.lianlian.service.LianLianService;
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.ThirdPartyPlatformUtils;
import com.jsowell.thirdparty.service.ThirdpartySecretInfoService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
@@ -85,10 +90,7 @@ public class HuaweiServiceV2 {
private PileBasicInfoService pileBasicInfoService;
@Autowired
private ThirdPartySettingInfoService thirdPartySettingInfoService;
@Autowired
private ThirdPartyPlatformConfigService thirdPartyPlatformConfigService;
private ThirdpartySecretInfoService thirdpartySecretInfoService;
@Autowired
private PileBillingTemplateService pileBillingTemplateService;
@@ -123,13 +125,13 @@ public class HuaweiServiceV2 {
// 通过华为的type查询出密钥配置
ThirdPartySettingInfo info = new ThirdPartySettingInfo();
info.setType(ThirdPlatformTypeEnum.HUA_WEI.getTypeCode());
ThirdPartySettingInfo settingInfo = thirdPartySettingInfoService.selectSettingInfo(info);
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getHuaWeiPlatformSecretInfo();
String operatorSecret = settingInfo.getOperatorSecret();
String dataSecret = settingInfo.getDataSecret();
String dataSecretIv = settingInfo.getDataSecretIv();
String signSecret = settingInfo.getSignSecret();
String urlAddress = settingInfo.getUrlAddress();
String operatorSecret = thirdPartySecretInfoVO.getTheirOperatorSecret();
String dataSecret = thirdPartySecretInfoVO.getTheirDataSecret();
String dataSecretIv = thirdPartySecretInfoVO.getTheirDataSecretIv();
String signSecret = thirdPartySecretInfoVO.getTheirSigSecret();
String urlAddress = thirdPartySecretInfoVO.getTheirUrlPrefix();
String requestUrl = urlAddress + "query_token";
@@ -177,13 +179,13 @@ public class HuaweiServiceV2 {
return token;
}
public Map<String, String> generateToken(CommonParamsDTO dto) throws UnsupportedEncodingException {
return lianLianService.generateToken(dto);
}
// public Map<String, String> generateToken(CommonParamsDTO dto) throws UnsupportedEncodingException {
// return lianLianService.generateToken(dto);
// }
public Map<String, String> checkoutSign(CommonParamsDTO dto) {
return lianLianService.checkoutSign(dto);
}
// public Map<String, String> checkoutSign(CommonParamsDTO dto) {
// return lianLianService.checkoutSign(dto);
// }
/**
* 平台充电设备编码同步
@@ -292,10 +294,10 @@ public class HuaweiServiceV2 {
if (status != 0) {
setPileAlive(pileSn);
}
ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(connectorStatusInfo.getOperatorId());
if (configInfo == null) {
return null;
}
// ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(connectorStatusInfo.getOperatorId());
// if (configInfo == null) {
// return null;
// }
// 将枪口状态改为对应的状态
pileConnectorInfoService.updateConnectorStatus(pileConnectorCode, String.valueOf(status));
// 构造返回参数
@@ -352,10 +354,11 @@ public class HuaweiServiceV2 {
String pileConnectorCode = dto.getConnectorID();
String equipBizSeq = dto.getEquipBizSeq();
// 根据枪口号查询计费模板,并返回信息
ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorId());
if (configInfo == null) {
return null;
}
// ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorId());
// if (configInfo == null) {
// return null;
// }
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getHuaWeiPlatformSecretInfo();
// 截取桩号
// String pileSn = StringUtils.substring(pileConnectorCode, 0, 14);
String pileSn = YKCUtils.getPileSn(pileConnectorCode);
@@ -387,17 +390,8 @@ public class HuaweiServiceV2 {
resultJson.put("FailReason", 0);
}
// 加密
Map<String, String> resultMap = Maps.newLinkedHashMap();
// 加密数据
byte[] encryptText = Cryptos.aesEncrypt(resultJson.toJSONString().getBytes(),
configInfo.getDataSecret().getBytes(), configInfo.getDataSecretIv().getBytes());
String encryptData = Encodes.encodeBase64(encryptText);
resultMap.put("Data", encryptData);
// 生成sig
String resultSign = GBSignUtils.sign(resultMap, configInfo.getSignSecret());
resultMap.put("Sig", resultSign);
Map<String, String> resultMap = ThirdPartyPlatformUtils.generateResultMapV2(resultJson, thirdPartySecretInfoVO.getOurDataSecret(),
thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret());
return resultMap;
}
@@ -882,10 +876,8 @@ public class HuaweiServiceV2 {
* @throws Exception
*/
public Map<String, String> vinStartCharge(VinStartChargeDTO dto) throws Exception {
ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorId());
if (configInfo == null) {
return null;
}
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getHuaWeiPlatformSecretInfo();
int succStat = Constants.one; // 操作结果
int failReason = Constants.one; // 失败原因
JSONObject jsonObject = new JSONObject();
@@ -1018,18 +1010,6 @@ public class HuaweiServiceV2 {
}
/**
* 获取华为配置信息
* @return
*/
private ThirdPartySettingInfo getHuaWeiSettingInfo() {
// 通过华为的type查询出密钥配置
ThirdPartySettingInfo info = new ThirdPartySettingInfo();
info.setType(ThirdPlatformTypeEnum.HUA_WEI.getTypeCode());
ThirdPartySettingInfo settingInfo = thirdPartySettingInfoService.selectSettingInfo(info);
return settingInfo;
}
/**
* 向华为发送请求
* @param jsonString 封装好的json请求参数
@@ -1039,27 +1019,25 @@ public class HuaweiServiceV2 {
*/
private String sendMsg2HuaWei(String jsonString, String token, String requestName) {
log.info("向华为发送请求 jsonString:{}, token:{}, requestName:{}", jsonString, token, requestName);
ThirdPartySettingInfo settingInfo = getHuaWeiSettingInfo();
if (settingInfo == null) {
return null;
}
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getHuaWeiPlatformSecretInfo();
//加密
byte[] encryptText = Cryptos.aesEncrypt(jsonString.getBytes(),
settingInfo.getDataSecret().getBytes(), settingInfo.getDataSecretIv().getBytes());
thirdPartySecretInfoVO.getTheirDataSecret().getBytes(), thirdPartySecretInfoVO.getTheirDataSecretIv().getBytes());
String encryptData = Encodes.encodeBase64(encryptText);
Map<String, String> params = Maps.newLinkedHashMap();
params.put("OperatorID", settingInfo.getOperatorId());
params.put("OperatorID", thirdPartySecretInfoVO.getTheirOperatorId());
params.put("Data", encryptData);
params.put("TimeStamp", DateUtils.parseDateToStr(DateUtils.YYYYMMDDHHMMSS, new Date()));
params.put("Seq", "001");
String sign = GBSignUtils.sign(params, settingInfo.getSignSecret());
String sign = GBSignUtils.sign(params, thirdPartySecretInfoVO.getTheirSigSecret());
params.put("Sig", sign);
String postData = JSON.toJSONString(params);
// 请求url
String requestUrl = settingInfo.getUrlAddress() + requestName;
String requestUrl = thirdPartySecretInfoVO.getTheirUrlPrefix() + requestName;
String hutoolRequest = HttpRequest.post(requestUrl)
.header("Authorization", "Bearer " + token)
.body(postData).execute().body();
@@ -1080,7 +1058,7 @@ public class HuaweiServiceV2 {
String rData = (String) map.get("Data");
// 解密
byte[] plainText = Cryptos.aesDecrypt(Encodes.decodeBase64(rData),
settingInfo.getDataSecret().getBytes(), settingInfo.getDataSecretIv().getBytes());
thirdPartySecretInfoVO.getTheirDataSecret().getBytes(), thirdPartySecretInfoVO.getTheirDataSecretIv().getBytes());
String plainData = new String(plainText, StandardCharsets.UTF_8);
return plainData;
}
@@ -1093,19 +1071,17 @@ public class HuaweiServiceV2 {
private Map<String, String> getResultMap(JSONObject jsonObject) {
log.info("加密华为数据 jsonObject:{}", jsonObject.toJSONString());
String operatorId = ThirdPartyOperatorIdEnum.HUA_WEI.getOperatorId();
ThirdPartyPlatformConfig platformConfig = thirdPartyPlatformConfigService.getInfoByOperatorId(operatorId);
if (platformConfig == null) {
return null;
}
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getHuaWeiPlatformSecretInfo();
Map<String, String> resultMap = Maps.newLinkedHashMap();
// 加密数据
byte[] encryptText = Cryptos.aesEncrypt(jsonObject.toJSONString().getBytes(),
platformConfig.getDataSecret().getBytes(), platformConfig.getDataSecretIv().getBytes());
thirdPartySecretInfoVO.getOurDataSecret().getBytes(), thirdPartySecretInfoVO.getOurDataSecretIv().getBytes());
String encryptData = Encodes.encodeBase64(encryptText);
resultMap.put("Data", encryptData);
// 生成sig
String resultSign = GBSignUtils.sign(resultMap, platformConfig.getSignSecret());
String resultSign = GBSignUtils.sign(resultMap, thirdPartySecretInfoVO.getOurSigSecret());
resultMap.put("Sig", resultSign);
return resultMap;
@@ -1212,5 +1188,20 @@ public class HuaweiServiceV2 {
return connectorInfoList;
}
/**
* 获取华为平台配置密钥信息
*
* @return
*/
private ThirdPartySecretInfoVO getHuaWeiPlatformSecretInfo() {
// 通过第三方平台类型查询相关配置信息
ThirdPartySecretInfoVO thirdPartySecretInfoVO = thirdpartySecretInfoService.queryByThirdPlatformType(ThirdPlatformTypeEnum.HUA_WEI.getTypeCode());
if (thirdPartySecretInfoVO == null) {
throw new BusinessException(ReturnCodeEnum.CODE_SELECT_INFO_IS_NULL);
}
thirdPartySecretInfoVO.setOurOperatorId(Constants.OPERATORID_JIANG_SU);
return thirdPartySecretInfoVO;
}
}

View File

@@ -4,6 +4,7 @@ import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.google.common.collect.Maps;
import com.jsowell.common.constant.Constants;
import com.jsowell.common.enums.thirdparty.ThirdPlatformTypeEnum;
import com.jsowell.common.enums.ykc.ReturnCodeEnum;
import com.jsowell.common.enums.ykc.StartModeEnum;
import com.jsowell.common.exception.BusinessException;
@@ -18,14 +19,13 @@ import com.jsowell.pile.dto.huawei.ReceiveDeliverDTO;
import com.jsowell.pile.dto.huawei.VinStartChargeDTO;
import com.jsowell.pile.service.*;
import com.jsowell.pile.thirdparty.CommonParamsDTO;
import com.jsowell.pile.vo.ThirdPartySecretInfoVO;
import com.jsowell.pile.vo.base.ThirdPartyStationRelationVO;
import com.jsowell.pile.vo.uniapp.customer.BillingPriceVO;
import com.jsowell.pile.vo.web.PileStationVO;
import com.jsowell.thirdparty.huawei.HuaWeiService;
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.platform.util.*;
import com.jsowell.thirdparty.service.ThirdpartySecretInfoService;
import com.jsowell.thirdparty.zhongdianlian.dto.ZDLGetTokenDTO;
import com.jsowell.thirdparty.zhongdianlian.service.ZDLService;
import lombok.extern.slf4j.Slf4j;
@@ -72,10 +72,7 @@ public class HuaWeiServiceImpl implements HuaWeiService {
private ThirdPartyStationRelationService thirdPartyStationRelationService;
@Autowired
private ThirdPartySettingInfoService thirdPartySettingInfoService;
@Autowired
private PileMerchantInfoService pileMerchantInfoService;
private ThirdpartySecretInfoService thirdpartySecretInfoService;
@Autowired
private MemberPlateNumberRelationService memberPlateNumberRelationService;
@@ -104,19 +101,19 @@ public class HuaWeiServiceImpl implements HuaWeiService {
* @param dto
* @return
*/
@Override
public Map<String, String> generateToken(CommonParamsDTO dto) throws UnsupportedEncodingException {
return zdlService.generateToken(dto);
}
// @Override
// public Map<String, String> generateToken(CommonParamsDTO dto) throws UnsupportedEncodingException {
// return zdlService.generateToken(dto);
// }
/**
* 校验签名
* @param dto
*/
@Override
public Map<String, String> checkoutSign(CommonParamsDTO dto) {
return zdlService.checkoutSign(dto);
}
// @Override
// public Map<String, String> checkoutSign(CommonParamsDTO dto) {
// return zdlService.checkoutSign(dto);
// }
/**
* 查询站点信息
@@ -273,10 +270,7 @@ public class HuaWeiServiceImpl implements HuaWeiService {
String pileConnectorCode = dto.getConnectorID();
String equipBizSeq = dto.getEquipBizSeq();
// 根据枪口号查询计费模板,并返回信息
ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorId());
if (configInfo == null) {
return null;
}
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getHuaWeiPlatformSecretInfo();
// 截取桩号
// String pileSn = StringUtils.substring(pileConnectorCode, 0, 14);
String pileSn = YKCUtils.getPileSn(pileConnectorCode);
@@ -308,17 +302,8 @@ public class HuaWeiServiceImpl implements HuaWeiService {
resultJson.put("FailReason", 0);
}
// 加密
Map<String, String> resultMap = Maps.newLinkedHashMap();
// 加密数据
byte[] encryptText = Cryptos.aesEncrypt(resultJson.toJSONString().getBytes(),
configInfo.getDataSecret().getBytes(), configInfo.getDataSecretIv().getBytes());
String encryptData = Encodes.encodeBase64(encryptText);
resultMap.put("Data", encryptData);
// 生成sig
String resultSign = GBSignUtils.sign(resultMap, configInfo.getSignSecret());
resultMap.put("Sig", resultSign);
Map<String, String> resultMap = ThirdPartyPlatformUtils.generateResultMapV2(resultJson, thirdPartySecretInfoVO.getOurDataSecret(),
thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret());
return resultMap;
}
@@ -446,10 +431,8 @@ public class HuaWeiServiceImpl implements HuaWeiService {
*/
@Override
public Map<String, String> receiveDeliverEquipBusinessPolicyResult(ReceiveDeliverDTO dto) {
ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorId());
if (configInfo == null) {
return null;
}
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getHuaWeiPlatformSecretInfo();
List<ReceiveDeliverDTO.ChargePolicyInfoRet> chargePolicyInfoRets = dto.getChargePolicyInfoRets();
// 将下发失败的进行筛选、收集
List<ReceiveDeliverDTO.ChargePolicyInfoRet> failedList = chargePolicyInfoRets.stream()
@@ -466,17 +449,8 @@ public class HuaWeiServiceImpl implements HuaWeiService {
map.put("FailReason", 0);
// 加密
Map<String, String> resultMap = Maps.newLinkedHashMap();
// 加密数据
byte[] encryptText = Cryptos.aesEncrypt(JSON.toJSONString(map).getBytes(),
configInfo.getDataSecret().getBytes(), configInfo.getDataSecretIv().getBytes());
String encryptData = Encodes.encodeBase64(encryptText);
resultMap.put("Data", encryptData);
// 生成sig
String resultSign = GBSignUtils.sign(resultMap, configInfo.getSignSecret());
resultMap.put("Sig", resultSign);
Map<String, String> resultMap = ThirdPartyPlatformUtils.generateResultMapV2(map, thirdPartySecretInfoVO.getOurDataSecret(),
thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret());
return resultMap;
}
@@ -492,10 +466,7 @@ public class HuaWeiServiceImpl implements HuaWeiService {
*/
@Override
public Map<String, String> vinStartCharge(VinStartChargeDTO dto) throws Exception {
ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorId());
if (configInfo == null) {
return null;
}
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getHuaWeiPlatformSecretInfo();
Map<String, Object> paramMap = new LinkedHashMap<>();
String vinCode = dto.getVin();
@@ -533,17 +504,8 @@ public class HuaWeiServiceImpl implements HuaWeiService {
paramMap.put("FailReason", failReason);
// 加密
Map<String, String> resultMap = Maps.newLinkedHashMap();
// 加密数据
byte[] encryptText = Cryptos.aesEncrypt(JSON.toJSONString(paramMap).getBytes(),
configInfo.getDataSecret().getBytes(), configInfo.getDataSecretIv().getBytes());
String encryptData = Encodes.encodeBase64(encryptText);
resultMap.put("Data", encryptData);
// 生成sig
String resultSign = GBSignUtils.sign(resultMap, configInfo.getSignSecret());
resultMap.put("Sig", resultSign);
Map<String, String> resultMap = ThirdPartyPlatformUtils.generateResultMapV2(map, thirdPartySecretInfoVO.getOurDataSecret(),
thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret());
return resultMap;
}
@@ -558,13 +520,14 @@ public class HuaWeiServiceImpl implements HuaWeiService {
// 通过第三方配置类型查询相关配置信息
ThirdPartySettingInfo settingInfo = new ThirdPartySettingInfo();
settingInfo.setType(dto.getThirdPartyType());
ThirdPartySettingInfo thirdPartySettingInfo = thirdPartySettingInfoService.selectSettingInfo(settingInfo);
String operatorId = thirdPartySettingInfo.getOperatorId();
String operatorSecret = thirdPartySettingInfo.getOperatorSecret();
String signSecret = thirdPartySettingInfo.getSignSecret();
String dataSecret = thirdPartySettingInfo.getDataSecret();
String dataSecretIv = thirdPartySettingInfo.getDataSecretIv();
String urlAddress = thirdPartySettingInfo.getUrlAddress();
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getHuaWeiPlatformSecretInfo();
String operatorId = thirdPartySecretInfoVO.getTheirOperatorId();
String operatorSecret = thirdPartySecretInfoVO.getTheirOperatorSecret();
String signSecret = thirdPartySecretInfoVO.getTheirSigSecret();
String dataSecret = thirdPartySecretInfoVO.getTheirDataSecret();
String dataSecretIv = thirdPartySecretInfoVO.getTheirDataSecretIv();
String urlAddress = thirdPartySecretInfoVO.getTheirUrlPrefix();
List<HWStationInfo
.EquipmentLogicInfo> equipmentLogicInfos = new ArrayList<>();
@@ -655,4 +618,19 @@ public class HuaWeiServiceImpl implements HuaWeiService {
return connectorInfoList;
}
/**
* 获取华为平台配置密钥信息
*
* @return
*/
private ThirdPartySecretInfoVO getHuaWeiPlatformSecretInfo() {
// 通过第三方平台类型查询相关配置信息
ThirdPartySecretInfoVO thirdPartySecretInfoVO = thirdpartySecretInfoService.queryByThirdPlatformType(ThirdPlatformTypeEnum.HUA_WEI.getTypeCode());
if (thirdPartySecretInfoVO == null) {
throw new BusinessException(ReturnCodeEnum.CODE_SELECT_INFO_IS_NULL);
}
thirdPartySecretInfoVO.setOurOperatorId(Constants.OPERATORID_JIANG_SU);
return thirdPartySecretInfoVO;
}
}

View File

@@ -166,11 +166,11 @@ public interface LianLianService {
* @return
* @throws UnsupportedEncodingException
*/
Map<String, String> generateToken(CommonParamsDTO dto) throws UnsupportedEncodingException;
// Map<String, String> generateToken(CommonParamsDTO dto) throws UnsupportedEncodingException;
/**
* 校验签名
* @param dto
*/
Map<String, String> checkoutSign(CommonParamsDTO dto);
// Map<String, String> checkoutSign(CommonParamsDTO dto);
}

View File

@@ -16,10 +16,8 @@ import com.jsowell.common.enums.lianlian.StationPaymentEnum;
import com.jsowell.common.enums.thirdparty.BusinessInformationExchangeEnum;
import com.jsowell.common.enums.thirdparty.ThirdPartyOperatorIdEnum;
import com.jsowell.common.enums.thirdparty.ThirdPlatformTypeEnum;
import com.jsowell.common.enums.ykc.OrderPayModeEnum;
import com.jsowell.common.enums.ykc.OrderStatusEnum;
import com.jsowell.common.enums.ykc.PileConnectorDataBaseStatusEnum;
import com.jsowell.common.enums.ykc.PileStatusEnum;
import com.jsowell.common.enums.ykc.*;
import com.jsowell.common.exception.BusinessException;
import com.jsowell.common.util.*;
import com.jsowell.pile.domain.*;
import com.jsowell.pile.domain.ykcCommond.StartChargingCommand;
@@ -29,6 +27,7 @@ import com.jsowell.pile.thirdparty.CommonParamsDTO;
import com.jsowell.pile.thirdparty.ConnectorInfo;
import com.jsowell.pile.thirdparty.EquipmentInfo;
import com.jsowell.pile.util.MerchantUtils;
import com.jsowell.pile.vo.ThirdPartySecretInfoVO;
import com.jsowell.pile.vo.base.*;
import com.jsowell.pile.vo.lianlian.AccumulativeInfoVO;
import com.jsowell.pile.vo.lianlian.PushStationFeeVO;
@@ -43,10 +42,8 @@ import com.jsowell.thirdparty.lianlian.vo.*;
import com.jsowell.thirdparty.platform.common.ChargeDetail;
import com.jsowell.thirdparty.platform.common.OrderInfo;
import com.jsowell.thirdparty.platform.common.StationInfo;
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.platform.util.*;
import com.jsowell.thirdparty.service.ThirdpartySecretInfoService;
import com.jsowell.thirdparty.yongchengboche.dto.YCBCGetTokenDTO;
import com.jsowell.thirdparty.yongchengboche.service.YCBCService;
import org.apache.commons.collections4.CollectionUtils;
@@ -103,10 +100,7 @@ public class LianLianServiceImpl implements LianLianService {
private PileBillingTemplateService pileBillingTemplateService;
@Autowired
private ThirdPartySettingInfoService thirdPartySettingInfoService;
@Autowired
private ThirdPartyPlatformConfigService thirdPartyPlatformConfigService;
private ThirdpartySecretInfoService thirdpartySecretInfoService;
@Autowired
private ThirdPartyStationRelationService thirdPartyStationRelationService;
@@ -134,14 +128,14 @@ public class LianLianServiceImpl implements LianLianService {
// 通过第三方配置类型查询相关配置信息
ThirdPartySettingInfo settingInfo = new ThirdPartySettingInfo();
settingInfo.setType(dto.getThirdPartyType());
ThirdPartySettingInfo thirdPartySettingInfo = thirdPartySettingInfoService.selectSettingInfo(settingInfo);
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getLianLianPlatformSecretInfo();
String operatorId = thirdPartySettingInfo.getOperatorId();
String operatorSecret = thirdPartySettingInfo.getOperatorSecret();
String signSecret = thirdPartySettingInfo.getSignSecret();
String dataSecret = thirdPartySettingInfo.getDataSecret();
String dataSecretIv = thirdPartySettingInfo.getDataSecretIv();
String urlAddress = thirdPartySettingInfo.getUrlAddress();
String operatorId = thirdPartySecretInfoVO.getTheirOperatorId();
String operatorSecret = thirdPartySecretInfoVO.getTheirOperatorSecret();
String signSecret = thirdPartySecretInfoVO.getTheirSigSecret();
String dataSecret = thirdPartySecretInfoVO.getTheirDataSecret();
String dataSecretIv = thirdPartySecretInfoVO.getTheirDataSecretIv();
String urlAddress = thirdPartySecretInfoVO.getTheirUrlPrefix();
// 组装联联平台所需要的数据格式
StationInfo info = StationInfo.builder()
@@ -302,10 +296,8 @@ public class LianLianServiceImpl implements LianLianService {
// 未查到数据
return null;
}
ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorId());
if (configInfo == null) {
return null;
}
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getLianLianPlatformSecretInfo();
PageInfo<ThirdPartyStationInfoVO> pageInfo = new PageInfo<>(stationInfos);
for (ThirdPartyStationInfoVO pileStationInfo : pageInfo.getList()) {
StationInfo stationInfo = new StationInfo();
@@ -361,17 +353,8 @@ public class LianLianServiceImpl implements LianLianService {
// .list(resultList)
// .build();
// 加密
Map<String, String> resultMap = Maps.newLinkedHashMap();
// 加密数据
byte[] encryptText = Cryptos.aesEncrypt(JSON.toJSONString(map).getBytes(),
configInfo.getDataSecret().getBytes(), configInfo.getDataSecretIv().getBytes());
String encryptData = Encodes.encodeBase64(encryptText);
resultMap.put("Data", encryptData);
// 生成sig
String resultSign = GBSignUtils.sign(resultMap, configInfo.getSignSecret());
resultMap.put("Sig", resultSign);
Map<String, String> resultMap = ThirdPartyPlatformUtils.generateResultMapV2(map, thirdPartySecretInfoVO.getOurDataSecret(),
thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret());
return resultMap;
}
@@ -387,10 +370,8 @@ public class LianLianServiceImpl implements LianLianService {
List<String> stationIds = dto.getStationIds();
List<StationStatusInfo> StationStatusInfos = new ArrayList<>();
List<Object> ConnectorStatusInfos = new ArrayList<>();
ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorId());
if (configInfo == null) {
return null;
}
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getLianLianPlatformSecretInfo();
ConnectorStatusInfo connectorStatusInfo;
for (String stationId : stationIds) {
StationStatusInfo stationStatusInfo= new StationStatusInfo();
@@ -454,17 +435,8 @@ public class LianLianServiceImpl implements LianLianService {
map.put("StationStatusInfos", collect);
// 加密
Map<String, String> resultMap = Maps.newLinkedHashMap();
// 加密数据
byte[] encryptText = Cryptos.aesEncrypt(JSON.toJSONString(map).getBytes(),
configInfo.getDataSecret().getBytes(), configInfo.getDataSecretIv().getBytes());
String encryptData = Encodes.encodeBase64(encryptText);
resultMap.put("Data", encryptData);
// 生成sig
String resultSign = GBSignUtils.sign(resultMap, configInfo.getSignSecret());
resultMap.put("Sig", resultSign);
Map<String, String> resultMap = ThirdPartyPlatformUtils.generateResultMapV2(map, thirdPartySecretInfoVO.getOurDataSecret(),
thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret());
return resultMap;
}
@@ -476,10 +448,8 @@ public class LianLianServiceImpl implements LianLianService {
*/
@Override
public Map<String, String> query_station_stats(QueryStationInfoDTO dto) {
ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorId());
if (configInfo == null) {
return null;
}
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getLianLianPlatformSecretInfo();
// 根据站点id 查出这段时间的充电量
List<AccumulativeInfoVO> list = orderBasicInfoService.getAccumulativeInfoForLianLian(dto);
if (CollectionUtils.isEmpty(list)) {
@@ -553,17 +523,8 @@ public class LianLianServiceImpl implements LianLianService {
map.put("StationStats", stationStatsInfo);
// 加密
Map<String, String> resultMap = Maps.newLinkedHashMap();
// 加密数据
byte[] encryptText = Cryptos.aesEncrypt(JSON.toJSONString(map).getBytes(),
configInfo.getDataSecret().getBytes(), configInfo.getDataSecretIv().getBytes());
String encryptData = Encodes.encodeBase64(encryptText);
resultMap.put("Data", encryptData);
// 生成sig
String resultSign = GBSignUtils.sign(resultMap, configInfo.getSignSecret());
resultMap.put("Sig", resultSign);
Map<String, String> resultMap = ThirdPartyPlatformUtils.generateResultMapV2(map, thirdPartySecretInfoVO.getOurDataSecret(),
thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret());
return resultMap;
}
@@ -575,16 +536,13 @@ public class LianLianServiceImpl implements LianLianService {
*/
@Override
public Map<String, String> query_equip_auth(QueryEquipmentDTO dto) {
Map<String, String> resultMap = Maps.newLinkedHashMap();
EquipmentAuthVO vo = new EquipmentAuthVO();
String equipAuthSeq = dto.getEquipAuthSeq(); // MA1X78KH5202311071202015732
String pileConnectorCode = dto.getConnectorID();
// 先查询配置密钥相关信息
ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorID());
if (configInfo == null) {
return null;
}
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getLianLianPlatformSecretInfo();
// 根据桩编号查询数据
// String merchantId = StringUtils.substring(equipAuthSeq, 0, 9);
// String pileSn = StringUtils.substring(pileConnectorCode, 0, 14);
@@ -612,15 +570,8 @@ public class LianLianServiceImpl implements LianLianService {
vo.setFailReasonMsg("未查到该桩的数据");
}
// 加密数据
byte[] encryptText = Cryptos.aesEncrypt(JSON.toJSONString(vo).getBytes(),
configInfo.getDataSecret().getBytes(), configInfo.getDataSecretIv().getBytes());
String encryptData = Encodes.encodeBase64(encryptText);
resultMap.put("Data", encryptData);
// 生成sig
String resultSign = GBSignUtils.sign(resultMap, configInfo.getSignSecret());
resultMap.put("Sig", resultSign);
Map<String, String> resultMap = ThirdPartyPlatformUtils.generateResultMapV2(vo, thirdPartySecretInfoVO.getOurDataSecret(),
thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret());
return resultMap;
}
@@ -638,10 +589,8 @@ public class LianLianServiceImpl implements LianLianService {
// 平台已存在订单
return null;
}
ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorId());
if (configInfo == null) {
return null;
}
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getLianLianPlatformSecretInfo();
// 生成订单
Map<String, Object> map = orderBasicInfoService.generateOrderForThirdParty(dto);
String orderCode = (String) map.get("orderCode");
@@ -675,19 +624,9 @@ public class LianLianServiceImpl implements LianLianService {
}
// 加密
Map<String, String> resultMap = Maps.newLinkedHashMap();
// 加密数据
byte[] encryptText = Cryptos.aesEncrypt(JSON.toJSONString(vo).getBytes(),
configInfo.getDataSecret().getBytes(), configInfo.getDataSecretIv().getBytes());
String encryptData = Encodes.encodeBase64(encryptText);
resultMap.put("Data", encryptData);
// 生成sig
String resultSign = GBSignUtils.sign(resultMap, configInfo.getSignSecret());
resultMap.put("Sig", resultSign);
Map<String, String> resultMap = ThirdPartyPlatformUtils.generateResultMapV2(map, thirdPartySecretInfoVO.getOurDataSecret(),
thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret());
return resultMap;
}
@@ -707,11 +646,8 @@ public class LianLianServiceImpl implements LianLianService {
if (orderInfo == null) {
return null;
}
ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(operatorID);
// logger.info(operatorName + "查询密钥信息 configInfo:{}", configInfo);
if (configInfo == null) {
return null;
}
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getLianLianPlatformSecretInfo();
OrderDetail orderDetail = orderBasicInfoService.getOrderDetailByOrderCode(orderInfo.getOrderCode());
// 通过订单号查询实时数据
List<RealTimeMonitorData> realTimeData = orderBasicInfoService.getChargingRealTimeData(orderInfo.getTransactionCode());
@@ -762,17 +698,8 @@ public class LianLianServiceImpl implements LianLianService {
}
// 加密
Map<String, String> resultMap = Maps.newLinkedHashMap();
// 加密数据
byte[] encryptText = Cryptos.aesEncrypt(JSON.toJSONString(vo).getBytes(),
configInfo.getDataSecret().getBytes(), configInfo.getDataSecretIv().getBytes());
String encryptData = Encodes.encodeBase64(encryptText);
resultMap.put("Data", encryptData);
// 生成sig
String resultSign = GBSignUtils.sign(resultMap, configInfo.getSignSecret());
resultMap.put("Sig", resultSign);
Map<String, String> resultMap = ThirdPartyPlatformUtils.generateResultMapV2(vo, thirdPartySecretInfoVO.getOurDataSecret(),
thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret());
return resultMap;
}
@@ -793,10 +720,8 @@ public class LianLianServiceImpl implements LianLianService {
if (orderInfo == null) {
return null;
}
ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorId());
if (configInfo == null) {
return null;
}
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getLianLianPlatformSecretInfo();
// 若状态为充电中,则发送停机指令
if (StringUtils.equals(OrderStatusEnum.IN_THE_CHARGING.getValue(), orderInfo.getOrderStatus())) {
// 充电中
@@ -818,17 +743,8 @@ public class LianLianServiceImpl implements LianLianService {
vo.setStartChargeSeqStat(3);
}
// 加密
Map<String, String> resultMap = Maps.newLinkedHashMap();
// 加密数据
byte[] encryptText = Cryptos.aesEncrypt(JSON.toJSONString(vo).getBytes(),
configInfo.getDataSecret().getBytes(), configInfo.getDataSecretIv().getBytes());
String encryptData = Encodes.encodeBase64(encryptText);
resultMap.put("Data", encryptData);
// 生成sig
String resultSign = GBSignUtils.sign(resultMap, configInfo.getSignSecret());
resultMap.put("Sig", resultSign);
Map<String, String> resultMap = ThirdPartyPlatformUtils.generateResultMapV2(vo, thirdPartySecretInfoVO.getOurDataSecret(),
thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret());
return resultMap;
}
@@ -1195,9 +1111,10 @@ public class LianLianServiceImpl implements LianLianService {
}
String data = map.get("Data");
// 解密data (此处解密需用 thirdparty_platform_config 的密钥配置)
ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(operatorIdByType);
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getLianLianPlatformSecretInfo();
byte[] plainText = Cryptos.aesDecrypt(Encodes.decodeBase64(data),
configInfo.getDataSecret().getBytes(), configInfo.getDataSecretIv().getBytes());
thirdPartySecretInfoVO.getOurDataSecret().getBytes(), thirdPartySecretInfoVO.getOurDataSecretIv().getBytes());
String dataStr = new String(plainText, StandardCharsets.UTF_8);
// 转成对应的对象
QueryChargingStatusVO vo = JSONObject.parseObject(dataStr, QueryChargingStatusVO.class);
@@ -1397,11 +1314,8 @@ public class LianLianServiceImpl implements LianLianService {
if (orderInfo == null || orderDetail == null) {
return null;
}
// 通过operatorID 查出 operatorSecret
ThirdPartyPlatformConfig platformConfig = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorId());
if (platformConfig == null) {
return null;
}
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getLianLianPlatformSecretInfo();
// orderInfo 和 orderDetail 都不为空,再根据传过来的数据进行修改数据库信息
confirmResult = Constants.zero;
orderDetail.setTotalUsedElectricity(dto.getTotalPower()); // 累计充电量
@@ -1414,12 +1328,12 @@ public class LianLianServiceImpl implements LianLianService {
Map<String, String> resultMap = Maps.newLinkedHashMap();
// 加密数据
byte[] encryptText = Cryptos.aesEncrypt(JSON.toJSONString(map).getBytes(),
platformConfig.getDataSecret().getBytes(), platformConfig.getDataSecretIv().getBytes());
thirdPartySecretInfoVO.getOurDataSecret().getBytes(), thirdPartySecretInfoVO.getOurDataSecretIv().getBytes());
String encryptData = Encodes.encodeBase64(encryptText);
resultMap.put("Data", encryptData);
// 生成sig
String resultSign = GBSignUtils.sign(resultMap, platformConfig.getSignSecret());
String resultSign = GBSignUtils.sign(resultMap, thirdPartySecretInfoVO.getOurSigSecret());
resultMap.put("Sig", resultSign);
return resultMap;
@@ -1670,107 +1584,104 @@ public class LianLianServiceImpl implements LianLianService {
* @return
* @throws UnsupportedEncodingException
*/
@Override
public Map<String, String> generateToken(CommonParamsDTO dto) throws UnsupportedEncodingException {
String operatorId = dto.getOperatorID();
// 通过operatorId 查出 operatorSecret
ThirdPartyPlatformConfig platformConfig = thirdPartyPlatformConfigService.getInfoByOperatorId(operatorId);
if (platformConfig == null) {
return null;
}
String operatorSecret = platformConfig.getOperatorSecret();
String dataSecret = platformConfig.getDataSecret();
String dataSecretIv = platformConfig.getDataSecretIv();
String signSecret = platformConfig.getSignSecret();
// 校验签名
Map<String, String> checkResultMap = checkoutSign(dto);
if (checkResultMap == null) {
// 校验失败
return null;
}
String dataString = checkResultMap.get("Data");
// 解密data
byte[] plainText = Cryptos.aesDecrypt(Encodes.decodeBase64(dataString), dataSecret.getBytes(), dataSecretIv.getBytes());
String dataStr = new String(plainText, StandardCharsets.UTF_8);
Map<String, String> resMap = (Map<String, String>) JSON.parse(dataStr);
String secret = resMap.get("OperatorSecret");
// 对比解出来的密钥是否和数据库中保存的一致
if (!StringUtils.equals(operatorSecret, secret)) {
System.out.println("密钥不一致");
return null;
}
System.out.println("密钥校验通过!! 密钥为: " + operatorSecret);
// 生成token返回 eyJhbGciOiJIUzI1NiJ9.eyJqdGkiOiI0MjUwMTA3NjUiLCJpYXQiOjE2ODUwOTcxMTYsInN1YiI6IjEyMzEyMzEyMzEyM2FhYWEiLCJleHAiOjY4NjkwOTcxMTZ9.NyxOUIZmgsqtfex7oiMRR2LaWePTA56WHVMXIkWWt2w
long ttlMillis = 60 * 60 * 24 * 1000;
String token = JWTUtils.createToken(operatorId, operatorSecret, ttlMillis);
System.out.println("生成的token" + token);
// 组装返回参数
AccessTokenVO vo = new AccessTokenVO();
vo.setAccessToken(token);
vo.setOperatorID(operatorId);
vo.setTokenAvailableTime((int) (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);
resultMap.put("Data", encryptData);
// 生成sig
String resultSign = GBSignUtils.sign(resultMap, signSecret);
resultMap.put("Sig", resultSign);
return resultMap;
}
// @Override
// public Map<String, String> generateToken(CommonParamsDTO dto) throws UnsupportedEncodingException {
// String operatorId = dto.getOperatorID();
// ThirdPartySecretInfoVO thirdPartySecretInfoVO = getLianLianPlatformSecretInfo();
//
// String operatorSecret = thirdPartySecretInfoVO.getOurOperatorSecret();
// String dataSecret = thirdPartySecretInfoVO.getOurDataSecret();
// String dataSecretIv = thirdPartySecretInfoVO.getOurDataSecretIv();
// String signSecret = thirdPartySecretInfoVO.getOurSigSecret();
// // 校验签名
// Map<String, String> checkResultMap = checkoutSign(dto);
// if (checkResultMap == null) {
// // 校验失败
// return null;
// }
// String dataString = checkResultMap.get("Data");
// // 解密data
// byte[] plainText = Cryptos.aesDecrypt(Encodes.decodeBase64(dataString), dataSecret.getBytes(), dataSecretIv.getBytes());
// String dataStr = new String(plainText, StandardCharsets.UTF_8);
// Map<String, String> resMap = (Map<String, String>) JSON.parse(dataStr);
// String secret = resMap.get("OperatorSecret");
//
// // 对比解出来的密钥是否和数据库中保存的一致
// if (!StringUtils.equals(operatorSecret, secret)) {
// System.out.println("密钥不一致");
// return null;
// }
// System.out.println("密钥校验通过!! 密钥为: " + operatorSecret);
//
// // 生成token返回 eyJhbGciOiJIUzI1NiJ9.eyJqdGkiOiI0MjUwMTA3NjUiLCJpYXQiOjE2ODUwOTcxMTYsInN1YiI6IjEyMzEyMzEyMzEyM2FhYWEiLCJleHAiOjY4NjkwOTcxMTZ9.NyxOUIZmgsqtfex7oiMRR2LaWePTA56WHVMXIkWWt2w
// long ttlMillis = 60 * 60 * 24 * 1000;
// String token = JWTUtils.createToken(operatorId, operatorSecret, ttlMillis);
// System.out.println("生成token" + token);
//
// // 组装返回参数
// AccessTokenVO vo = new AccessTokenVO();
// vo.setAccessToken(token);
// vo.setOperatorID(operatorId);
// vo.setTokenAvailableTime((int) (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);
//
// resultMap.put("Data", encryptData);
// // 生成sig
// String resultSign = GBSignUtils.sign(resultMap, signSecret);
// resultMap.put("Sig", resultSign);
//
// return resultMap;
// }
/**
* 校验签名并返回data(未解密)
* @param dto
*/
@Override
public Map<String, String> checkoutSign(CommonParamsDTO dto){
String operatorID = dto.getOperatorID();
// 通过operatorID 查出 operatorSecret
ThirdPartyPlatformConfig platformConfig = thirdPartyPlatformConfigService.getInfoByOperatorId(operatorID);
if (platformConfig == null) {
return null;
}
String operatorSecret = platformConfig.getOperatorSecret();
String signSecret = platformConfig.getSignSecret();
Map<String, String> map = Maps.newLinkedHashMap();
map.put("OperatorID", dto.getOperatorID());
map.put("Data", dto.getData());
map.put("TimeStamp", dto.getTimeStamp());
map.put("Seq", dto.getSeq());
String sign = GBSignUtils.sign(map, signSecret);
System.out.println(sign);
// 验证签名 得到请求方传过来的签名sig->自己拿到请求体后再按双方约定的协议生成一个sig->对比两个sig是否一致
if (!StringUtils.equals(dto.getSig(), sign)) {
System.out.println("签名校验==失败");
return null;
}
System.out.println("签名校验通过!!!");
// 解密data
// byte[] plainText = Cryptos.aesDecrypt(Encodes.decodeBase64(dto.getData()), operatorSecret.getBytes(), operatorSecret.getBytes());
// String dataStr = new String(plainText, "UTF-8");
// Map<String, String> resMap = (Map<String, String>) JSON.parse(dataStr);
// return resMap;
Map<String, String> resultMap = new LinkedHashMap<>();
resultMap.put("Data", dto.getData());
resultMap.put("OperatorSecret", operatorSecret);
resultMap.put("DataSecret", platformConfig.getDataSecret());
resultMap.put("DataSecretIV", platformConfig.getDataSecretIv());
return resultMap;
}
// @Override
// public Map<String, String> checkoutSign(CommonParamsDTO dto){
// String operatorID = dto.getOperatorID();
// // 通过operatorID 查出 operatorSecret
// ThirdPartyPlatformConfig platformConfig = thirdPartyPlatformConfigService.getInfoByOperatorId(operatorID);
// if (platformConfig == null) {
// return null;
// }
// String operatorSecret = platformConfig.getOperatorSecret();
// String signSecret = platformConfig.getSignSecret();
//
// Map<String, String> map = Maps.newLinkedHashMap();
// map.put("OperatorID", dto.getOperatorID());
// map.put("Data", dto.getData());
// map.put("TimeStamp", dto.getTimeStamp());
// map.put("Seq", dto.getSeq());
// String sign = GBSignUtils.sign(map, signSecret);
// System.out.println(sign);
//
// // 验证签名 得到请求方传过来的签名sig->自己拿到请求体后再按双方约定的协议生成一个sig->对比两个sig是否一致
// if (!StringUtils.equals(dto.getSig(), sign)) {
// System.out.println("签名校验==失败");
// return null;
// }
// System.out.println("签名校验通过!!!");
//
// // 解密data
// // byte[] plainText = Cryptos.aesDecrypt(Encodes.decodeBase64(dto.getData()), operatorSecret.getBytes(), operatorSecret.getBytes());
// // String dataStr = new String(plainText, "UTF-8");
// // Map<String, String> resMap = (Map<String, String>) JSON.parse(dataStr);
// // return resMap;
// Map<String, String> resultMap = new LinkedHashMap<>();
// resultMap.put("Data", dto.getData());
// resultMap.put("OperatorSecret", operatorSecret);
// resultMap.put("DataSecret", platformConfig.getDataSecret());
// resultMap.put("DataSecretIV", platformConfig.getDataSecretIv());
// return resultMap;
// }
/**
* TODO 请求打印充电小票
@@ -1870,4 +1781,19 @@ public class LianLianServiceImpl implements LianLianService {
return resultList;
}
/**
* 获取联联平台配置密钥信息
*
* @return
*/
private ThirdPartySecretInfoVO getLianLianPlatformSecretInfo() {
// 通过第三方平台类型查询相关配置信息
ThirdPartySecretInfoVO thirdPartySecretInfoVO = thirdpartySecretInfoService.queryByThirdPlatformType(ThirdPlatformTypeEnum.LIAN_LIAN_PLATFORM.getTypeCode());
if (thirdPartySecretInfoVO == null) {
throw new BusinessException(ReturnCodeEnum.CODE_SELECT_INFO_IS_NULL);
}
thirdPartySecretInfoVO.setOurOperatorId(Constants.OPERATORID_JIANG_SU);
return thirdPartySecretInfoVO;
}
}

View File

@@ -33,13 +33,13 @@ public interface NRService {
* @return
* @throws UnsupportedEncodingException
*/
Map<String, String> generateToken(CommonParamsDTO dto) throws UnsupportedEncodingException;
// Map<String, String> generateToken(CommonParamsDTO dto) throws UnsupportedEncodingException;
/**
* 校验签名
* @param dto
*/
Map<String, String> checkoutSign(CommonParamsDTO dto);
// Map<String, String> checkoutSign(CommonParamsDTO dto);
/**
* 推送充电站信息

View File

@@ -11,7 +11,10 @@ import com.jsowell.common.core.domain.ykc.RealTimeMonitorData;
import com.jsowell.common.core.redis.RedisCache;
import com.jsowell.common.enums.thirdparty.BusinessInformationExchangeEnum;
import com.jsowell.common.enums.thirdparty.JiangSuConstructionEnum;
import com.jsowell.common.enums.thirdparty.ThirdPlatformTypeEnum;
import com.jsowell.common.enums.ykc.PileStatusEnum;
import com.jsowell.common.enums.ykc.ReturnCodeEnum;
import com.jsowell.common.exception.BusinessException;
import com.jsowell.common.util.DateUtils;
import com.jsowell.common.util.PageUtils;
import com.jsowell.common.util.StringUtils;
@@ -24,6 +27,7 @@ import com.jsowell.pile.dto.QueryStationInfoDTO;
import com.jsowell.pile.dto.nanrui.NRQueryOrderDTO;
import com.jsowell.pile.dto.nanrui.PushAlarmInfoDTO;
import com.jsowell.pile.service.*;
import com.jsowell.pile.vo.ThirdPartySecretInfoVO;
import com.jsowell.pile.vo.base.MerchantInfoVO;
import com.jsowell.pile.vo.base.ThirdPartyStationInfoVO;
import com.jsowell.pile.vo.base.ThirdPartyStationRelationVO;
@@ -35,12 +39,10 @@ import com.jsowell.pile.vo.web.PileStationVO;
import com.jsowell.thirdparty.common.CommonService;
import com.jsowell.pile.thirdparty.CommonParamsDTO;
import com.jsowell.thirdparty.lianlian.service.LianLianService;
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.platform.util.*;
import com.jsowell.thirdparty.nanrui.domain.*;
import com.jsowell.thirdparty.nanrui.service.NRService;
import com.jsowell.thirdparty.service.ThirdpartySecretInfoService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.RandomStringUtils;
@@ -88,10 +90,7 @@ public class NRServiceImpl implements NRService {
private ThirdPartyStationRelationService thirdPartyStationRelationService;
@Autowired
private ThirdPartyPlatformConfigService thirdPartyPlatformConfigService;
@Autowired
private ThirdPartySettingInfoService thirdPartySettingInfoService;
private ThirdpartySecretInfoService thirdpartySecretInfoService;
@Autowired
private LianLianService lianLianService;
@@ -120,15 +119,15 @@ public class NRServiceImpl implements NRService {
dataSecretIv, signSecret, dataSecret);
}
@Override
public Map<String, String> generateToken(CommonParamsDTO dto) throws UnsupportedEncodingException {
return lianLianService.generateToken(dto);
}
// @Override
// public Map<String, String> generateToken(CommonParamsDTO dto) throws UnsupportedEncodingException {
// return lianLianService.generateToken(dto);
// }
@Override
public Map<String, String> checkoutSign(CommonParamsDTO dto) {
return lianLianService.checkoutSign(dto);
}
// @Override
// public Map<String, String> checkoutSign(CommonParamsDTO dto) {
// return lianLianService.checkoutSign(dto);
// }
/**
* 推送充电站信息
@@ -254,14 +253,14 @@ public class NRServiceImpl implements NRService {
// 通过第三方配置类型查询相关配置信息
ThirdPartySettingInfo settingInfo = new ThirdPartySettingInfo();
settingInfo.setType(dto.getThirdPartyType());
ThirdPartySettingInfo thirdPartySettingInfo = thirdPartySettingInfoService.selectSettingInfo(settingInfo);
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getJiangSuPlatformSecretInfo();
String operatorId = thirdPartySettingInfo.getOperatorId();
String operatorSecret = thirdPartySettingInfo.getOperatorSecret();
String signSecret = thirdPartySettingInfo.getSignSecret();
String dataSecret = thirdPartySettingInfo.getDataSecret();
String dataSecretIv = thirdPartySettingInfo.getDataSecretIv();
String urlAddress = thirdPartySettingInfo.getUrlAddress();
String operatorId = thirdPartySecretInfoVO.getTheirOperatorId();
String operatorSecret = thirdPartySecretInfoVO.getTheirOperatorSecret();
String signSecret = thirdPartySecretInfoVO.getTheirSigSecret();
String dataSecret = thirdPartySecretInfoVO.getTheirDataSecret();
String dataSecretIv = thirdPartySecretInfoVO.getTheirDataSecretIv();
String urlAddress = thirdPartySecretInfoVO.getTheirUrlPrefix();
// 拼装南瑞平台所需参数
NRStationInfo nrStationInfo = NRStationInfo.builder()
@@ -366,10 +365,8 @@ public class NRServiceImpl implements NRService {
// 未查到数据
return null;
}
ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorId());
if (configInfo == null) {
return null;
}
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getJiangSuPlatformSecretInfo();
PageInfo<ThirdPartyStationInfoVO> pageInfo = new PageInfo<>(stationInfos);
for (ThirdPartyStationInfoVO pileStationInfo : pageInfo.getList()) {
// 拼装参数
@@ -431,17 +428,8 @@ public class NRServiceImpl implements NRService {
map.put("StationInfos", resultList);
// 加密
Map<String, String> resultMap = Maps.newLinkedHashMap();
// 加密数据
byte[] encryptText = Cryptos.aesEncrypt(JSON.toJSONString(map).getBytes(),
configInfo.getDataSecret().getBytes(), configInfo.getDataSecretIv().getBytes());
String encryptData = Encodes.encodeBase64(encryptText);
resultMap.put("Data", encryptData);
// 生成sig
String resultSign = GBSignUtils.sign(resultMap, configInfo.getSignSecret());
resultMap.put("Sig", resultSign);
Map<String, String> resultMap = ThirdPartyPlatformUtils.generateResultMapV2(map, thirdPartySecretInfoVO.getOurDataSecret(),
thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret());
return resultMap;
}
@@ -588,10 +576,8 @@ public class NRServiceImpl implements NRService {
public Map<String, String> query_station_status(QueryStationInfoDTO dto) {
List<String> stationIds = dto.getStationIds();
List<NRStationStatusInfo> resultList = new ArrayList<>();
ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorId());
if (configInfo == null) {
return null;
}
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getJiangSuPlatformSecretInfo();
// 将 stationIdList 转换成 List<Long>
List<Long> stationLongList = stationIds.stream()
.map(Long::parseLong)
@@ -651,17 +637,8 @@ public class NRServiceImpl implements NRService {
map.put("StationStatusInfos", resultList);
// 加密
Map<String, String> resultMap = Maps.newLinkedHashMap();
// 加密数据
byte[] encryptText = Cryptos.aesEncrypt(JSON.toJSONString(map).getBytes(),
configInfo.getDataSecret().getBytes(), configInfo.getDataSecretIv().getBytes());
String encryptData = Encodes.encodeBase64(encryptText);
resultMap.put("Data", encryptData);
// 生成sig
String resultSign = GBSignUtils.sign(resultMap, configInfo.getSignSecret());
resultMap.put("Sig", resultSign);
Map<String, String> resultMap = ThirdPartyPlatformUtils.generateResultMapV2(map, thirdPartySecretInfoVO.getOurDataSecret(),
thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret());
return resultMap;
}
@@ -718,10 +695,8 @@ public class NRServiceImpl implements NRService {
@Override
public Map<String, String> query_order_info(NRQueryOrderDTO dto) {
List<JiangSuOrderInfo> resultList = new ArrayList<>();
ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorId());
if (configInfo == null) {
return null;
}
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getJiangSuPlatformSecretInfo();
List<JiangSuOrderInfoVO> nrOrderInfos = orderBasicInfoService.getNROrderInfos(dto);
if (CollectionUtils.isEmpty(nrOrderInfos)) {
return Maps.newLinkedHashMap();
@@ -731,17 +706,8 @@ public class NRServiceImpl implements NRService {
resultList.add(jiangSuOrderInfo);
}
// 加密
Map<String, String> resultMap = Maps.newLinkedHashMap();
// 加密数据
byte[] encryptText = Cryptos.aesEncrypt(JSON.toJSONString(resultList).getBytes(),
configInfo.getDataSecret().getBytes(), configInfo.getDataSecretIv().getBytes());
String encryptData = Encodes.encodeBase64(encryptText);
resultMap.put("Data", encryptData);
// 生成sig
String resultSign = GBSignUtils.sign(resultMap, configInfo.getSignSecret());
resultMap.put("Sig", resultSign);
Map<String, String> resultMap = ThirdPartyPlatformUtils.generateResultMapV2(resultList, thirdPartySecretInfoVO.getOurDataSecret(),
thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret());
return resultMap;
}
@@ -872,4 +838,19 @@ public class NRServiceImpl implements NRService {
}
return resultList;
}
/**
* 获取江苏省平台配置密钥信息
*
* @return
*/
private ThirdPartySecretInfoVO getJiangSuPlatformSecretInfo() {
// 通过第三方平台类型查询相关配置信息
ThirdPartySecretInfoVO thirdPartySecretInfoVO = thirdpartySecretInfoService.queryByThirdPlatformType(ThirdPlatformTypeEnum.JIANG_SU_PLATFORM.getTypeCode());
if (thirdPartySecretInfoVO == null) {
throw new BusinessException(ReturnCodeEnum.CODE_SELECT_INFO_IS_NULL);
}
thirdPartySecretInfoVO.setOurOperatorId(Constants.OPERATORID_JIANG_SU);
return thirdPartySecretInfoVO;
}
}

View File

@@ -21,7 +21,7 @@ public interface NXJTService {
* @return
* @throws UnsupportedEncodingException
*/
Map<String, String> generateToken(CommonParamsDTO dto) throws UnsupportedEncodingException;
// Map<String, String> generateToken(CommonParamsDTO dto) throws UnsupportedEncodingException;
/**

View File

@@ -3,6 +3,10 @@ package com.jsowell.thirdparty.ningxiajiaotou.service.impl;
import com.alibaba.fastjson2.JSON;
import com.github.pagehelper.PageInfo;
import com.google.common.collect.Maps;
import com.jsowell.common.constant.Constants;
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.DateUtils;
import com.jsowell.common.util.PageUtils;
import com.jsowell.common.util.StringUtils;
@@ -10,6 +14,7 @@ import com.jsowell.pile.domain.ThirdPartyPlatformConfig;
import com.jsowell.pile.dto.ningxiajiaotou.NXJTQueryOrdersInfoDTO;
import com.jsowell.pile.dto.ningxiajiaotou.NXJTQueryStationInfoDTO;
import com.jsowell.pile.service.*;
import com.jsowell.pile.vo.ThirdPartySecretInfoVO;
import com.jsowell.pile.vo.base.ConnectorInfoVO;
import com.jsowell.pile.vo.ningxiajiaotou.NXJTOrderVO;
import com.jsowell.pile.vo.ningxiajiaotou.NXJTStationInfoVO;
@@ -20,6 +25,8 @@ 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.ningxiajiaotou.service.NXJTService;
import com.jsowell.thirdparty.platform.util.ThirdPartyPlatformUtils;
import com.jsowell.thirdparty.service.ThirdpartySecretInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -43,7 +50,7 @@ public class NXJTServiceImpl implements NXJTService {
private PileStationInfoService pileStationInfoService;
@Autowired
private ThirdPartyPlatformConfigService thirdPartyPlatformConfigService;
private ThirdpartySecretInfoService thirdpartySecretInfoService;
@Autowired
private PileBasicInfoService pileBasicInfoService;
@@ -60,10 +67,10 @@ public class NXJTServiceImpl implements NXJTService {
* @return
* @throws UnsupportedEncodingException
*/
@Override
public Map<String, String> generateToken(CommonParamsDTO dto) throws UnsupportedEncodingException {
return lianLianService.generateToken(dto);
}
// @Override
// public Map<String, String> generateToken(CommonParamsDTO dto) throws UnsupportedEncodingException {
// return lianLianService.generateToken(dto);
// }
/**
* 获取令牌
@@ -90,10 +97,7 @@ public class NXJTServiceImpl implements NXJTService {
int pageNo = dto.getPageNo() == null ? 1 : dto.getPageNo();
int pageSize = dto.getPageSize() == null ? 10 : dto.getPageSize();
ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorId());
if (configInfo == null) {
return null;
}
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getNXJTPlatformSecretInfo();
// 分页
PageUtils.startPage(pageNo, pageSize);
List<NXJTStationInfoVO> stationInfos = pileStationInfoService.NXJTQueryStationsInfo(dto);
@@ -106,17 +110,8 @@ public class NXJTServiceImpl implements NXJTService {
map.put("stationInfos", pageInfo.getList());
// 加密
Map<String, String> resultMap = Maps.newLinkedHashMap();
// 加密数据
byte[] encryptText = Cryptos.aesEncrypt(JSON.toJSONString(map).getBytes(),
configInfo.getDataSecret().getBytes(), configInfo.getDataSecretIv().getBytes());
String encryptData = Encodes.encodeBase64(encryptText);
resultMap.put("Data", encryptData);
// 生成sig
String resultSign = GBSignUtils.sign(resultMap, configInfo.getSignSecret());
resultMap.put("Sig", resultSign);
Map<String, String> resultMap = ThirdPartyPlatformUtils.generateResultMapV2(map, thirdPartySecretInfoVO.getOurDataSecret(),
thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret());
return resultMap;
}
@@ -127,10 +122,8 @@ public class NXJTServiceImpl implements NXJTService {
*/
@Override
public Map<String, String> queryFreePileNumber(NXJTQueryStationInfoDTO dto) {
ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorId());
if (configInfo == null) {
return null;
}
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getNXJTPlatformSecretInfo();
long stationId = Long.parseLong(dto.getStationId());
List<ConnectorInfoVO> connectorList = pileConnectorInfoService.getUniAppConnectorList(stationId);
// 先根据pileSn分组获取设备总数
@@ -153,17 +146,8 @@ public class NXJTServiceImpl implements NXJTService {
map.put("freePileNum", freePileNumber);
// 加密
Map<String, String> resultMap = Maps.newLinkedHashMap();
// 加密数据
byte[] encryptText = Cryptos.aesEncrypt(JSON.toJSONString(map).getBytes(),
configInfo.getDataSecret().getBytes(), configInfo.getDataSecretIv().getBytes());
String encryptData = Encodes.encodeBase64(encryptText);
resultMap.put("Data", encryptData);
// 生成sig
String resultSign = GBSignUtils.sign(resultMap, configInfo.getSignSecret());
resultMap.put("Sig", resultSign);
Map<String, String> resultMap = ThirdPartyPlatformUtils.generateResultMapV2(map, thirdPartySecretInfoVO.getOurDataSecret(),
thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret());
return resultMap;
}
@@ -178,10 +162,8 @@ public class NXJTServiceImpl implements NXJTService {
int pageNo = dto.getPageNo() == null ? 1 : dto.getPageNo();
int pageSize = dto.getPageSize() == null ? 10 : dto.getPageSize();
ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorId());
if (configInfo == null) {
return null;
}
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getNXJTPlatformSecretInfo();
// 如果开始时间、结束时间为空,则默认为一个月内
if (StringUtils.isBlank(dto.getStartTime()) && StringUtils.isBlank(dto.getEndTime())) {
dto.setStartTime(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, DateUtils.addMonths(new Date(), -1)));
@@ -212,17 +194,8 @@ public class NXJTServiceImpl implements NXJTService {
map.put("orderInfos", resultList);
// 加密
Map<String, String> resultMap = Maps.newLinkedHashMap();
// 加密数据
byte[] encryptText = Cryptos.aesEncrypt(JSON.toJSONString(map).getBytes(),
configInfo.getDataSecret().getBytes(), configInfo.getDataSecretIv().getBytes());
String encryptData = Encodes.encodeBase64(encryptText);
resultMap.put("Data", encryptData);
// 生成sig
String resultSign = GBSignUtils.sign(resultMap, configInfo.getSignSecret());
resultMap.put("Sig", resultSign);
Map<String, String> resultMap = ThirdPartyPlatformUtils.generateResultMapV2(map, thirdPartySecretInfoVO.getOurDataSecret(),
thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret());
return resultMap;
}
@@ -238,4 +211,19 @@ public class NXJTServiceImpl implements NXJTService {
return queryOrdersInfoByPlateNumber(dto);
// return null;
}
/**
* 获取宁夏交投平台配置密钥信息
*
* @return
*/
private ThirdPartySecretInfoVO getNXJTPlatformSecretInfo() {
// 通过第三方平台类型查询相关配置信息
ThirdPartySecretInfoVO thirdPartySecretInfoVO = thirdpartySecretInfoService.queryByThirdPlatformType(ThirdPlatformTypeEnum.NING_XIA_JIAO_TOU.getTypeCode());
if (thirdPartySecretInfoVO == null) {
throw new BusinessException(ReturnCodeEnum.CODE_SELECT_INFO_IS_NULL);
}
thirdPartySecretInfoVO.setOurOperatorId(Constants.OPERATORID_JIANG_SU);
return thirdPartySecretInfoVO;
}
}

View File

@@ -13,6 +13,8 @@ import com.jsowell.common.enums.thirdparty.ThirdPartyOperatorIdEnum;
import com.jsowell.common.enums.thirdparty.ThirdPlatformTypeEnum;
import com.jsowell.common.enums.ykc.OrderStatusEnum;
import com.jsowell.common.enums.ykc.PileConnectorDataBaseStatusEnum;
import com.jsowell.common.enums.ykc.ReturnCodeEnum;
import com.jsowell.common.exception.BusinessException;
import com.jsowell.common.util.*;
import com.jsowell.pile.domain.*;
import com.jsowell.pile.domain.ykcCommond.StartChargingCommand;
@@ -37,10 +39,8 @@ import com.jsowell.thirdparty.lianlian.vo.QueryStopChargeVO;
import com.jsowell.thirdparty.platform.service.ThirdPartyPlatformService;
import com.jsowell.thirdparty.platform.factory.ThirdPartyPlatformFactory;
import com.jsowell.thirdparty.platform.domain.HNStationInfo;
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.platform.util.*;
import com.jsowell.thirdparty.service.ThirdpartySecretInfoService;
import com.jsowell.thirdparty.zhongdianlian.service.ZDLService;
import org.apache.commons.collections4.CollectionUtils;
import org.slf4j.Logger;
@@ -89,10 +89,7 @@ public class HaiNanPlatformServiceImpl implements ThirdPartyPlatformService {
private OrderBasicInfoService orderBasicInfoService;
@Autowired
private ThirdPartyPlatformConfigService thirdPartyPlatformConfigService;
@Autowired
private ThirdPartySettingInfoService thirdPartySettingInfoService;
private ThirdpartySecretInfoService thirdpartySecretInfoService;
@Resource
private ThirdPartyStationRelationService thirdPartyStationRelationService;
@@ -146,10 +143,8 @@ public class HaiNanPlatformServiceImpl implements ThirdPartyPlatformService {
// 未查到数据
return null;
}
ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorId());
if (configInfo == null) {
return null;
}
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getHaiNanPlatformSecretInfo();
PageInfo<ThirdPartyStationInfoVO> pageInfo = new PageInfo<>(stationInfos);
List<HNStationInfo> resultList = new ArrayList<>();
HNStationInfo stationInfo = null;
@@ -211,13 +206,8 @@ public class HaiNanPlatformServiceImpl implements ThirdPartyPlatformService {
map.put("ItemSize", resultList.size());
map.put("StationInfos", resultList);
Map<String, String> resultMap = Maps.newLinkedHashMap();
// 加密数据
String encryptData = Cryptos.aesEncrypt(JSON.toJSONString(map), configInfo.getDataSecret(), configInfo.getDataSecretIv());
resultMap.put("Data", encryptData);
// 生成sig
String resultSign = GBSignUtils.sign(resultMap, configInfo.getSignSecret());
resultMap.put("Sig", resultSign);
Map<String, String> resultMap = ThirdPartyPlatformUtils.generateResultMapV2(map, thirdPartySecretInfoVO.getOurDataSecret(),
thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret());
return resultMap;
}
@@ -415,10 +405,8 @@ public class HaiNanPlatformServiceImpl implements ThirdPartyPlatformService {
List<String> stationIds = dto.getStationIds();
List<StationStatusInfo> StationStatusInfos = new ArrayList<>();
List<Object> ConnectorStatusInfos = new ArrayList<>();
ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorId());
if (configInfo == null) {
return null;
}
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getHaiNanPlatformSecretInfo();
ConnectorStatusInfo connectorStatusInfo;
for (String stationId : stationIds) {
StationStatusInfo stationStatusInfo = new StationStatusInfo();
@@ -481,13 +469,8 @@ public class HaiNanPlatformServiceImpl implements ThirdPartyPlatformService {
map.put("Total", total);
map.put("StationStatusInfos", collect);
Map<String, String> resultMap = Maps.newLinkedHashMap();
// 加密数据
String encryptData = Cryptos.aesEncrypt(JSON.toJSONString(map), configInfo.getDataSecret(), configInfo.getDataSecretIv());
resultMap.put("Data", encryptData);
// 生成sig
String resultSign = GBSignUtils.sign(resultMap, configInfo.getSignSecret());
resultMap.put("Sig", resultSign);
Map<String, String> resultMap = ThirdPartyPlatformUtils.generateResultMapV2(map, thirdPartySecretInfoVO.getOurDataSecret(),
thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret());
return resultMap;
}
@@ -499,10 +482,7 @@ public class HaiNanPlatformServiceImpl implements ThirdPartyPlatformService {
@Override
public Map<String, String> queryStationStats(QueryStationInfoDTO dto) {
// 查询信息
ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorId());
if (configInfo == null) {
return null;
}
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getHaiNanPlatformSecretInfo();
// 根据站点id 查出这段时间的充电量
List<AccumulativeInfoVO> list = orderBasicInfoService.getAccumulativeInfoForLianLian(dto);
if (CollectionUtils.isEmpty(list)) {
@@ -575,13 +555,8 @@ public class HaiNanPlatformServiceImpl implements ThirdPartyPlatformService {
Map<String, Object> map = new LinkedHashMap<>();
map.put("StationStats", stationStatsInfo);
Map<String, String> resultMap = Maps.newLinkedHashMap();
// 加密数据
String encryptData = Cryptos.aesEncrypt(JSON.toJSONString(map), configInfo.getDataSecret(), configInfo.getDataSecretIv());
resultMap.put("Data", encryptData);
// 生成sig
String resultSign = GBSignUtils.sign(resultMap, configInfo.getSignSecret());
resultMap.put("Sig", resultSign);
Map<String, String> resultMap = ThirdPartyPlatformUtils.generateResultMapV2(map, thirdPartySecretInfoVO.getOurDataSecret(),
thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret());
return resultMap;
}
@@ -598,10 +573,8 @@ public class HaiNanPlatformServiceImpl implements ThirdPartyPlatformService {
String equipAuthSeq = dto.getEquipAuthSeq(); // MA1X78KH5202311071202015732
String pileConnectorCode = dto.getConnectorID();
// 先查询配置密钥相关信息
ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorID());
if (configInfo == null) {
return null;
}
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getHaiNanPlatformSecretInfo();
// 根据桩编号查询数据
// String merchantId = StringUtils.substring(equipAuthSeq, 0, 9);
// String pileSn = StringUtils.substring(pileConnectorCode, 0, 14);
@@ -628,13 +601,8 @@ public class HaiNanPlatformServiceImpl implements ThirdPartyPlatformService {
vo.setFailReason(2); // 设备检测失败
vo.setFailReasonMsg("未查到该桩的数据");
}
Map<String, String> resultMap = Maps.newLinkedHashMap();
// 加密数据
String encryptData = Cryptos.aesEncrypt(JSON.toJSONString(vo), configInfo.getDataSecret(), configInfo.getDataSecretIv());
resultMap.put("Data", encryptData);
// 生成sig
String resultSign = GBSignUtils.sign(resultMap, configInfo.getSignSecret());
resultMap.put("Sig", resultSign);
Map<String, String> resultMap = ThirdPartyPlatformUtils.generateResultMapV2(vo, thirdPartySecretInfoVO.getOurDataSecret(),
thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret());
return resultMap;
}
@@ -647,10 +615,8 @@ public class HaiNanPlatformServiceImpl implements ThirdPartyPlatformService {
public Map<String, String> queryEquipBusinessPolicy(QueryStartChargeDTO dto) {
List<EquipBusinessPolicyVO.PolicyInfo> policyInfoList = new ArrayList<>();
String pileConnectorCode = dto.getConnectorID();
ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorId());
if (configInfo == null) {
return null;
}
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getHaiNanPlatformSecretInfo();
// 截取桩号
// String pileSn = StringUtils.substring(pileConnectorCode, 0, 14);
String pileSn = YKCUtils.getPileSn(pileConnectorCode);
@@ -686,13 +652,8 @@ public class HaiNanPlatformServiceImpl implements ThirdPartyPlatformService {
.policyInfos(policyInfoList)
.build();
Map<String, String> resultMap = Maps.newLinkedHashMap();
// 加密数据
String encryptData = Cryptos.aesEncrypt(JSON.toJSONString(vo), configInfo.getDataSecret(), configInfo.getDataSecretIv());
resultMap.put("Data", encryptData);
// 生成sig
String resultSign = GBSignUtils.sign(resultMap, configInfo.getSignSecret());
resultMap.put("Sig", resultSign);
Map<String, String> resultMap = ThirdPartyPlatformUtils.generateResultMapV2(vo, thirdPartySecretInfoVO.getOurDataSecret(),
thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret());
return resultMap;
}
@@ -769,10 +730,7 @@ public class HaiNanPlatformServiceImpl implements ThirdPartyPlatformService {
// 平台已存在订单
return null;
}
ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorId());
if (configInfo == null) {
return null;
}
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getHaiNanPlatformSecretInfo();
// 生成订单
Map<String, Object> map = orderBasicInfoService.generateOrderForThirdParty(dto);
String orderCode = (String) map.get("orderCode");
@@ -805,13 +763,8 @@ public class HaiNanPlatformServiceImpl implements ThirdPartyPlatformService {
vo.setStartChargeSeqStat(1);
}
Map<String, String> resultMap = Maps.newLinkedHashMap();
// 加密数据
String encryptData = Cryptos.aesEncrypt(JSON.toJSONString(vo), configInfo.getDataSecret(), configInfo.getDataSecretIv());
resultMap.put("Data", encryptData);
// 生成sig
String resultSign = GBSignUtils.sign(resultMap, configInfo.getSignSecret());
resultMap.put("Sig", resultSign);
Map<String, String> resultMap = ThirdPartyPlatformUtils.generateResultMapV2(vo, thirdPartySecretInfoVO.getOurDataSecret(),
thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret());
return resultMap;
}
@@ -831,11 +784,7 @@ public class HaiNanPlatformServiceImpl implements ThirdPartyPlatformService {
if (orderInfo == null) {
return null;
}
ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(operatorID);
// logger.info(operatorName + "查询密钥信息 configInfo:{}", configInfo);
if (configInfo == null) {
return null;
}
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getHaiNanPlatformSecretInfo();
OrderDetail orderDetail = orderBasicInfoService.getOrderDetailByOrderCode(orderInfo.getOrderCode());
// 通过订单号查询实时数据
List<RealTimeMonitorData> realTimeData = orderBasicInfoService.getChargingRealTimeData(orderInfo.getTransactionCode());
@@ -884,13 +833,8 @@ public class HaiNanPlatformServiceImpl implements ThirdPartyPlatformService {
.build();
}
Map<String, String> resultMap = Maps.newLinkedHashMap();
// 加密数据
String encryptData = Cryptos.aesEncrypt(JSON.toJSONString(vo), configInfo.getDataSecret(), configInfo.getDataSecretIv());
resultMap.put("Data", encryptData);
// 生成sig
String resultSign = GBSignUtils.sign(resultMap, configInfo.getSignSecret());
resultMap.put("Sig", resultSign);
Map<String, String> resultMap = ThirdPartyPlatformUtils.generateResultMapV2(vo, thirdPartySecretInfoVO.getOurDataSecret(),
thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret());
return resultMap;
}
@@ -931,9 +875,9 @@ public class HaiNanPlatformServiceImpl implements ThirdPartyPlatformService {
}
String data = map.get("Data");
// 解密data (此处解密需用 thirdparty_platform_config 的密钥配置)
ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(operatorIdByType);
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getHaiNanPlatformSecretInfo();
byte[] plainText = Cryptos.aesDecrypt(Encodes.decodeBase64(data),
configInfo.getDataSecret().getBytes(), configInfo.getDataSecretIv().getBytes());
thirdPartySecretInfoVO.getOurDataSecret().getBytes(), thirdPartySecretInfoVO.getOurDataSecretIv().getBytes());
String dataStr = new String(plainText, StandardCharsets.UTF_8);
// 转成对应的对象
QueryChargingStatusVO vo = JSONObject.parseObject(dataStr, QueryChargingStatusVO.class);
@@ -962,10 +906,8 @@ public class HaiNanPlatformServiceImpl implements ThirdPartyPlatformService {
if (orderInfo == null) {
return null;
}
ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorId());
if (configInfo == null) {
return null;
}
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getHaiNanPlatformSecretInfo();
// 若状态为充电中,则发送停机指令
if (StringUtils.equals(OrderStatusEnum.IN_THE_CHARGING.getValue(), orderInfo.getOrderStatus())) {
// 充电中
@@ -986,13 +928,8 @@ public class HaiNanPlatformServiceImpl implements ThirdPartyPlatformService {
// 如果是新电途平台,则将 startChargeSeqStat 改为 3-停止中
vo.setStartChargeSeqStat(3);
}
Map<String, String> resultMap = Maps.newLinkedHashMap();
// 加密数据
String encryptData = Cryptos.aesEncrypt(JSON.toJSONString(vo), configInfo.getDataSecret(), configInfo.getDataSecretIv());
resultMap.put("Data", encryptData);
// 生成sig
String resultSign = GBSignUtils.sign(resultMap, configInfo.getSignSecret());
resultMap.put("Sig", resultSign);
Map<String, String> resultMap = ThirdPartyPlatformUtils.generateResultMapV2(vo, thirdPartySecretInfoVO.getOurDataSecret(),
thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret());
return resultMap;
}
@@ -1042,5 +979,18 @@ public class HaiNanPlatformServiceImpl implements ThirdPartyPlatformService {
return result;
}
/**
* 获取海南省平台配置密钥信息
*
* @return
*/
private ThirdPartySecretInfoVO getHaiNanPlatformSecretInfo() {
// 通过第三方平台类型查询相关配置信息
ThirdPartySecretInfoVO thirdPartySecretInfoVO = thirdpartySecretInfoService.queryByThirdPlatformType(ThirdPlatformTypeEnum.HAI_NAN_1_PLATFORM.getTypeCode());
if (thirdPartySecretInfoVO == null) {
throw new BusinessException(ReturnCodeEnum.CODE_SELECT_INFO_IS_NULL);
}
thirdPartySecretInfoVO.setOurOperatorId(Constants.OPERATORID_JIANG_SU);
return thirdPartySecretInfoVO;
}
}

View File

@@ -16,6 +16,7 @@ import com.jsowell.common.enums.thirdparty.ThirdPlatformTypeEnum;
import com.jsowell.common.enums.ykc.OrderPayModeEnum;
import com.jsowell.common.enums.ykc.OrderStatusEnum;
import com.jsowell.common.enums.ykc.PileConnectorDataBaseStatusEnum;
import com.jsowell.common.enums.ykc.ReturnCodeEnum;
import com.jsowell.common.exception.BusinessException;
import com.jsowell.common.util.*;
import com.jsowell.pile.domain.*;
@@ -86,12 +87,6 @@ public class LianLianPlatformServiceImpl implements ThirdPartyPlatformService {
@Autowired
private OrderBasicInfoService orderBasicInfoService;
@Autowired
private ThirdPartyPlatformConfigService thirdPartyPlatformConfigService;
@Autowired
private ThirdPartySettingInfoService thirdPartySettingInfoService;
@Resource
private ThirdPartyStationRelationService thirdPartyStationRelationService;
@@ -201,10 +196,8 @@ public class LianLianPlatformServiceImpl implements ThirdPartyPlatformService {
// 未查到数据
return null;
}
ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorId());
if (configInfo == null) {
return null;
}
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getLianLianPlatformSecretInfo();
PageInfo<ThirdPartyStationInfoVO> pageInfo = new PageInfo<>(stationInfos);
List<StationInfo> resultList = new ArrayList<>();
for (ThirdPartyStationInfoVO pileStationInfo : pageInfo.getList()) {
@@ -256,13 +249,8 @@ public class LianLianPlatformServiceImpl implements ThirdPartyPlatformService {
map.put("ItemSize", resultList.size());
map.put("StationInfos", resultList);
Map<String, String> resultMap = Maps.newLinkedHashMap();
// 加密数据
String encryptData = Cryptos.aesEncrypt(JSON.toJSONString(map), configInfo.getDataSecret(), configInfo.getDataSecretIv());
resultMap.put("Data", encryptData);
// 生成sig
String resultSign = GBSignUtils.sign(resultMap, configInfo.getSignSecret());
resultMap.put("Sig", resultSign);
Map<String, String> resultMap = ThirdPartyPlatformUtils.generateResultMapV2(map, thirdPartySecretInfoVO.getOurDataSecret(),
thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret());
return resultMap;
}
@@ -277,10 +265,8 @@ public class LianLianPlatformServiceImpl implements ThirdPartyPlatformService {
List<String> stationIds = dto.getStationIds();
List<StationStatusInfo> StationStatusInfos = new ArrayList<>();
List<Object> ConnectorStatusInfos = new ArrayList<>();
ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorId());
if (configInfo == null) {
return null;
}
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getLianLianPlatformSecretInfo();
ConnectorStatusInfo connectorStatusInfo;
for (String stationId : stationIds) {
StationStatusInfo stationStatusInfo = new StationStatusInfo();
@@ -343,13 +329,8 @@ public class LianLianPlatformServiceImpl implements ThirdPartyPlatformService {
map.put("Total", total);
map.put("StationStatusInfos", collect);
Map<String, String> resultMap = Maps.newLinkedHashMap();
// 加密数据
String encryptData = Cryptos.aesEncrypt(JSON.toJSONString(map), configInfo.getDataSecret(), configInfo.getDataSecretIv());
resultMap.put("Data", encryptData);
// 生成sig
String resultSign = GBSignUtils.sign(resultMap, configInfo.getSignSecret());
resultMap.put("Sig", resultSign);
Map<String, String> resultMap = ThirdPartyPlatformUtils.generateResultMapV2(map, thirdPartySecretInfoVO.getOurDataSecret(),
thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret());
return resultMap;
}
@@ -361,10 +342,8 @@ public class LianLianPlatformServiceImpl implements ThirdPartyPlatformService {
*/
@Override
public Map<String, String> queryStationStats(QueryStationInfoDTO dto) {
ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorId());
if (configInfo == null) {
return null;
}
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getLianLianPlatformSecretInfo();
// 根据站点id 查出这段时间的充电量
List<AccumulativeInfoVO> list = orderBasicInfoService.getAccumulativeInfoForLianLian(dto);
if (CollectionUtils.isEmpty(list)) {
@@ -437,13 +416,8 @@ public class LianLianPlatformServiceImpl implements ThirdPartyPlatformService {
Map<String, Object> map = new LinkedHashMap<>();
map.put("StationStats", stationStatsInfo);
Map<String, String> resultMap = Maps.newLinkedHashMap();
// 加密数据
String encryptData = Cryptos.aesEncrypt(JSON.toJSONString(map), configInfo.getDataSecret(), configInfo.getDataSecretIv());
resultMap.put("Data", encryptData);
// 生成sig
String resultSign = GBSignUtils.sign(resultMap, configInfo.getSignSecret());
resultMap.put("Sig", resultSign);
Map<String, String> resultMap = ThirdPartyPlatformUtils.generateResultMapV2(map, thirdPartySecretInfoVO.getOurDataSecret(),
thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret());
return resultMap;
}
@@ -462,14 +436,14 @@ public class LianLianPlatformServiceImpl implements ThirdPartyPlatformService {
// 通过第三方配置类型查询相关配置信息
ThirdPartySettingInfo settingInfo = new ThirdPartySettingInfo();
settingInfo.setType(thirdPlatformType);
ThirdPartySettingInfo thirdPartySettingInfo = thirdPartySettingInfoService.selectSettingInfo(settingInfo);
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getLianLianPlatformSecretInfo();
String operatorId = thirdPartySettingInfo.getOperatorId();
String operatorSecret = thirdPartySettingInfo.getOperatorSecret();
String signSecret = thirdPartySettingInfo.getSignSecret();
String dataSecret = thirdPartySettingInfo.getDataSecret();
String dataSecretIv = thirdPartySettingInfo.getDataSecretIv();
String urlAddress = thirdPartySettingInfo.getUrlAddress();
String operatorId = thirdPartySecretInfoVO.getTheirOperatorId();
String operatorSecret = thirdPartySecretInfoVO.getTheirOperatorSecret();
String signSecret = thirdPartySecretInfoVO.getTheirSigSecret();
String dataSecret = thirdPartySecretInfoVO.getTheirDataSecret();
String dataSecretIv = thirdPartySecretInfoVO.getTheirDataSecretIv();
String urlAddress = thirdPartySecretInfoVO.getTheirUrlPrefix();
// 组装联联平台所需要的数据格式
StationInfo info = StationInfo.builder()
@@ -1103,10 +1077,8 @@ public class LianLianPlatformServiceImpl implements ThirdPartyPlatformService {
return null;
}
// 通过operatorID 查出 operatorSecret
ThirdPartyPlatformConfig platformConfig = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorId());
if (platformConfig == null) {
return null;
}
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getLianLianPlatformSecretInfo();
// orderInfo 和 orderDetail 都不为空,再根据传过来的数据进行修改数据库信息
confirmResult = Constants.zero;
orderDetail.setTotalUsedElectricity(dto.getTotalPower()); // 累计充电量
@@ -1116,10 +1088,10 @@ public class LianLianPlatformServiceImpl implements ThirdPartyPlatformService {
Map<String, String> resultMap = Maps.newLinkedHashMap();
// 加密数据
String encrypt = Cryptos.encrypt(JSON.toJSONString(map), platformConfig.getDataSecret(), platformConfig.getDataSecretIv());
String encrypt = Cryptos.encrypt(JSON.toJSONString(map), thirdPartySecretInfoVO.getOurDataSecret(), thirdPartySecretInfoVO.getOurDataSecretIv());
resultMap.put("Data", encrypt);
// 生成sig
String resultSign = GBSignUtils.sign(resultMap, platformConfig.getSignSecret());
String resultSign = GBSignUtils.sign(resultMap, thirdPartySecretInfoVO.getOurSigSecret());
resultMap.put("Sig", resultSign);
return resultMap;
}
@@ -1132,16 +1104,13 @@ public class LianLianPlatformServiceImpl implements ThirdPartyPlatformService {
*/
@Override
public Map<String, String> queryEquipAuth(QueryEquipmentDTO dto) {
Map<String, String> resultMap = Maps.newLinkedHashMap();
EquipmentAuthVO vo = new EquipmentAuthVO();
String equipAuthSeq = dto.getEquipAuthSeq(); // MA1X78KH5202311071202015732
String pileConnectorCode = ThirdPartyPlatformUtils.extractConnectorID(dto.getConnectorID());
// 先查询配置密钥相关信息
ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorID());
if (configInfo == null) {
return null;
}
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getLianLianPlatformSecretInfo();
// 根据桩编号查询数据
// String merchantId = StringUtils.substring(equipAuthSeq, 0, 9);
// String pileSn = StringUtils.substring(pileConnectorCode, 0, 14);
@@ -1176,15 +1145,8 @@ public class LianLianPlatformServiceImpl implements ThirdPartyPlatformService {
vo.setFailReason(failReason); // 设备检测失败
vo.setFailReasonMsg(failReasonMsg);
// 加密数据
byte[] encryptText = Cryptos.aesEncrypt(JSON.toJSONString(vo).getBytes(),
configInfo.getDataSecret().getBytes(), configInfo.getDataSecretIv().getBytes());
String encryptData = Encodes.encodeBase64(encryptText);
resultMap.put("Data", encryptData);
// 生成sig
String resultSign = GBSignUtils.sign(resultMap, configInfo.getSignSecret());
resultMap.put("Sig", resultSign);
Map<String, String> resultMap = ThirdPartyPlatformUtils.generateResultMapV2(vo, thirdPartySecretInfoVO.getOurDataSecret(),
thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret());
return resultMap;
}
@@ -1281,10 +1243,8 @@ public class LianLianPlatformServiceImpl implements ThirdPartyPlatformService {
if (orderInfo == null) {
return null;
}
ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorId());
if (configInfo == null) {
return null;
}
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getLianLianPlatformSecretInfo();
// 若状态为充电中,则发送停机指令
if (StringUtils.equals(OrderStatusEnum.IN_THE_CHARGING.getValue(), orderInfo.getOrderStatus())) {
// 充电中
@@ -1306,17 +1266,8 @@ public class LianLianPlatformServiceImpl implements ThirdPartyPlatformService {
vo.setStartChargeSeqStat(3);
}
// 加密
Map<String, String> resultMap = Maps.newLinkedHashMap();
// 加密数据
byte[] encryptText = Cryptos.aesEncrypt(JSON.toJSONString(vo).getBytes(),
configInfo.getDataSecret().getBytes(), configInfo.getDataSecretIv().getBytes());
String encryptData = Encodes.encodeBase64(encryptText);
resultMap.put("Data", encryptData);
// 生成sig
String resultSign = GBSignUtils.sign(resultMap, configInfo.getSignSecret());
resultMap.put("Sig", resultSign);
Map<String, String> resultMap = ThirdPartyPlatformUtils.generateResultMapV2(vo, thirdPartySecretInfoVO.getOurDataSecret(),
thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret());
return resultMap;
}
@@ -1336,11 +1287,8 @@ public class LianLianPlatformServiceImpl implements ThirdPartyPlatformService {
if (orderInfo == null) {
return null;
}
ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(operatorID);
// logger.info(operatorName + "查询密钥信息 configInfo:{}", configInfo);
if (configInfo == null) {
return null;
}
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getLianLianPlatformSecretInfo();
OrderDetail orderDetail = orderBasicInfoService.getOrderDetailByOrderCode(orderInfo.getOrderCode());
// 通过订单号查询实时数据
List<RealTimeMonitorData> realTimeData = orderBasicInfoService.getChargingRealTimeData(orderInfo.getTransactionCode());
@@ -1391,18 +1339,23 @@ public class LianLianPlatformServiceImpl implements ThirdPartyPlatformService {
}
// 加密
Map<String, String> resultMap = Maps.newLinkedHashMap();
// 加密数据
byte[] encryptText = Cryptos.aesEncrypt(JSON.toJSONString(vo).getBytes(),
configInfo.getDataSecret().getBytes(), configInfo.getDataSecretIv().getBytes());
String encryptData = Encodes.encodeBase64(encryptText);
resultMap.put("Data", encryptData);
// 生成sig
String resultSign = GBSignUtils.sign(resultMap, configInfo.getSignSecret());
resultMap.put("Sig", resultSign);
Map<String, String> resultMap = ThirdPartyPlatformUtils.generateResultMapV2(vo, thirdPartySecretInfoVO.getOurDataSecret(),
thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret());
return resultMap;
}
/**
* 获取联联平台配置密钥信息
*
* @return
*/
private ThirdPartySecretInfoVO getLianLianPlatformSecretInfo() {
// 通过第三方平台类型查询相关配置信息
ThirdPartySecretInfoVO thirdPartySecretInfoVO = thirdpartySecretInfoService.queryByThirdPlatformType(ThirdPlatformTypeEnum.LIAN_LIAN_PLATFORM.getTypeCode());
if (thirdPartySecretInfoVO == null) {
throw new BusinessException(ReturnCodeEnum.CODE_SELECT_INFO_IS_NULL);
}
thirdPartySecretInfoVO.setOurOperatorId(Constants.OPERATORID_JIANG_SU);
return thirdPartySecretInfoVO;
}
}

View File

@@ -127,7 +127,7 @@ public class NeiMengGuPlatformServiceImpl implements ThirdPartyPlatformService {
String operatorId = dto.getPlatformID();
// 通过operatorId 查出 operatorSecret
ThirdPartySecretInfoVO thirdPartySecretInfoVO = thirdpartySecretInfoService.queryByOperatorId(operatorId);
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getNeiMengGuPlatformSecretInfo();
if (thirdPartySecretInfoVO == null) {
failReason = 1;
succStat = 1;
@@ -187,7 +187,7 @@ public class NeiMengGuPlatformServiceImpl implements ThirdPartyPlatformService {
operatorInfos.add(supOperatorInfo);
}
}
ThirdPartySecretInfoVO thirdPartySecretInfoVO = thirdpartySecretInfoService.queryByThirdPlatformType(thirdPlatformType);
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getNeiMengGuPlatformSecretInfo();
// 组装结果集
Map<String, Object> map = Maps.newHashMap();
@@ -225,10 +225,8 @@ public class NeiMengGuPlatformServiceImpl implements ThirdPartyPlatformService {
// 未查到数据
return null;
}
ThirdPartySecretInfoVO thirdPartySecretInfoVO = thirdpartySecretInfoService.queryByThirdPlatformType(thirdPlatformType);
if (thirdPartySecretInfoVO == null) {
return null;
}
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getNeiMengGuPlatformSecretInfo();
PageInfo<ThirdPartyStationInfoVO> pageInfo = new PageInfo<>(stationInfos);
List<SupStationInfo> resultList = new ArrayList<>();
for (ThirdPartyStationInfoVO pileStationInfo : pageInfo.getList()) {
@@ -346,10 +344,8 @@ public class NeiMengGuPlatformServiceImpl implements ThirdPartyPlatformService {
List<String> stationIds = dto.getStationIds();
List<StationStatusInfo> StationStatusInfos = new ArrayList<>();
List<Object> connectorStatusInfos = new ArrayList<>();
ThirdPartySecretInfoVO thirdPartySecretInfoVO = thirdpartySecretInfoService.queryByThirdPlatformType(thirdPlatformType);
if (thirdPartySecretInfoVO == null) {
return null;
}
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getNeiMengGuPlatformSecretInfo();
ConnectorStatusInfo connectorStatusInfo;
for (String stationId : stationIds) {
StationStatusInfo stationStatusInfo = new StationStatusInfo();
@@ -417,10 +413,8 @@ public class NeiMengGuPlatformServiceImpl implements ThirdPartyPlatformService {
public Map<String, String> queryStationStatus(QueryStationInfoDTO dto) {
List<String> stationIds = dto.getStationIds();
List<SupStationStatusInfo> stationStatusInfos = Lists.newArrayList();
ThirdPartySecretInfoVO thirdPartySecretInfoVO = thirdpartySecretInfoService.queryByThirdPlatformType(thirdPlatformType);
if (thirdPartySecretInfoVO == null) {
return null;
}
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getNeiMengGuPlatformSecretInfo();
for (String stationId : stationIds) {
// 查询站点的运营商信息
PileMerchantInfoVO pileMerchantInfoVO = pileMerchantInfoService.queryMerchantInfoByStationId(stationId);
@@ -482,17 +476,15 @@ public class NeiMengGuPlatformServiceImpl implements ThirdPartyPlatformService {
// String pileSn = StringUtils.substring(pileConnectorCode, 0, 14);
String pileSn = YKCUtils.getPileSn(pileConnectorCode);
PileStationVO stationVO = pileStationInfoService.getStationInfoByPileSn(pileSn);
// 通过站点id查询相关配置信息
ThirdPartyStationRelationVO relationInfo = thirdPartyStationRelationService.selectRelationInfo(stationVO.getId());
if (relationInfo == null) {
return null;
}
String operatorId = relationInfo.getOperatorId();
String operatorSecret = relationInfo.getOperatorSecret();
String signSecret = relationInfo.getSignSecret();
String dataSecret = relationInfo.getDataSecret();
String dataSecretIv = relationInfo.getDataSecretIv();
String urlAddress = relationInfo.getUrlAddress();
// 查询相关配置信息
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getNeiMengGuPlatformSecretInfo();
String operatorId = thirdPartySecretInfoVO.getTheirOperatorId();
String operatorSecret = thirdPartySecretInfoVO.getTheirOperatorSecret();
String signSecret = thirdPartySecretInfoVO.getTheirSigSecret();
String dataSecret = thirdPartySecretInfoVO.getTheirDataSecret();
String dataSecretIv = thirdPartySecretInfoVO.getTheirDataSecretIv();
String urlAddress = thirdPartySecretInfoVO.getTheirUrlPrefix();
String url = urlAddress + BusinessInformationExchangeEnum.NOTIFICATION_STATION_STATUS.getValue();
ConnectorStatusInfo info = ConnectorStatusInfo.builder()
@@ -571,18 +563,15 @@ public class NeiMengGuPlatformServiceImpl implements ThirdPartyPlatformService {
return null;
}
// 通过站点id查询相关配置信息
ThirdPartyStationRelationVO relationInfo = thirdPartyStationRelationService.selectRelationInfo(orderBasicInfo.getStationId());
if (relationInfo == null) {
return null;
}
// 查询相关配置信息
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getNeiMengGuPlatformSecretInfo();
String operatorId = relationInfo.getOperatorId();
String operatorSecret = relationInfo.getOperatorSecret();
String signSecret = relationInfo.getSignSecret();
String dataSecret = relationInfo.getDataSecret();
String dataSecretIv = relationInfo.getDataSecretIv();
String urlAddress = relationInfo.getUrlAddress();
String operatorId = thirdPartySecretInfoVO.getTheirOperatorId();
String operatorSecret = thirdPartySecretInfoVO.getTheirOperatorSecret();
String signSecret = thirdPartySecretInfoVO.getTheirSigSecret();
String dataSecret = thirdPartySecretInfoVO.getTheirDataSecret();
String dataSecretIv = thirdPartySecretInfoVO.getTheirDataSecretIv();
String urlAddress = thirdPartySecretInfoVO.getTheirUrlPrefix();
// 根据订单号查询订单详情
OrderDetail orderDetail = orderBasicInfoService.getOrderDetailByOrderCode(orderCode);
@@ -696,38 +685,28 @@ public class NeiMengGuPlatformServiceImpl implements ThirdPartyPlatformService {
public String notificationEquipChargeStatus(String orderCode) {
// 根据订单号查询订单信息
OrderBasicInfo orderInfo = orderBasicInfoService.getOrderInfoByOrderCode(orderCode);
// 通过第三方平台类型查询相关配置信息
ThirdPartyStationRelation relation = new ThirdPartyStationRelation();
relation.setThirdPartyType(orderInfo.getThirdPartyType());
ThirdPartyStationRelationVO relationInfo = thirdPartyStationRelationService.selectRelationInfo(relation);
// ThirdPartySettingInfo settingInfo = thirdPartySettingInfoService.getInfoByStationId(Long.parseLong(orderInfo.getStationId()));
if (relationInfo == null) {
return null;
}
String operatorId = relationInfo.getOperatorId();
String operatorSecret = relationInfo.getOperatorSecret();
String signSecret = relationInfo.getSignSecret();
String dataSecret = relationInfo.getDataSecret();
String dataSecretIv = relationInfo.getDataSecretIv();
String urlAddress = relationInfo.getUrlAddress();
String thirdPartyType = relationInfo.getThirdPartyType();
// 查询相关配置信息
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getNeiMengGuPlatformSecretInfo();
String operatorId = thirdPartySecretInfoVO.getTheirOperatorId();
String operatorSecret = thirdPartySecretInfoVO.getTheirOperatorSecret();
String signSecret = thirdPartySecretInfoVO.getTheirSigSecret();
String dataSecret = thirdPartySecretInfoVO.getTheirDataSecret();
String dataSecretIv = thirdPartySecretInfoVO.getTheirDataSecretIv();
String urlAddress = thirdPartySecretInfoVO.getTheirUrlPrefix();
// 调用 查询充电状态方法
QueryEquipChargeStatusDTO dto = new QueryEquipChargeStatusDTO();
dto.setStartChargeSeq(orderCode);
// 根据type获取operatorId
String operatorIdByType = ThirdPartyOperatorIdEnum.getOperatorIdByType(thirdPartyType);
dto.setOperatorID(operatorIdByType);
dto.setOperatorID(thirdPartySecretInfoVO.getTheirOperatorId());
Map<String, String> map = queryEquipChargeStatus(dto);
if (map == null) {
return null;
}
String data = map.get("Data");
// 解密data (此处解密需用 thirdparty_platform_config 的密钥配置)
ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(operatorIdByType);
ThirdPartySecretInfoVO thirdPartySecretInfoVO = thirdpartySecretInfoService.queryByThirdPlatformType(thirdPlatformType);
byte[] plainText = Cryptos.aesDecrypt(Encodes.decodeBase64(data),
configInfo.getDataSecret().getBytes(), configInfo.getDataSecretIv().getBytes());
thirdPartySecretInfoVO.getOurDataSecret().getBytes(), thirdPartySecretInfoVO.getOurDataSecretIv().getBytes());
String dataStr = new String(plainText, StandardCharsets.UTF_8);
// 转成对应的对象
QueryChargingStatusVO vo = JSONObject.parseObject(dataStr, QueryChargingStatusVO.class);
@@ -763,20 +742,17 @@ public class NeiMengGuPlatformServiceImpl implements ThirdPartyPlatformService {
public String notificationChargeOrderInfoHistory(String orderCode) {
// 根据订单号查询出信息
OrderBasicInfo orderBasicInfo = orderBasicInfoService.getOrderInfoByOrderCode(orderCode);
// 通过站点id查询相关配置信息
ThirdPartyStationRelationVO relationInfo = thirdPartyStationRelationService.selectRelationInfo(orderBasicInfo.getStationId());
if (relationInfo == null) {
return null;
}
OrderDetail orderDetail = orderBasicInfoService.getOrderDetailByOrderCode(orderCode);
String operatorId = relationInfo.getOperatorId();
String operatorSecret = relationInfo.getOperatorSecret();
String signSecret = relationInfo.getSignSecret();
String dataSecret = relationInfo.getDataSecret();
String dataSecretIv = relationInfo.getDataSecretIv();
String urlAddress = relationInfo.getUrlAddress();
// 查询相关配置信息
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getNeiMengGuPlatformSecretInfo();
String operatorId = thirdPartySecretInfoVO.getTheirOperatorId();
String operatorSecret = thirdPartySecretInfoVO.getTheirOperatorSecret();
String signSecret = thirdPartySecretInfoVO.getTheirSigSecret();
String dataSecret = thirdPartySecretInfoVO.getTheirDataSecret();
String dataSecretIv = thirdPartySecretInfoVO.getTheirDataSecretIv();
String urlAddress = thirdPartySecretInfoVO.getTheirUrlPrefix();
String url = urlAddress + "supervise_notification_charge_order_info_history";
@@ -898,5 +874,19 @@ public class NeiMengGuPlatformServiceImpl implements ThirdPartyPlatformService {
return resultList;
}
/**
* 获取内蒙古平台配置密钥信息
*
* @return
*/
private ThirdPartySecretInfoVO getNeiMengGuPlatformSecretInfo() {
// 通过第三方平台类型查询相关配置信息
ThirdPartySecretInfoVO thirdPartySecretInfoVO = thirdpartySecretInfoService.queryByThirdPlatformType(ThirdPlatformTypeEnum.NEI_MENG_GU_PLATFORM.getTypeCode());
if (thirdPartySecretInfoVO == null) {
throw new BusinessException(ReturnCodeEnum.CODE_SELECT_INFO_IS_NULL);
}
thirdPartySecretInfoVO.setOurOperatorId(Constants.OPERATORID_JIANG_SU);
return thirdPartySecretInfoVO;
}
}

View File

@@ -6,6 +6,7 @@ import com.github.pagehelper.PageInfo;
import com.google.common.collect.Maps;
import com.jsowell.common.constant.Constants;
import com.jsowell.common.core.domain.ykc.RealTimeMonitorData;
import com.jsowell.common.core.redis.RedisCache;
import com.jsowell.common.enums.thirdparty.BusinessInformationExchangeEnum;
import com.jsowell.common.enums.thirdparty.ThirdPlatformTypeEnum;
import com.jsowell.common.enums.ykc.OrderStatusEnum;
@@ -21,6 +22,7 @@ import com.jsowell.pile.service.*;
import com.jsowell.pile.thirdparty.CommonParamsDTO;
import com.jsowell.pile.thirdparty.ZDLEquipmentInfo;
import com.jsowell.pile.thirdparty.ZDLStationInfo;
import com.jsowell.pile.vo.ThirdPartySecretInfoVO;
import com.jsowell.pile.vo.base.ThirdPartyStationInfoVO;
import com.jsowell.pile.vo.base.ThirdPartyStationRelationVO;
import com.jsowell.pile.vo.uniapp.customer.BillingPriceVO;
@@ -50,6 +52,7 @@ import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
/**
@@ -86,7 +89,7 @@ public class QingHaiPlatformServiceImpl implements ThirdPartyPlatformService {
private PileMerchantInfoService pileMerchantInfoService;
@Autowired
private ThirdPartyPlatformConfigService thirdPartyPlatformConfigService;
private RedisCache redisCache;
Logger logger = LoggerFactory.getLogger(QingHaiPlatformServiceImpl.class);
@@ -111,55 +114,56 @@ public class QingHaiPlatformServiceImpl implements ThirdPartyPlatformService {
*/
@Override
public Map<String, String> queryToken(CommonParamsDTO dto) {
AccessTokenVO vo = new AccessTokenVO();
// 0:成功1:失败
int succStat = 0;
// 0:无1:无此对接平台2:密钥错误; 399:自定义
int failReason = 0;
String operatorId = dto.getOperatorID();
// token缓存key值
String redisKey = operatorId + "_token:";
// 通过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 = getQingHaiPlatformSecretInfo();
if (thirdPartySecretInfoVO == null) {
failReason = 1;
succStat = 1;
} else {
String ourOperatorSecret = thirdPartySecretInfoVO.getOurOperatorSecret();
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("密钥不一致");
// 对比密钥
if (!StringUtils.equals(ourOperatorSecret, inputOperatorSecret)) {
failReason = 1;
succStat = 1;
} else {
// 先查缓存中是否有已生成的token
String token = redisCache.getCacheObject(redisKey);
int expiredTime = (int) redisCache.getExpire(redisKey);
if (StringUtils.isBlank(token)) {
// 生成token
token = JWTUtils.createToken(operatorId, ourOperatorSecret, JWTUtils.ttlMillis);
expiredTime = (int) (JWTUtils.ttlMillis / 1000);
}
vo.setAccessToken(token);
vo.setTokenAvailableTime(expiredTime);
// 设置缓存
redisCache.setCacheObject(redisKey, token, expiredTime, TimeUnit.SECONDS);
}
} 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);
vo.setFailReason(failReason);
vo.setSuccStat(succStat);
Map<String, String> resultMap = ThirdPartyPlatformUtils.generateResultMapV2(vo, thirdPartySecretInfoVO.getOurDataSecret(),
thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret());
return resultMap;
}
@@ -279,9 +283,10 @@ public class QingHaiPlatformServiceImpl implements ThirdPartyPlatformService {
jsonObject.put("ItemSize", resultList.size());
jsonObject.put("StationInfos", resultList);
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getQingHaiPlatformSecretInfo();
// 加密
Map<String, String> resultMap = getResultMap(jsonObject);
Map<String, String> resultMap = ThirdPartyPlatformUtils.generateResultMapV2(jsonObject, thirdPartySecretInfoVO.getOurDataSecret(),
thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret());
return resultMap;
}
@@ -294,20 +299,17 @@ public class QingHaiPlatformServiceImpl implements ThirdPartyPlatformService {
*/
@Override
public String notificationStationStatus(PushRealTimeInfoDTO dto) {
String thirdPartyType = dto.getThirdPartyType();
String status = dto.getStatus();
String pileConnectorCode = dto.getPileConnectorCode();
ThirdPartyStationRelationVO settingInfo = getQingHaiSettingInfo();
if (settingInfo == null) {
return null;
}
String operatorId = settingInfo.getOperatorId();
String operatorSecret = settingInfo.getOperatorSecret();
String signSecret = settingInfo.getSignSecret();
String dataSecret = settingInfo.getDataSecret();
String dataSecretIv = settingInfo.getDataSecretIv();
String urlAddress = settingInfo.getUrlAddress();
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getQingHaiPlatformSecretInfo();
String operatorId = thirdPartySecretInfoVO.getTheirOperatorId();
String operatorSecret = thirdPartySecretInfoVO.getTheirOperatorSecret();
String signSecret = thirdPartySecretInfoVO.getTheirSigSecret();
String dataSecret = thirdPartySecretInfoVO.getTheirDataSecret();
String dataSecretIv = thirdPartySecretInfoVO.getTheirDataSecretIv();
String urlAddress = thirdPartySecretInfoVO.getTheirUrlPrefix();
String url = urlAddress + BusinessInformationExchangeEnum.NOTIFICATION_STATION_STATUS.getValue();
ConnectorStatusInfo info = ConnectorStatusInfo.builder()
.connectorID(pileConnectorCode)
@@ -331,16 +333,14 @@ public class QingHaiPlatformServiceImpl implements ThirdPartyPlatformService {
public String notificationEquipChargeStatus(String orderCode) {
// 根据订单号查询订单信息
OrderBasicInfo orderInfo = orderBasicInfoService.getOrderInfoByOrderCode(orderCode);
ThirdPartyStationRelationVO settingInfo = getQingHaiSettingInfo();
if (settingInfo == null) {
return null;
}
String operatorId = settingInfo.getOperatorId();
String operatorSecret = settingInfo.getOperatorSecret();
String signSecret = settingInfo.getSignSecret();
String dataSecret = settingInfo.getDataSecret();
String dataSecretIv = settingInfo.getDataSecretIv();
String urlAddress = settingInfo.getUrlAddress();
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getQingHaiPlatformSecretInfo();
String operatorId = thirdPartySecretInfoVO.getTheirOperatorId();
String operatorSecret = thirdPartySecretInfoVO.getTheirOperatorSecret();
String signSecret = thirdPartySecretInfoVO.getTheirSigSecret();
String dataSecret = thirdPartySecretInfoVO.getTheirDataSecret();
String dataSecretIv = thirdPartySecretInfoVO.getTheirDataSecretIv();
String urlAddress = thirdPartySecretInfoVO.getTheirUrlPrefix();
String url = urlAddress + "notification_equip_charge_status";
@@ -490,16 +490,14 @@ public class QingHaiPlatformServiceImpl implements ThirdPartyPlatformService {
list.add(supStationPowerInfo);
// 获取推送配置密钥信息
ThirdPartyStationRelationVO settingInfo = getQingHaiSettingInfo();
if (settingInfo == null) {
return null;
}
String operatorId = settingInfo.getOperatorId();
String operatorSecret = settingInfo.getOperatorSecret();
String signSecret = settingInfo.getSignSecret();
String dataSecret = settingInfo.getDataSecret();
String dataSecretIv = settingInfo.getDataSecretIv();
String urlAddress = settingInfo.getUrlAddress();
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getQingHaiPlatformSecretInfo();
String operatorId = thirdPartySecretInfoVO.getTheirOperatorId();
String operatorSecret = thirdPartySecretInfoVO.getTheirOperatorSecret();
String signSecret = thirdPartySecretInfoVO.getTheirSigSecret();
String dataSecret = thirdPartySecretInfoVO.getTheirDataSecret();
String dataSecretIv = thirdPartySecretInfoVO.getTheirDataSecretIv();
String urlAddress = thirdPartySecretInfoVO.getTheirUrlPrefix();
String url = urlAddress + "supervise_notification_realtime_power_info";
// 获取令牌
@@ -526,10 +524,8 @@ public class QingHaiPlatformServiceImpl implements ThirdPartyPlatformService {
public Map<String, String> queryEquipBusinessPolicy(QueryStartChargeDTO dto) {
List<EquipBusinessPolicyVO.PolicyInfo> policyInfoList = new ArrayList<>();
String pileConnectorCode = dto.getConnectorID();
ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorId());
if (configInfo == null) {
return null;
}
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getQingHaiPlatformSecretInfo();
// 截取桩号
// String pileSn = StringUtils.substring(pileConnectorCode, 0, 14);
String pileSn = YKCUtils.getPileSn(pileConnectorCode);
@@ -574,7 +570,8 @@ public class QingHaiPlatformServiceImpl implements ThirdPartyPlatformService {
jsonObject.put("PolicyInfos", policyInfoList);
// 加密
Map<String, String> resultMap = getResultMap(jsonObject);
Map<String, String> resultMap = ThirdPartyPlatformUtils.generateResultMapV2(jsonObject, thirdPartySecretInfoVO.getOurDataSecret(),
thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret());
return resultMap;
}
@@ -633,16 +630,14 @@ public class QingHaiPlatformServiceImpl implements ThirdPartyPlatformService {
}
// 获取推送配置密钥信息
ThirdPartyStationRelationVO settingInfo = getQingHaiSettingInfo();
if (settingInfo == null) {
return null;
}
String operatorId = settingInfo.getOperatorId();
String operatorSecret = settingInfo.getOperatorSecret();
String signSecret = settingInfo.getSignSecret();
String dataSecret = settingInfo.getDataSecret();
String dataSecretIv = settingInfo.getDataSecretIv();
String urlAddress = settingInfo.getUrlAddress();
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getQingHaiPlatformSecretInfo();
String operatorId = thirdPartySecretInfoVO.getTheirOperatorId();
String operatorSecret = thirdPartySecretInfoVO.getTheirOperatorSecret();
String signSecret = thirdPartySecretInfoVO.getTheirSigSecret();
String dataSecret = thirdPartySecretInfoVO.getTheirDataSecret();
String dataSecretIv = thirdPartySecretInfoVO.getTheirDataSecretIv();
String urlAddress = thirdPartySecretInfoVO.getTheirUrlPrefix();
String url = urlAddress + "notification_charge_order_info";
// 获取令牌
@@ -657,42 +652,19 @@ public class QingHaiPlatformServiceImpl implements ThirdPartyPlatformService {
return result;
}
// 获取青海平台配置密钥信息
private ThirdPartyStationRelationVO getQingHaiSettingInfo() {
// 通过第三方平台类型查询相关配置信息
ThirdPartyStationRelation relation = new ThirdPartyStationRelation();
relation.setThirdPartyType(ThirdPlatformTypeEnum.QING_HAI_PLATFORM.getTypeCode());
ThirdPartyStationRelationVO relationInfo = thirdPartyStationRelationService.selectRelationInfo(relation);
return relationInfo;
}
/**
* 将需要发送至对接平台的的返回参数加密返回
* 获取青海省平台配置密钥信息
*
* @param jsonObject
* @return
*/
private Map<String, String> getResultMap(JSONObject jsonObject) {
String operatorId = ThirdPlatformTypeEnum.QING_HAI_PLATFORM.getOperatorId();
ThirdPartyPlatformConfig platformConfig = thirdPartyPlatformConfigService.getInfoByOperatorId(operatorId);
if (platformConfig == null) {
return null;
private ThirdPartySecretInfoVO getQingHaiPlatformSecretInfo() {
// 通过第三方平台类型查询相关配置信息
ThirdPartySecretInfoVO thirdPartySecretInfoVO = thirdpartySecretInfoService.queryByThirdPlatformType(ThirdPlatformTypeEnum.QING_HAI_PLATFORM.getTypeCode());
if (thirdPartySecretInfoVO == null) {
throw new BusinessException(ReturnCodeEnum.CODE_SELECT_INFO_IS_NULL);
}
Map<String, String> resultMap = Maps.newLinkedHashMap();
// 加密数据
byte[] encryptText = Cryptos.aesEncrypt(jsonObject.toJSONString().getBytes(),
platformConfig.getDataSecret().getBytes(), platformConfig.getDataSecretIv().getBytes());
String encryptData = Encodes.encodeBase64(encryptText);
resultMap.put("Ret", "0");
resultMap.put("Msg", "请求令牌成功!");
resultMap.put("Data", encryptData);
// 生成sig
String resultSign = GBSignUtils.sign(resultMap, platformConfig.getSignSecret());
resultMap.put("Sig", resultSign);
return resultMap;
thirdPartySecretInfoVO.setOurOperatorId(Constants.OPERATORID_JIANG_SU);
return thirdPartySecretInfoVO;
}
}

View File

@@ -313,16 +313,13 @@ public class XinDiantuPlatfromServiceImpl implements ThirdPartyPlatformService {
*/
@Override
public Map<String, String> queryEquipAuth(QueryEquipmentDTO dto) {
Map<String, String> resultMap = Maps.newLinkedHashMap();
EquipmentAuthVO vo = new EquipmentAuthVO();
String equipAuthSeq = dto.getEquipAuthSeq(); // MA1X78KH5202311071202015732
String pileConnectorCode = ThirdPartyPlatformUtils.extractConnectorID(dto.getConnectorID());
// 先查询配置密钥相关信息
ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorID());
if (configInfo == null) {
return null;
}
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getXinDiantuPlatformSecretInfo();
// 根据桩编号查询数据
// String merchantId = StringUtils.substring(equipAuthSeq, 0, 9);
// String pileSn = StringUtils.substring(pileConnectorCode, 0, 14);
@@ -356,16 +353,9 @@ public class XinDiantuPlatfromServiceImpl implements ThirdPartyPlatformService {
vo.setSuccStat(succStat);
vo.setFailReason(failReason); // 设备检测失败
vo.setFailReasonMsg(failReasonMsg);
// 加密数据
byte[] encryptText = Cryptos.aesEncrypt(JSON.toJSONString(vo).getBytes(),
configInfo.getDataSecret().getBytes(), configInfo.getDataSecretIv().getBytes());
String encryptData = Encodes.encodeBase64(encryptText);
resultMap.put("Data", encryptData);
// 生成sig
String resultSign = GBSignUtils.sign(resultMap, configInfo.getSignSecret());
resultMap.put("Sig", resultSign);
Map<String, String> resultMap = ThirdPartyPlatformUtils.generateResultMapV2(vo, thirdPartySecretInfoVO.getOurDataSecret(),
thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret());
return resultMap;
}

View File

@@ -73,9 +73,6 @@ public class YongChengbochePlatfromServiceImpl implements ThirdPartyPlatformServ
@Autowired
private PileMerchantInfoService pileMerchantInfoService;
@Autowired
private ThirdPartyPlatformConfigService thirdPartyPlatformConfigService;
@Autowired
private PileConnectorInfoService pileConnectorInfoService;
@@ -88,9 +85,6 @@ public class YongChengbochePlatfromServiceImpl implements ThirdPartyPlatformServ
@Autowired
private PileRemoteService pileRemoteService;
@Autowired
private ThirdPartyStationRelationService thirdPartyStationRelationService;
@Override
public void afterPropertiesSet() throws Exception {
ThirdPartyPlatformFactory.register(thirdPlatformType, this);
@@ -142,7 +136,8 @@ public class YongChengbochePlatfromServiceImpl implements ThirdPartyPlatformServ
vo.setFailReason(failReason);
vo.setSuccStat(succStat);
Map<String, String> resultMap = ThirdPartyPlatformUtils.generateResultMap(vo, thirdPartySecretInfoVO);
Map<String, String> resultMap = ThirdPartyPlatformUtils.generateResultMapV2(vo, thirdPartySecretInfoVO.getOurDataSecret(),
thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret());
return resultMap;
}
@@ -215,7 +210,8 @@ public class YongChengbochePlatfromServiceImpl implements ThirdPartyPlatformServ
map.put("PageCount", pageInfo.getPages());
map.put("ItemSize", pageInfo.getTotal());
map.put("StationInfos", resultList);
Map<String, String> resultMap = ThirdPartyPlatformUtils.generateResultMap(map, thirdPartySecretInfoVO);
Map<String, String> resultMap = ThirdPartyPlatformUtils.generateResultMapV2(map, thirdPartySecretInfoVO.getOurDataSecret(),
thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret());
return resultMap;
}
@@ -230,10 +226,8 @@ public class YongChengbochePlatfromServiceImpl implements ThirdPartyPlatformServ
List<String> stationIds = dto.getStationIds();
List<StationStatusInfo> StationStatusInfos = new ArrayList<>();
List<Object> ConnectorStatusInfos = new ArrayList<>();
ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorId());
if (configInfo == null) {
return null;
}
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getYongChengbochePlatformSecretInfo();
ConnectorStatusInfo connectorStatusInfo;
for (String stationId : stationIds) {
StationStatusInfo stationStatusInfo = new StationStatusInfo();
@@ -296,13 +290,8 @@ public class YongChengbochePlatfromServiceImpl implements ThirdPartyPlatformServ
map.put("Total", total);
map.put("StationStatusInfos", collect);
Map<String, String> resultMap = Maps.newLinkedHashMap();
// 加密数据
String encryptData = Cryptos.aesEncrypt(JSON.toJSONString(map), configInfo.getDataSecret(), configInfo.getDataSecretIv());
resultMap.put("Data", encryptData);
// 生成sig
String resultSign = GBSignUtils.sign(resultMap, configInfo.getSignSecret());
resultMap.put("Sig", resultSign);
Map<String, String> resultMap = ThirdPartyPlatformUtils.generateResultMapV2(map, thirdPartySecretInfoVO.getOurDataSecret(),
thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret());
return resultMap;
}
@@ -357,7 +346,7 @@ public class YongChengbochePlatfromServiceImpl implements ThirdPartyPlatformServ
public Map<String, String> queryEquipBusinessPolicy(QueryStartChargeDTO dto) {
List<EquipBusinessPolicyVO.PolicyInfo> policyInfoList = new ArrayList<>();
String pileConnectorCode = dto.getConnectorID();
ThirdPartySecretInfoVO yongChengbochePlatformSecretInfo = getYongChengbochePlatformSecretInfo();
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getYongChengbochePlatformSecretInfo();
// 截取桩号
// String pileSn = StringUtils.substring(pileConnectorCode, 0, 14);
@@ -394,7 +383,9 @@ public class YongChengbochePlatfromServiceImpl implements ThirdPartyPlatformServ
.policyInfos(policyInfoList)
.build();
return ThirdPartyPlatformUtils.generateResultMap(vo, yongChengbochePlatformSecretInfo);
Map<String, String> resultMap = ThirdPartyPlatformUtils.generateResultMapV2(vo, thirdPartySecretInfoVO.getOurDataSecret(),
thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret());
return resultMap;
}
/**
@@ -405,16 +396,12 @@ public class YongChengbochePlatfromServiceImpl implements ThirdPartyPlatformServ
*/
@Override
public Map<String, String> queryEquipAuth(QueryEquipmentDTO dto) {
Map<String, String> resultMap = Maps.newLinkedHashMap();
EquipmentAuthVO vo = new EquipmentAuthVO();
String equipAuthSeq = dto.getEquipAuthSeq(); // MA1X78KH5202311071202015732
String pileConnectorCode = ThirdPartyPlatformUtils.extractConnectorID(dto.getConnectorID());
// 先查询配置密钥相关信息
ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorID());
if (configInfo == null) {
return null;
}
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getYongChengbochePlatformSecretInfo();
// 根据桩编号查询数据
// String merchantId = StringUtils.substring(equipAuthSeq, 0, 9);
// String pileSn = StringUtils.substring(pileConnectorCode, 0, 14);
@@ -449,15 +436,8 @@ public class YongChengbochePlatfromServiceImpl implements ThirdPartyPlatformServ
vo.setFailReason(failReason); // 设备检测失败
vo.setFailReasonMsg(failReasonMsg);
// 加密数据
byte[] encryptText = Cryptos.aesEncrypt(JSON.toJSONString(vo).getBytes(),
configInfo.getDataSecret().getBytes(), configInfo.getDataSecretIv().getBytes());
String encryptData = Encodes.encodeBase64(encryptText);
resultMap.put("Data", encryptData);
// 生成sig
String resultSign = GBSignUtils.sign(resultMap, configInfo.getSignSecret());
resultMap.put("Sig", resultSign);
Map<String, String> resultMap = ThirdPartyPlatformUtils.generateResultMapV2(vo, thirdPartySecretInfoVO.getOurDataSecret(),
thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret());
return resultMap;
}
@@ -476,7 +456,7 @@ public class YongChengbochePlatfromServiceImpl implements ThirdPartyPlatformServ
// 平台已存在订单
return null;
}
ThirdPartySecretInfoVO yongChengbochePlatformSecretInfoVO = getYongChengbochePlatformSecretInfo();
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getYongChengbochePlatformSecretInfo();
// 生成订单
Map<String, Object> map = orderBasicInfoService.generateOrderForThirdParty(dto);
String orderCode = (String) map.get("orderCode");
@@ -503,7 +483,9 @@ public class YongChengbochePlatfromServiceImpl implements ThirdPartyPlatformServ
.failReason(0)
.build();
return ThirdPartyPlatformUtils.generateResultMap(vo, yongChengbochePlatformSecretInfoVO);
Map<String, String> resultMap = ThirdPartyPlatformUtils.generateResultMapV2(vo, thirdPartySecretInfoVO.getOurDataSecret(),
thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret());
return resultMap;
}
/**
@@ -560,7 +542,7 @@ public class YongChengbochePlatfromServiceImpl implements ThirdPartyPlatformServ
if (orderInfo == null) {
return null;
}
ThirdPartySecretInfoVO yongChengbochePlatformSecretInfoVO = getYongChengbochePlatformSecretInfo();
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getYongChengbochePlatformSecretInfo();
OrderDetail orderDetail = orderBasicInfoService.getOrderDetailByOrderCode(orderInfo.getOrderCode());
// 通过订单号查询实时数据
List<RealTimeMonitorData> realTimeData = orderBasicInfoService.getChargingRealTimeData(orderInfo.getTransactionCode());
@@ -609,7 +591,9 @@ public class YongChengbochePlatfromServiceImpl implements ThirdPartyPlatformServ
.build();
}
return ThirdPartyPlatformUtils.generateResultMap(vo, yongChengbochePlatformSecretInfoVO);
Map<String, String> resultMap = ThirdPartyPlatformUtils.generateResultMapV2(vo, thirdPartySecretInfoVO.getOurDataSecret(),
thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret());
return resultMap;
}
/**
@@ -687,7 +671,7 @@ public class YongChengbochePlatfromServiceImpl implements ThirdPartyPlatformServ
QueryStopChargeVO vo = new QueryStopChargeVO();
String orderCode = dto.getStartChargeSeq();
ThirdPartySecretInfoVO yongChengbochePlatformSecretInfo = getYongChengbochePlatformSecretInfo();
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getYongChengbochePlatformSecretInfo();
// 根据订单号查询订单信息
OrderBasicInfo orderInfo = orderBasicInfoService.getOrderInfoByOrderCode(orderCode);
if (orderInfo == null) {
@@ -703,7 +687,9 @@ public class YongChengbochePlatfromServiceImpl implements ThirdPartyPlatformServ
vo.setSuccStat(0);
vo.setFailReason(0);
return ThirdPartyPlatformUtils.generateResultMap(vo, yongChengbochePlatformSecretInfo);
Map<String, String> resultMap = ThirdPartyPlatformUtils.generateResultMapV2(vo, thirdPartySecretInfoVO.getOurDataSecret(),
thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret());
return resultMap;
}
/**

View File

@@ -26,13 +26,13 @@ public interface XDTService {
* @param dto
* @return
*/
Map<String, String> generateToken(CommonParamsDTO dto) throws UnsupportedEncodingException;
// Map<String, String> generateToken(CommonParamsDTO dto) throws UnsupportedEncodingException;
/**
* 校验签名
* @param dto
*/
Map<String, String> checkoutSign(CommonParamsDTO dto);
// Map<String, String> checkoutSign(CommonParamsDTO dto);
/**
* 查询站点信息

View File

@@ -55,15 +55,15 @@ public class XDTServiceImpl implements XDTService {
* @param dto
* @return
*/
@Override
public Map<String, String> generateToken(CommonParamsDTO dto) throws UnsupportedEncodingException {
return zdlService.generateToken(dto);
}
// @Override
// public Map<String, String> generateToken(CommonParamsDTO dto) throws UnsupportedEncodingException {
// return zdlService.generateToken(dto);
// }
@Override
public Map<String, String> checkoutSign(CommonParamsDTO dto) {
return zdlService.checkoutSign(dto);
}
// @Override
// public Map<String, String> checkoutSign(CommonParamsDTO dto) {
// return zdlService.checkoutSign(dto);
// }
/**
* 查询站点信息

View File

@@ -26,7 +26,7 @@ public interface YCBCService {
* @param dto
* @return
*/
Map<String, String> generateToken(CommonParamsDTO dto) throws UnsupportedEncodingException;
// Map<String, String> generateToken(CommonParamsDTO dto) throws UnsupportedEncodingException;
/**
* 查询站点信息

View File

@@ -143,10 +143,10 @@ public class YCBCServiceImpl implements YCBCService {
* @return
* @throws UnsupportedEncodingException
*/
@Override
public Map<String, String> generateToken(CommonParamsDTO dto) throws UnsupportedEncodingException {
return zdlService.generateToken(dto);
}
// @Override
// public Map<String, String> generateToken(CommonParamsDTO dto) throws UnsupportedEncodingException {
// return zdlService.generateToken(dto);
// }
/**
* 获取充电站信息

View File

@@ -74,7 +74,7 @@ public interface ZDLService {
* @param dto
* @return
*/
Map<String, String> generateToken(CommonParamsDTO dto) throws UnsupportedEncodingException;
// Map<String, String> generateToken(CommonParamsDTO dto) throws UnsupportedEncodingException;
/**
* 请求设备认证
@@ -134,5 +134,5 @@ public interface ZDLService {
* 校验签名
* @param dto
*/
Map<String, String> checkoutSign(CommonParamsDTO dto);
// Map<String, String> checkoutSign(CommonParamsDTO dto);
}

View File

@@ -7,12 +7,15 @@ import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.jsowell.common.constant.Constants;
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.PageUtils;
import com.jsowell.common.util.StringUtils;
import com.jsowell.common.util.YKCUtils;
import com.jsowell.pile.domain.*;
import com.jsowell.pile.dto.*;
import com.jsowell.pile.service.*;
import com.jsowell.pile.vo.ThirdPartySecretInfoVO;
import com.jsowell.pile.vo.base.MerchantInfoVO;
import com.jsowell.pile.vo.base.ThirdPartyStationInfoVO;
import com.jsowell.pile.vo.base.ThirdPartyStationRelationVO;
@@ -22,10 +25,8 @@ import com.jsowell.pile.vo.zdl.EquipBusinessPolicyVO;
import com.jsowell.thirdparty.common.CommonService;
import com.jsowell.pile.thirdparty.CommonParamsDTO;
import com.jsowell.thirdparty.lianlian.service.LianLianService;
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.platform.util.*;
import com.jsowell.thirdparty.service.ThirdpartySecretInfoService;
import com.jsowell.thirdparty.yongchengboche.dto.YCBCGetTokenDTO;
import com.jsowell.thirdparty.yongchengboche.service.YCBCService;
import com.jsowell.pile.thirdparty.ZDLConnectorInfo;
@@ -63,9 +64,6 @@ public class ZDLServiceImpl implements ZDLService {
@Autowired
private PileStationInfoService pileStationInfoService;
@Autowired
private ThirdPartyPlatformConfigService thirdPartyPlatformConfigService;
@Autowired
private PileBasicInfoService pileBasicInfoService;
@@ -85,7 +83,7 @@ public class ZDLServiceImpl implements ZDLService {
private PileBillingTemplateService pileBillingTemplateService;
@Autowired
private ThirdPartySettingInfoService thirdPartySettingInfoService;
private ThirdpartySecretInfoService thirdpartySecretInfoService;
@Autowired
private CommonService commonService;
@@ -208,14 +206,14 @@ public class ZDLServiceImpl implements ZDLService {
// 通过第三方配置类型查询相关配置信息
ThirdPartySettingInfo settingInfo = new ThirdPartySettingInfo();
settingInfo.setType(dto.getThirdPartyType());
ThirdPartySettingInfo thirdPartySettingInfo = thirdPartySettingInfoService.selectSettingInfo(settingInfo);
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getNingBoPlatformSecretInfo();
String operatorId = thirdPartySettingInfo.getOperatorId();
String operatorSecret = thirdPartySettingInfo.getOperatorSecret();
String signSecret = thirdPartySettingInfo.getSignSecret();
String dataSecret = thirdPartySettingInfo.getDataSecret();
String dataSecretIv = thirdPartySettingInfo.getDataSecretIv();
String urlAddress = thirdPartySettingInfo.getUrlAddress();
String operatorId = thirdPartySecretInfoVO.getTheirOperatorId();
String operatorSecret = thirdPartySecretInfoVO.getTheirOperatorSecret();
String signSecret = thirdPartySecretInfoVO.getTheirSigSecret();
String dataSecret = thirdPartySecretInfoVO.getTheirDataSecret();
String dataSecretIv = thirdPartySecretInfoVO.getTheirDataSecretIv();
String urlAddress = thirdPartySecretInfoVO.getTheirUrlPrefix();
// 组装中电联平台所需要的数据格式
ZDLStationInfo info = ZDLStationInfo.builder()
@@ -348,10 +346,8 @@ public class ZDLServiceImpl implements ZDLService {
// 未查到数据
return null;
}
ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorId());
if (configInfo == null) {
return null;
}
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getNingBoPlatformSecretInfo();
PageInfo<ThirdPartyStationInfoVO> pageInfo = new PageInfo<>(stationInfos);
for (ThirdPartyStationInfoVO pileStationInfo : pageInfo.getList()) {
ZDLStationInfo stationInfo = new ZDLStationInfo();
@@ -402,18 +398,8 @@ public class ZDLServiceImpl implements ZDLService {
map.put("ItemSize", resultList.size());
map.put("StationInfos", resultList);
// 加密
Map<String, String> resultMap = Maps.newLinkedHashMap();
// 加密数据
byte[] encryptText = Cryptos.aesEncrypt(JSON.toJSONString(map).getBytes(),
configInfo.getDataSecret().getBytes(), configInfo.getDataSecretIv().getBytes());
String encryptData = Encodes.encodeBase64(encryptText);
resultMap.put("Data", encryptData);
// 生成sig
String resultSign = GBSignUtils.sign(resultMap, configInfo.getSignSecret());
resultMap.put("Sig", resultSign);
Map<String, String> resultMap = ThirdPartyPlatformUtils.generateResultMapV2(map, thirdPartySecretInfoVO.getOurDataSecret(),
thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret());
return resultMap;
}
@@ -465,10 +451,10 @@ public class ZDLServiceImpl implements ZDLService {
* @param dto
* @return
*/
@Override
public Map<String, String> generateToken(CommonParamsDTO dto) throws UnsupportedEncodingException {
return lianLianService.generateToken(dto);
}
// @Override
// public Map<String, String> generateToken(CommonParamsDTO dto) throws UnsupportedEncodingException {
// return lianLianService.generateToken(dto);
// }
/**
* 请求设备认证
@@ -499,10 +485,8 @@ public class ZDLServiceImpl implements ZDLService {
public Map<String, String> queryEquipBusinessPolicy(QueryStartChargeDTO dto) {
List<EquipBusinessPolicyVO.PolicyInfo> policyInfoList = new ArrayList<>();
String pileConnectorCode = dto.getConnectorID();
ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorId());
if (configInfo == null) {
return null;
}
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getNingBoPlatformSecretInfo();
// 截取桩号
// String pileSn = StringUtils.substring(pileConnectorCode, 0, 14);
String pileSn = YKCUtils.getPileSn(pileConnectorCode);
@@ -539,18 +523,8 @@ public class ZDLServiceImpl implements ZDLService {
.build();
// 加密
Map<String, String> resultMap = Maps.newLinkedHashMap();
// 加密数据
byte[] encryptText = Cryptos.aesEncrypt(JSON.toJSONString(vo).getBytes(),
configInfo.getDataSecret().getBytes(), configInfo.getDataSecretIv().getBytes());
String encryptData = Encodes.encodeBase64(encryptText);
resultMap.put("Data", encryptData);
// 生成sig
String resultSign = GBSignUtils.sign(resultMap, configInfo.getSignSecret());
resultMap.put("Sig", resultSign);
Map<String, String> resultMap = ThirdPartyPlatformUtils.generateResultMapV2(vo, thirdPartySecretInfoVO.getOurDataSecret(),
thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret());
return resultMap;
}
@@ -596,10 +570,10 @@ public class ZDLServiceImpl implements ZDLService {
* 校验签名
* @param dto
*/
@Override
public Map<String, String> checkoutSign(CommonParamsDTO dto) {
return lianLianService.checkoutSign(dto);
}
// @Override
// public Map<String, String> checkoutSign(CommonParamsDTO dto) {
// return lianLianService.checkoutSign(dto);
// }
/**
* 推送充电状态
@@ -681,4 +655,19 @@ public class ZDLServiceImpl implements ZDLService {
return resultList;
}
/**
* 获取宁波平台配置密钥信息
*
* @return
*/
private ThirdPartySecretInfoVO getNingBoPlatformSecretInfo() {
// 通过第三方平台类型查询相关配置信息
ThirdPartySecretInfoVO thirdPartySecretInfoVO = thirdpartySecretInfoService.queryByThirdPlatformType(ThirdPlatformTypeEnum.NING_BO_PLATFORM.getTypeCode());
if (thirdPartySecretInfoVO == null) {
throw new BusinessException(ReturnCodeEnum.CODE_SELECT_INFO_IS_NULL);
}
thirdPartySecretInfoVO.setOurOperatorId(Constants.OPERATORID_JIANG_SU);
return thirdPartySecretInfoVO;
}
}