mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-21 03:25:12 +08:00
update 重构华为Service
This commit is contained in:
@@ -1,11 +1,14 @@
|
||||
package com.jsowell.thirdparty.huawei;
|
||||
|
||||
import cn.hutool.http.HttpRequest;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
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.core.domain.ykc.RealTimeMonitorData;
|
||||
import com.jsowell.common.core.redis.RedisCache;
|
||||
import com.jsowell.common.enums.thirdparty.ThirdPartyOperatorIdEnum;
|
||||
import com.jsowell.common.enums.thirdparty.ThirdPlatformTypeEnum;
|
||||
import com.jsowell.common.enums.thirdparty.huawei.StartFailedReasonEnum;
|
||||
import com.jsowell.common.enums.ykc.OrderStatusEnum;
|
||||
@@ -18,11 +21,10 @@ import com.jsowell.pile.domain.*;
|
||||
import com.jsowell.pile.domain.huawei.HWStationInfo;
|
||||
import com.jsowell.pile.dto.PushStationInfoDTO;
|
||||
import com.jsowell.pile.dto.QueryStartChargeDTO;
|
||||
import com.jsowell.pile.dto.huawei.DeliverEquipBusinessDTO;
|
||||
import com.jsowell.pile.dto.huawei.HWQueryStartChargeDTO;
|
||||
import com.jsowell.pile.dto.huawei.ReceiveStartChargeResultDTO;
|
||||
import com.jsowell.pile.dto.huawei.RequestEquipBusinessPolicyDTO;
|
||||
import com.jsowell.pile.dto.huawei.*;
|
||||
import com.jsowell.pile.service.*;
|
||||
import com.jsowell.pile.vo.huawei.DeliverEquipBusinessPolicyVO;
|
||||
import com.jsowell.pile.vo.huawei.QueryChargeStatusVO;
|
||||
import com.jsowell.pile.vo.huawei.QueryEquipAuthVO;
|
||||
import com.jsowell.pile.vo.huawei.QueryStartChargeVO;
|
||||
import com.jsowell.pile.vo.uniapp.BillingPriceVO;
|
||||
@@ -118,8 +120,18 @@ public class HuaweiServiceV2 {
|
||||
dataSecret.getBytes(), dataSecretIv.getBytes());
|
||||
String strData = Encodes.encodeBase64(encryptText);
|
||||
|
||||
Map<String, String> request = new LinkedHashMap<>();
|
||||
request.put("OperatorID", Constants.OPERATORID_JIANG_SU);
|
||||
request.put("Data", strData);
|
||||
request.put("TimeStamp", DateUtils.parseDateToStr(DateUtils.YYYYMMDDHHMMSS, new Date()));
|
||||
request.put("Seq", "0001");
|
||||
// 生成签名
|
||||
String sig = GBSignUtils.sign(request, signSecret);
|
||||
request.put("Sig", sig);
|
||||
|
||||
String tokenRequest = JSONObject.toJSONString(request);
|
||||
// 向华为发送请求
|
||||
String response = sendRequest2HuaWei(strData, signSecret, requestUrl);
|
||||
String response = HttpUtil.post(requestUrl, tokenRequest);
|
||||
|
||||
CommonResult<?> commonResult = JSONObject.parseObject(response, CommonResult.class);
|
||||
if (commonResult.getRet() != 0) {
|
||||
@@ -202,42 +214,22 @@ public class HuaweiServiceV2 {
|
||||
* @return
|
||||
*/
|
||||
public List<StationStatusInfo> queryStationStatus(List<String> stationIds) {
|
||||
ThirdPartySettingInfo settingInfo = getHuaWeiSettingInfo();
|
||||
if (settingInfo == null) {
|
||||
return null;
|
||||
}
|
||||
String operatorSecret = settingInfo.getOperatorSecret();
|
||||
String dataSecret = settingInfo.getDataSecret();
|
||||
String dataSecretIv = settingInfo.getDataSecretIv();
|
||||
String signSecret = settingInfo.getSignSecret();
|
||||
String urlAddress = settingInfo.getUrlAddress();
|
||||
|
||||
String requestUrl = urlAddress + "query_station_status";
|
||||
String requestName = "query_station_status";
|
||||
|
||||
// 拼装参数
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("StationIDs", stationIds);
|
||||
|
||||
// 加密
|
||||
byte[] encryptText = Cryptos.aesEncrypt(jsonObject.toJSONString().getBytes(StandardCharsets.UTF_8),
|
||||
dataSecret.getBytes(), dataSecretIv.getBytes());
|
||||
String strData = Encodes.encodeBase64(encryptText);
|
||||
|
||||
String jsonString = jsonObject.toJSONString();
|
||||
// 向华为发送请求
|
||||
String response = sendRequest2HuaWei(strData, signSecret, requestUrl);
|
||||
|
||||
CommonResult<?> commonResult = JSONObject.parseObject(response, CommonResult.class);
|
||||
if (commonResult.getRet() != 0) {
|
||||
log.error("查询华为设备接口状态 error:{}, ", commonResult.getMsg());
|
||||
// 获取令牌
|
||||
String token = getHuaWeiToken();
|
||||
// 发送请求
|
||||
String result = sendMsg2HuaWei(jsonString, token, requestName);
|
||||
if (result == null) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
// 解密data
|
||||
byte[] plainText = Cryptos.aesDecrypt(Encodes.decodeBase64((String) commonResult.getData()),
|
||||
dataSecret.getBytes(), dataSecretIv.getBytes());
|
||||
String dataStr = new String(plainText, StandardCharsets.UTF_8);
|
||||
|
||||
// 转换成 StationStatus 对象
|
||||
List<StationStatusInfo> list = JSON.parseArray(dataStr, StationStatusInfo.class);
|
||||
List<StationStatusInfo> list = JSON.parseArray(result, StationStatusInfo.class);
|
||||
return list;
|
||||
|
||||
}
|
||||
@@ -261,18 +253,8 @@ public class HuaweiServiceV2 {
|
||||
// 构造返回参数
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("Status", 0);
|
||||
// 加密
|
||||
Map<String, String> resultMap = Maps.newLinkedHashMap();
|
||||
// 加密数据
|
||||
byte[] encryptText = Cryptos.aesEncrypt(jsonObject.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 = getResultMap(jsonObject);
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
@@ -283,17 +265,7 @@ public class HuaweiServiceV2 {
|
||||
* @return
|
||||
*/
|
||||
public QueryEquipAuthVO queryEquipAuth(String connectorId) {
|
||||
ThirdPartySettingInfo settingInfo = getHuaWeiSettingInfo();
|
||||
if (settingInfo == null) {
|
||||
return null;
|
||||
}
|
||||
String operatorSecret = settingInfo.getOperatorSecret();
|
||||
String dataSecret = settingInfo.getDataSecret();
|
||||
String dataSecretIv = settingInfo.getDataSecretIv();
|
||||
String signSecret = settingInfo.getSignSecret();
|
||||
String urlAddress = settingInfo.getUrlAddress();
|
||||
|
||||
String requestUrl = urlAddress + "query_equip_auth";
|
||||
String requestName = "query_equip_auth";
|
||||
|
||||
// 生成设备认证流水号(格式“运营商ID + 唯一编号”(<=27字符))
|
||||
// 生成唯一编号(用时间戳表示)
|
||||
@@ -304,26 +276,18 @@ public class HuaweiServiceV2 {
|
||||
jsonObject.put("EquipAuthSeq", equipAuthSeq);
|
||||
jsonObject.put("ConnectorID", connectorId);
|
||||
|
||||
// 加密
|
||||
byte[] encryptText = Cryptos.aesEncrypt(jsonObject.toJSONString().getBytes(StandardCharsets.UTF_8),
|
||||
dataSecret.getBytes(), dataSecretIv.getBytes());
|
||||
String strData = Encodes.encodeBase64(encryptText);
|
||||
|
||||
String jsonString = jsonObject.toJSONString();
|
||||
// 向华为发送请求
|
||||
String response = sendRequest2HuaWei(strData, signSecret, requestUrl);
|
||||
|
||||
CommonResult<?> commonResult = JSONObject.parseObject(response, CommonResult.class);
|
||||
if (commonResult.getRet() != 0) {
|
||||
log.error("查询华为设备接口状态 error:{}, ", commonResult.getMsg());
|
||||
// 获取令牌
|
||||
String token = getHuaWeiToken();
|
||||
// 发送请求
|
||||
String result = sendMsg2HuaWei(jsonString, token, requestName);
|
||||
if (result == null) {
|
||||
return null;
|
||||
}
|
||||
// 解密data
|
||||
byte[] plainText = Cryptos.aesDecrypt(Encodes.decodeBase64((String) commonResult.getData()),
|
||||
dataSecret.getBytes(), dataSecretIv.getBytes());
|
||||
String dataStr = new String(plainText, StandardCharsets.UTF_8);
|
||||
|
||||
// 转换成 StationStatus 对象
|
||||
QueryEquipAuthVO queryEquipAuthVO = JSON.parseObject(dataStr, QueryEquipAuthVO.class);
|
||||
QueryEquipAuthVO queryEquipAuthVO = JSON.parseObject(result, QueryEquipAuthVO.class);
|
||||
return queryEquipAuthVO;
|
||||
}
|
||||
|
||||
@@ -363,8 +327,8 @@ public class HuaweiServiceV2 {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
String result = deliverEquipBusinessPolicy(equipBizSeq, pileConnectorCode);
|
||||
log.info("华为 异步调用 下发计费策略 接口 result:{}", result);
|
||||
DeliverEquipBusinessPolicyVO vo = deliverEquipBusinessPolicy(equipBizSeq, pileConnectorCode);
|
||||
log.info("华为 异步调用 下发计费策略 接口 result:{}", JSONObject.toJSONString(vo));
|
||||
});
|
||||
|
||||
resultJson.put("SuccStat", 0);
|
||||
@@ -392,7 +356,8 @@ public class HuaweiServiceV2 {
|
||||
* @param pileConnectorCode 枪口号
|
||||
* @return
|
||||
*/
|
||||
public String deliverEquipBusinessPolicy(String equipBizSeq, String pileConnectorCode) {
|
||||
public DeliverEquipBusinessPolicyVO deliverEquipBusinessPolicy(String equipBizSeq, String pileConnectorCode) {
|
||||
String requestName = "deliver_equip_business_policy";
|
||||
DeliverEquipBusinessDTO params = new DeliverEquipBusinessDTO();
|
||||
|
||||
// 充电业务策略信息
|
||||
@@ -431,9 +396,6 @@ public class HuaweiServiceV2 {
|
||||
// return null;
|
||||
// }
|
||||
|
||||
// 通过站点id查询相关配置信息 换成如下方法
|
||||
ThirdPartySettingInfo settingInfo = getHuaWeiSettingInfo();
|
||||
|
||||
// 根据站点id查询正在使用的计费模板
|
||||
List<BillingPriceVO> billingPriceVOList = pileBillingTemplateService.queryBillingPrice(stationId);
|
||||
if (CollectionUtils.isEmpty(billingPriceVOList)) {
|
||||
@@ -481,21 +443,17 @@ public class HuaweiServiceV2 {
|
||||
|
||||
String jsonString = JSONObject.toJSONString(params);
|
||||
|
||||
// 获取请求参数
|
||||
String operatorId = Constants.OPERATORID_JIANG_SU;
|
||||
String operatorSecret = settingInfo.getOperatorSecret();
|
||||
String signSecret = settingInfo.getSignSecret();
|
||||
String dataSecret = settingInfo.getDataSecret();
|
||||
String dataSecretIv = settingInfo.getDataSecretIv();
|
||||
String urlAddress = settingInfo.getUrlAddress();
|
||||
|
||||
String url = urlAddress + "deliver_equip_business_policy";
|
||||
// 向华为发送请求
|
||||
// 获取令牌
|
||||
|
||||
String token = getHuaWeiToken();
|
||||
// 发送请求
|
||||
String result = HttpRequestUtil.sendPost(token, jsonString, url, dataSecret, dataSecretIv, operatorId, signSecret);
|
||||
return result;
|
||||
String result = sendMsg2HuaWei(jsonString, token, requestName);
|
||||
if (result == null) {
|
||||
return null;
|
||||
}
|
||||
// 转换成 DeliverEquipBusinessPolicyVO 对象
|
||||
DeliverEquipBusinessPolicyVO vo = JSON.parseObject(result, DeliverEquipBusinessPolicyVO.class);
|
||||
return vo;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -507,18 +465,8 @@ public class HuaweiServiceV2 {
|
||||
public QueryStartChargeVO queryStartCharge(HWQueryStartChargeDTO dto) {
|
||||
String pileConnectorCode = dto.getConnectorID();
|
||||
BigDecimal chargeAmount = dto.getMoneyLimit();
|
||||
// 获取华为配置参数
|
||||
ThirdPartySettingInfo settingInfo = getHuaWeiSettingInfo();
|
||||
if (settingInfo == null) {
|
||||
return null;
|
||||
}
|
||||
String operatorSecret = settingInfo.getOperatorSecret();
|
||||
String dataSecret = settingInfo.getDataSecret();
|
||||
String dataSecretIv = settingInfo.getDataSecretIv();
|
||||
String signSecret = settingInfo.getSignSecret();
|
||||
String urlAddress = settingInfo.getUrlAddress();
|
||||
|
||||
String requestUrl = urlAddress + "query_start_charge";
|
||||
String requestName = "query_start_charge";
|
||||
|
||||
// 生成订单
|
||||
String orderCode = IdUtils.getOrderCode();
|
||||
@@ -540,26 +488,18 @@ public class HuaweiServiceV2 {
|
||||
jsonObject.put("ConnectorID", pileConnectorCode);
|
||||
jsonObject.put("MoneyLimit", chargeAmount);
|
||||
|
||||
// 加密
|
||||
byte[] encryptText = Cryptos.aesEncrypt(jsonObject.toJSONString().getBytes(StandardCharsets.UTF_8),
|
||||
dataSecret.getBytes(), dataSecretIv.getBytes());
|
||||
String strData = Encodes.encodeBase64(encryptText);
|
||||
|
||||
String jsonString = jsonObject.toJSONString();
|
||||
// 向华为发送请求
|
||||
String response = sendRequest2HuaWei(strData, signSecret, requestUrl);
|
||||
|
||||
CommonResult<?> commonResult = JSONObject.parseObject(response, CommonResult.class);
|
||||
if (commonResult.getRet() != 0) {
|
||||
log.error("解析华为请求启动充电接口result error:{}, ", commonResult.getMsg());
|
||||
// 获取令牌
|
||||
String token = getHuaWeiToken();
|
||||
// 发送请求
|
||||
String result = sendMsg2HuaWei(jsonString, token, requestName);
|
||||
if (result == null) {
|
||||
return null;
|
||||
}
|
||||
// 解密data
|
||||
byte[] plainText = Cryptos.aesDecrypt(Encodes.decodeBase64((String) commonResult.getData()),
|
||||
dataSecret.getBytes(), dataSecretIv.getBytes());
|
||||
String dataStr = new String(plainText, StandardCharsets.UTF_8);
|
||||
|
||||
// 转换成 QueryStartChargeVO 对象
|
||||
QueryStartChargeVO vo = JSON.parseObject(dataStr, QueryStartChargeVO.class);
|
||||
QueryStartChargeVO vo = JSON.parseObject(result, QueryStartChargeVO.class);
|
||||
return vo;
|
||||
}
|
||||
|
||||
@@ -567,7 +507,7 @@ public class HuaweiServiceV2 {
|
||||
/**
|
||||
* 接收启动充电结果
|
||||
*/
|
||||
public void receiveStartChargeResult(ReceiveStartChargeResultDTO dto) {
|
||||
public Map<String, String> receiveStartChargeResult(ReceiveStartChargeResultDTO dto) {
|
||||
String startChargeSeq = dto.getStartChargeSeq();
|
||||
Integer startChargeSeqStat = dto.getStartChargeSeqStat(); // 充电订单状态
|
||||
Integer failReason = dto.getFailReason();
|
||||
@@ -588,50 +528,102 @@ public class HuaweiServiceV2 {
|
||||
// 给用户退款(执行0x33中启动失败的操作流程)
|
||||
orderBasicInfoService.chargingPileFailedToStart(orderBasicInfo.getTransactionCode(), reason);
|
||||
}
|
||||
|
||||
// 构建返回参数
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("StartChargeSeq", startChargeSeq);
|
||||
jsonObject.put("SuccStat", 0);
|
||||
jsonObject.put("FailReason", 0);
|
||||
|
||||
Map<String, String> resultMap = getResultMap(jsonObject);
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询充电状态
|
||||
* @param startChargeSeq
|
||||
* @param startChargeSeq 订单号
|
||||
*/
|
||||
public void queryChargeStatus(String startChargeSeq) {
|
||||
ThirdPartySettingInfo settingInfo = getHuaWeiSettingInfo();
|
||||
if (settingInfo == null) {
|
||||
return;
|
||||
}
|
||||
String operatorSecret = settingInfo.getOperatorSecret();
|
||||
String dataSecret = settingInfo.getDataSecret();
|
||||
String dataSecretIv = settingInfo.getDataSecretIv();
|
||||
String signSecret = settingInfo.getSignSecret();
|
||||
String urlAddress = settingInfo.getUrlAddress();
|
||||
|
||||
String requestUrl = urlAddress + "query_equip_auth";
|
||||
public QueryChargeStatusVO queryChargeStatus(String startChargeSeq) {
|
||||
String requestName = "query_equip_auth";
|
||||
|
||||
// 拼装参数
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("StartChargeSeq", startChargeSeq);
|
||||
|
||||
// 加密
|
||||
byte[] encryptText = Cryptos.aesEncrypt(jsonObject.toJSONString().getBytes(StandardCharsets.UTF_8),
|
||||
dataSecret.getBytes(), dataSecretIv.getBytes());
|
||||
String strData = Encodes.encodeBase64(encryptText);
|
||||
|
||||
String jsonString = jsonObject.toJSONString();
|
||||
// 向华为发送请求
|
||||
String response = sendRequest2HuaWei(strData, signSecret, requestUrl);
|
||||
// 获取令牌
|
||||
String token = getHuaWeiToken();
|
||||
// 发送请求
|
||||
String result = sendMsg2HuaWei(jsonString, token, requestName);
|
||||
if (result == null) {
|
||||
return null;
|
||||
}
|
||||
// 转换成 QueryChargeStatusVO 对象
|
||||
QueryChargeStatusVO vo = JSON.parseObject(result, QueryChargeStatusVO.class);
|
||||
return vo;
|
||||
|
||||
CommonResult<?> commonResult = JSONObject.parseObject(response, CommonResult.class);
|
||||
if (commonResult.getRet() != 0) {
|
||||
log.error("解析查询华为充电状态接口result error:{}, ", commonResult.getMsg());
|
||||
}
|
||||
|
||||
/**
|
||||
* 接收华为所推送的设备充电状态
|
||||
* @param dto
|
||||
*/
|
||||
public Map<String, String> receiveEquipChargeStatus(ReceiveEquipChargeStatusDTO dto) {
|
||||
String startChargeSeq = dto.getStartChargeSeq(); // 订单号
|
||||
String startTime = dto.getStartTime();
|
||||
String endTime = dto.getEndTime();
|
||||
// 计算时间间隔
|
||||
String poorDays = DateUtils.getDatePoor(DateUtils.parseDate(endTime), DateUtils.parseDate(startTime));
|
||||
// 通过订单号查询交易流水号
|
||||
OrderBasicInfo orderBasicInfo = orderBasicInfoService.getOrderInfoByOrderCode(startChargeSeq);
|
||||
if (orderBasicInfo == null) {
|
||||
return null;
|
||||
}
|
||||
// 将源数据存储至缓存
|
||||
String redisKey = "HUA_WEI_ORDER_INFO_BY_ORDER_CODE:" + startChargeSeq;
|
||||
String jsonMsg = JSONObject.toJSONString(dto);
|
||||
// 在同一分钟内,只保留最后一条实时数据
|
||||
redisCache.hset(redisKey, DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:00", new Date()), jsonMsg);
|
||||
|
||||
// 封装成实时数据对象
|
||||
RealTimeMonitorData data = RealTimeMonitorData.builder()
|
||||
.transactionCode(orderBasicInfo.getTransactionCode())
|
||||
.pileSn(orderBasicInfo.getPileSn())
|
||||
.connectorCode(orderBasicInfo.getConnectorCode())
|
||||
.connectorStatus(String.valueOf(dto.getConnectorStatus()))
|
||||
.pileConnectorCode(orderBasicInfo.getPileConnectorCode())
|
||||
.outputVoltage(String.valueOf(dto.getVoltageA()))
|
||||
.outputCurrent(String.valueOf(dto.getCurrentA()))
|
||||
.SOC(String.valueOf(dto.getSoc()))
|
||||
.sumChargingTime(poorDays)
|
||||
.chargingDegree(String.valueOf(dto.getTotalPower()))
|
||||
.chargingAmount(String.valueOf(dto.getTotalMoney()))
|
||||
|
||||
.build();
|
||||
|
||||
// 将实时数据信息保存至缓存
|
||||
pileBasicInfoService.saveRealTimeMonitorData2Redis(data);
|
||||
|
||||
// 构建返回参数
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("StartChargeSeq", startChargeSeq);
|
||||
jsonObject.put("SuccStat", 0);
|
||||
|
||||
Map<String, String> resultMap = getResultMap(jsonObject);
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
|
||||
public void queryStopCharge(String startChargeSeq) {
|
||||
// 通过订单号查询订单信息
|
||||
OrderBasicInfo orderBasicInfo = orderBasicInfoService.getOrderInfoByOrderCode(startChargeSeq);
|
||||
if(orderBasicInfo == null) {
|
||||
return;
|
||||
}
|
||||
// 解密data
|
||||
byte[] plainText = Cryptos.aesDecrypt(Encodes.decodeBase64((String) commonResult.getData()),
|
||||
dataSecret.getBytes(), dataSecretIv.getBytes());
|
||||
String dataStr = new String(plainText, StandardCharsets.UTF_8);
|
||||
|
||||
// 转换成对应的对象
|
||||
|
||||
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("StartChargeSeq", startChargeSeq);
|
||||
jsonObject.put("ConnectorID", orderBasicInfo.getPileConnectorCode());
|
||||
|
||||
}
|
||||
|
||||
@@ -650,26 +642,82 @@ public class HuaweiServiceV2 {
|
||||
|
||||
/**
|
||||
* 向华为发送请求
|
||||
* @param strData 加密后的Data
|
||||
* @param signSecret 签名密钥
|
||||
* @param requestUrl 请求url
|
||||
* @param jsonString 封装好的json请求参数
|
||||
* @param token 从华为平台请求到的令牌
|
||||
* @param requestName 请求接口名称
|
||||
* @return 请求结果
|
||||
*/
|
||||
private String sendRequest2HuaWei(String strData, String signSecret, String requestUrl) {
|
||||
Map<String, String> request = new LinkedHashMap<>();
|
||||
request.put("OperatorID", Constants.OPERATORID_JIANG_SU);
|
||||
request.put("Data", strData);
|
||||
request.put("TimeStamp", DateUtils.parseDateToStr(DateUtils.YYYYMMDDHHMMSS, new Date()));
|
||||
request.put("Seq", "0001");
|
||||
// 生成签名
|
||||
String sig = GBSignUtils.sign(request, signSecret);
|
||||
request.put("Sig", sig);
|
||||
private String sendMsg2HuaWei(String jsonString, String token, String requestName) {
|
||||
ThirdPartySettingInfo settingInfo = getHuaWeiSettingInfo();
|
||||
if (settingInfo == null) {
|
||||
return null;
|
||||
}
|
||||
//加密
|
||||
byte[] encryptText = Cryptos.aesEncrypt(jsonString.getBytes(),
|
||||
settingInfo.getDataSecret().getBytes(), settingInfo.getDataSecretIv().getBytes());
|
||||
String encryptData = Encodes.encodeBase64(encryptText);
|
||||
|
||||
String tokenRequest = JSONObject.toJSONString(request);
|
||||
String response = HttpUtil.post(requestUrl, tokenRequest);
|
||||
return response;
|
||||
Map<String, String> params = Maps.newLinkedHashMap();
|
||||
params.put("OperatorID", settingInfo.getOperatorId());
|
||||
params.put("Data", encryptData);
|
||||
params.put("TimeStamp", DateUtils.parseDateToStr(DateUtils.YYYYMMDDHHMMSS, new Date()));
|
||||
params.put("Seq", "001");
|
||||
|
||||
String sign = GBSignUtils.sign(params, settingInfo.getSignSecret());
|
||||
params.put("Sig", sign);
|
||||
|
||||
String postData = JSON.toJSONString(params);
|
||||
// 请求url
|
||||
String requestUrl = settingInfo.getUrlAddress() + requestName;
|
||||
String hutoolRequest = HttpRequest.post(requestUrl)
|
||||
.header("Authorization", "Bearer " + token)
|
||||
.body(postData).execute().body();
|
||||
log.info("华为发送请求 接收到返回数据:{}", hutoolRequest);
|
||||
if (StringUtils.isBlank(hutoolRequest)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Map<String, Object> map = (Map<String, Object>) JSON.parse(hutoolRequest);
|
||||
|
||||
int ret = (int) map.get("Ret");
|
||||
String resultMsg = (String) map.get("Msg");
|
||||
if (ret != 0) {
|
||||
// 表示请求有异常
|
||||
log.error("华为发送请求 error:{}, 源数据:{}", resultMsg, jsonString);
|
||||
return null;
|
||||
}
|
||||
String rData = (String) map.get("Data");
|
||||
// 解密
|
||||
byte[] plainText = Cryptos.aesDecrypt(Encodes.decodeBase64(rData),
|
||||
settingInfo.getDataSecret().getBytes(), settingInfo.getDataSecretIv().getBytes());
|
||||
String plainData = new String(plainText, StandardCharsets.UTF_8);
|
||||
return plainData;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将需要发送至华为的返回参数加密返回
|
||||
* @param jsonObject
|
||||
* @return
|
||||
*/
|
||||
private Map<String, String> getResultMap(JSONObject jsonObject) {
|
||||
String operatorId = ThirdPartyOperatorIdEnum.HUA_WEI.getOperatorId();
|
||||
ThirdPartyPlatformConfig platformConfig = thirdPartyPlatformConfigService.getInfoByOperatorId(operatorId);
|
||||
if (platformConfig == null) {
|
||||
return 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("Data", encryptData);
|
||||
// 生成sig
|
||||
String resultSign = GBSignUtils.sign(resultMap, platformConfig.getSignSecret());
|
||||
resultMap.put("Sig", resultSign);
|
||||
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取桩列表
|
||||
|
||||
Reference in New Issue
Block a user