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;
}
}