package com.jsowell.thirdparty.huawei; 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.redis.RedisCache; import com.jsowell.common.enums.thirdparty.ThirdPlatformTypeEnum; import com.jsowell.common.enums.thirdparty.huawei.StartFailedReasonEnum; import com.jsowell.common.enums.ykc.OrderStatusEnum; import com.jsowell.common.enums.ykc.ReturnCodeEnum; import com.jsowell.common.exception.BusinessException; import com.jsowell.common.util.DateUtils; import com.jsowell.common.util.StringUtils; import com.jsowell.common.util.id.IdUtils; 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.service.*; import com.jsowell.pile.vo.huawei.QueryEquipAuthVO; import com.jsowell.pile.vo.huawei.QueryStartChargeVO; import com.jsowell.pile.vo.uniapp.BillingPriceVO; import com.jsowell.pile.vo.web.PileStationVO; import com.jsowell.thirdparty.lianlian.common.CommonResult; import com.jsowell.thirdparty.lianlian.domain.ConnectorStatusInfo; import com.jsowell.thirdparty.lianlian.domain.StationStatusInfo; import com.jsowell.thirdparty.lianlian.util.Cryptos; import com.jsowell.thirdparty.lianlian.util.Encodes; import com.jsowell.thirdparty.lianlian.util.GBSignUtils; import com.jsowell.thirdparty.lianlian.util.HttpRequestUtil; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.CollectionUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.math.BigDecimal; import java.math.RoundingMode; import java.nio.charset.StandardCharsets; import java.util.*; import java.util.concurrent.CompletableFuture; import java.util.concurrent.TimeUnit; /** * 华为Service * * @author Lemon * @Date 2024/1/19 14:10:02 */ @Service @Slf4j public class HuaweiServiceV2 { @Autowired private PileStationInfoService pileStationInfoService; @Autowired private PileConnectorInfoService pileConnectorInfoService; @Autowired private PileBasicInfoService pileBasicInfoService; @Autowired private ThirdPartySettingInfoService thirdPartySettingInfoService; @Autowired private ThirdPartyPlatformConfigService thirdPartyPlatformConfigService; @Autowired private PileBillingTemplateService pileBillingTemplateService; @Autowired private OrderBasicInfoService orderBasicInfoService; @Autowired private ThirdPartyStationRelationService thirdPartyStationRelationService; @Autowired private RedisCache redisCache; /** * 获取华为 Token * @return */ public String getHuaWeiToken() { String operatorId = Constants.OPERATORID_JIANG_SU; String redisKey = "huawei_get_token:" + operatorId; // 先查缓存 String cacheToken = redisCache.getCacheObject(redisKey); if (StringUtils.isNotBlank(cacheToken)) { return cacheToken; } // 通过华为的type查询出密钥配置 ThirdPartySettingInfo info = new ThirdPartySettingInfo(); info.setType(ThirdPlatformTypeEnum.HUA_WEI.getCode()); ThirdPartySettingInfo settingInfo = thirdPartySettingInfoService.selectSettingInfo(info); String operatorSecret = settingInfo.getOperatorSecret(); String dataSecret = settingInfo.getDataSecret(); String dataSecretIv = settingInfo.getDataSecretIv(); String signSecret = settingInfo.getSignSecret(); String urlAddress = settingInfo.getUrlAddress(); String requestUrl = urlAddress + "query_token"; // 拼装参数 JSONObject jsonObject = new JSONObject(); jsonObject.put("OperatorID", operatorId); jsonObject.put("OperatorSecret", operatorSecret); // 加密 byte[] encryptText = Cryptos.aesEncrypt(jsonObject.toJSONString().getBytes(StandardCharsets.UTF_8), dataSecret.getBytes(), dataSecretIv.getBytes()); String strData = Encodes.encodeBase64(encryptText); // 向华为发送请求 String response = sendRequest2HuaWei(strData, signSecret, requestUrl); CommonResult commonResult = JSONObject.parseObject(response, CommonResult.class); if (commonResult.getRet() != 0) { return commonResult.getMsg(); } // 解密data byte[] plainText = Cryptos.aesDecrypt(Encodes.decodeBase64((String) commonResult.getData()), dataSecret.getBytes(), dataSecretIv.getBytes()); String dataStr = new String(plainText, StandardCharsets.UTF_8); Map resultMap = (Map) JSON.parse(dataStr); int succStat = Integer.parseInt(resultMap.get("SuccStat")); if (succStat != 0) { return resultMap.get("FailReason"); } String token = resultMap.get("AccessToken"); int tokenAvailableTime = Integer.parseInt(resultMap.get("TokenAvailableTime")); // 凭证有效期,单位秒 // 存入缓存 redisCache.setCacheObject(redisKey, token, tokenAvailableTime, TimeUnit.SECONDS); return token; } /** * 平台充电设备编码同步 * * notification_operation_system_info * * @param dto * @return */ public String notificationOperationSystemInfo(PushStationInfoDTO dto) { Long stationId = dto.getStationId(); String type = dto.getThirdPartyType(); // 通过第三方配置类型查询相关配置信息 ThirdPartySettingInfo settingInfo = new ThirdPartySettingInfo(); settingInfo.setType(type); 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(); List equipmentLogicInfos = new ArrayList<>(); // 通过站点id查询站点信息 PileStationVO stationInfo = pileStationInfoService.getStationInfo(String.valueOf(stationId)); if (stationInfo == null) { return null; } HWStationInfo hwStationInfo = HWStationInfo.builder() .stationId(stationInfo.getId()) .stationName(stationInfo.getStationName()) .build(); // 查询桩列表 equipmentLogicInfos = getPileList(String.valueOf(stationId)); hwStationInfo.setEquipmentInfoNum(equipmentLogicInfos.size()); hwStationInfo.setEquipmentLogicInfos(equipmentLogicInfos); String jsonString = JSONObject.toJSONString(hwStationInfo); String url = urlAddress + "notification_operation_system_info"; // 获取令牌 String token = getHuaWeiToken(); // 发送请求 String result = HttpRequestUtil.sendPost(token, jsonString, url, dataSecret, dataSecretIv, operatorId, signSecret); return result; } /** * 设备接口状态查询 * * query_station_status * * @param stationIds * @return */ public List queryStationStatus(List 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"; // 拼装参数 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 response = sendRequest2HuaWei(strData, signSecret, requestUrl); CommonResult commonResult = JSONObject.parseObject(response, CommonResult.class); if (commonResult.getRet() != 0) { log.error("查询华为设备接口状态 error:{}, ", commonResult.getMsg()); 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 list = JSON.parseArray(dataStr, StationStatusInfo.class); return list; } /** * 接收设备接口状态变化推送 * 需在Controller传入operatorId * * @param connectorStatusInfo * @return */ public Map receiveNotificationStationStatus(ConnectorStatusInfo connectorStatusInfo) { String pileConnectorCode = connectorStatusInfo.getConnectorID(); Integer status = connectorStatusInfo.getStatus(); ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(connectorStatusInfo.getOperatorId()); if (configInfo == null) { return null; } // 将枪口状态改为对应的状态 pileConnectorInfoService.updateConnectorStatus(pileConnectorCode, String.valueOf(status)); // 构造返回参数 JSONObject jsonObject = new JSONObject(); jsonObject.put("Status", 0); // 加密 Map 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); return resultMap; } /** * 请求设备认证 * @param connectorId * @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"; // 生成设备认证流水号(格式“运营商ID + 唯一编号”(<=27字符)) // 生成唯一编号(用时间戳表示) long currentTimeMillis = System.currentTimeMillis(); String equipAuthSeq = Constants.OPERATORID_JIANG_SU + currentTimeMillis; // 拼装参数 JSONObject jsonObject = new JSONObject(); 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 response = sendRequest2HuaWei(strData, signSecret, requestUrl); CommonResult commonResult = JSONObject.parseObject(response, CommonResult.class); if (commonResult.getRet() != 0) { log.error("查询华为设备接口状态 error:{}, ", commonResult.getMsg()); 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); return queryEquipAuthVO; } /** * 请求计费策略 * @param dto * @return */ public Map requestEquipBusinessPolicy(RequestEquipBusinessPolicyDTO dto) { String pileConnectorCode = dto.getConnectorID(); String equipBizSeq = dto.getEquipBizSeq(); // 根据枪口号查询计费模板,并返回信息 ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorId()); if (configInfo == null) { return null; } // 截取桩号 String pileSn = StringUtils.substring(pileConnectorCode, 0, 14); // 查询该桩的站点id PileBasicInfo pileBasicInfo = pileBasicInfoService.selectPileBasicInfoBySN(pileSn); // 根据桩号查询正在使用的计费模板 List billingPriceVOList = pileBillingTemplateService.queryBillingPrice(String.valueOf(pileBasicInfo.getStationId())); JSONObject resultJson = new JSONObject(); resultJson.put("EquipBizSeq", equipBizSeq); resultJson.put("ConnectorID", pileConnectorCode); if (CollectionUtils.isEmpty(billingPriceVOList)) { // 为空说明未查到该枪口的计费模板 resultJson.put("SuccStat", 1); resultJson.put("FailReason", 1); }else { // 延时 500ms,异步调用 下发计费策略 接口 CompletableFuture.runAsync(() -> { try { Thread.sleep(500); } catch (Exception e) { e.printStackTrace(); } String result = deliverEquipBusinessPolicy(equipBizSeq, pileConnectorCode); log.info("华为 异步调用 下发计费策略 接口 result:{}", result); }); resultJson.put("SuccStat", 0); resultJson.put("FailReason", 0); } // 加密 Map 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); return resultMap; } /** * 下发计费策略 * @param equipBizSeq 策略下发流水号 * @param pileConnectorCode 枪口号 * @return */ public String deliverEquipBusinessPolicy(String equipBizSeq, String pileConnectorCode) { DeliverEquipBusinessDTO params = new DeliverEquipBusinessDTO(); // 充电业务策略信息 List chargePolicyInfos = new ArrayList<>(); DeliverEquipBusinessDTO.ChargePolicyInfo chargePolicyInfo = new DeliverEquipBusinessDTO.ChargePolicyInfo(); // 业务策略信息体 List pricePolicyInfos = new ArrayList<>(); DeliverEquipBusinessDTO.ChargePolicyInfo.PricePolicyInfo pricePolicyInfo = new DeliverEquipBusinessDTO.ChargePolicyInfo.PricePolicyInfo(); // 计费信息 List policyInfoList = new ArrayList<>(); DeliverEquipBusinessDTO.ChargePolicyInfo.PricePolicyInfo.PolicyInfo policyInfo = null; // 截取桩号 String pileSn = StringUtils.substring(pileConnectorCode, 0, 14); // 查询该桩的站点id PileBasicInfo pileBasicInfo = pileBasicInfoService.selectPileBasicInfoBySN(pileSn); String stationId = String.valueOf(pileBasicInfo.getStationId()); // 获取运营商组织结构代码 // MerchantInfoVO merchantInfoVO = pileMerchantInfoService.getMerchantInfoVO(String.valueOf(pileBasicInfo.getMerchantId())); // String organizationCode = merchantInfoVO.getOrganizationCode(); // 通过站点id查询相关配置信息 // ThirdPartyStationRelation relation = new ThirdPartyStationRelation(); // relation.setStationId(Long.parseLong(stationId)); // ThirdPartyStationRelationVO relationInfo = thirdPartyStationRelationService.selectRelationInfo(relation); // if (relationInfo == null) { // return null; // } // 通过站点id查询相关配置信息 换成如下方法 ThirdPartySettingInfo settingInfo = getHuaWeiSettingInfo(); // 根据站点id查询正在使用的计费模板 List billingPriceVOList = pileBillingTemplateService.queryBillingPrice(stationId); if (CollectionUtils.isEmpty(billingPriceVOList)) { return null; } for (BillingPriceVO billingPriceVO : billingPriceVOList) { // 将时段开始时间、电费、服务费信息进行封装 policyInfo = new DeliverEquipBusinessDTO.ChargePolicyInfo.PricePolicyInfo.PolicyInfo(); String startTime = billingPriceVO.getStartTime() + ":00"; // 00:00:00 格式 // 需要将中间的冒号去掉,改为 000000 格式 String replace = StringUtils.replace(startTime, ":", ""); policyInfo.setStartTime(replace); policyInfo.setElecPrice(new BigDecimal(billingPriceVO.getElectricityPrice()).setScale(4, RoundingMode.DOWN)); policyInfo.setSevicePrice(new BigDecimal(billingPriceVO.getServicePrice()).setScale(4, RoundingMode.DOWN)); policyInfoList.add(policyInfo); } BillingPriceVO billingPriceVO = billingPriceVOList.get(0); // String equipmentOwnerId = ""; // if (StringUtils.isNotBlank(organizationCode) && organizationCode.length() == 18) { // equipmentOwnerId = StringUtils.substring(organizationCode, organizationCode.length() - 10, organizationCode.length() - 1); // }else { // equipmentOwnerId = Constants.OPERATORID_JIANG_SU; // } // 封装参数 pricePolicyInfo.setEquipBizID(Constants.OPERATORID_JIANG_SU + billingPriceVO.getTemplateCode()); // 计费策略ID pricePolicyInfo.setValidStat(1); // 执行状态 pricePolicyInfo.setValidStartTime(billingPriceVO.getPublishTime()); // 生效时间 pricePolicyInfo.setValidEndTime("2099-12-31 23:59:59"); // 失效时间 pricePolicyInfo.setSumPeriod(policyInfoList.size()); // 时段数 pricePolicyInfo.setPolicyInfos(policyInfoList); pricePolicyInfos.add(pricePolicyInfo); chargePolicyInfo.setConnectorID(pileConnectorCode); chargePolicyInfo.setPricePolicyInfos(pricePolicyInfos); chargePolicyInfos.add(chargePolicyInfo); params.setEquipBizSeq(equipBizSeq); params.setSumChargePolicyInfos(pricePolicyInfos.size()); params.setChargePolicyInfos(chargePolicyInfos); 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; } /** * 请求启动充电 * 只需传枪口号、充电金额即可 * @param dto * @return QueryStartChargeVO */ 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 orderCode = IdUtils.getOrderCode(); String startChargeSeq = Constants.OPERATORID_JIANG_SU + "_C" + orderCode; QueryStartChargeDTO startChargeDTO = new QueryStartChargeDTO(); startChargeDTO.setOperatorId(dto.getOperatorId()); startChargeDTO.setStartChargeSeq(startChargeSeq); startChargeDTO.setConnectorID(dto.getConnectorID()); startChargeDTO.setAccountBalance(dto.getMoneyLimit()); Map map = orderBasicInfoService.generateOrderForThirdParty(startChargeDTO); if (map == null) { log.error("华为平台生成订单 error"); throw new BusinessException(ReturnCodeEnum.CODE_GENERATE_ORDER_ERROR); } // 拼装参数 JSONObject jsonObject = new JSONObject(); jsonObject.put("StartChargeSeq", startChargeSeq); 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 response = sendRequest2HuaWei(strData, signSecret, requestUrl); CommonResult commonResult = JSONObject.parseObject(response, CommonResult.class); if (commonResult.getRet() != 0) { log.error("解析华为请求启动充电接口result error:{}, ", commonResult.getMsg()); 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); return vo; } /** * 接收启动充电结果 */ public void receiveStartChargeResult(ReceiveStartChargeResultDTO dto) { String startChargeSeq = dto.getStartChargeSeq(); Integer startChargeSeqStat = dto.getStartChargeSeqStat(); // 充电订单状态 Integer failReason = dto.getFailReason(); String startTime = dto.getStartTime(); // 根据订单号查询订单信息 OrderBasicInfo orderBasicInfo = orderBasicInfoService.getOrderInfoByOrderCode(startChargeSeq); // 判断订单状态 if (startChargeSeqStat == Constants.two) { // 充电中 orderBasicInfo.setOrderStatus(OrderStatusEnum.IN_THE_CHARGING.getValue()); // 设置开始时间 orderBasicInfo.setChargeStartTime(DateUtils.parseDate(startTime)); orderBasicInfoService.updateOrderBasicInfo(orderBasicInfo); } if (failReason != 0) { // 启动失败, 将失败原因换成中文 String reason = StartFailedReasonEnum.getReasonByCode(failReason); // 给用户退款(执行0x33中启动失败的操作流程) orderBasicInfoService.chargingPileFailedToStart(orderBasicInfo.getTransactionCode(), reason); } } /** * 查询充电状态 * @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"; // 拼装参数 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 response = sendRequest2HuaWei(strData, signSecret, requestUrl); CommonResult commonResult = JSONObject.parseObject(response, CommonResult.class); if (commonResult.getRet() != 0) { log.error("解析查询华为充电状态接口result error:{}, ", commonResult.getMsg()); return; } // 解密data byte[] plainText = Cryptos.aesDecrypt(Encodes.decodeBase64((String) commonResult.getData()), dataSecret.getBytes(), dataSecretIv.getBytes()); String dataStr = new String(plainText, StandardCharsets.UTF_8); // 转换成对应的对象 } /** * 获取华为配置信息 * @return */ private ThirdPartySettingInfo getHuaWeiSettingInfo() { // 通过华为的type查询出密钥配置 ThirdPartySettingInfo info = new ThirdPartySettingInfo(); info.setType(ThirdPlatformTypeEnum.HUA_WEI.getCode()); ThirdPartySettingInfo settingInfo = thirdPartySettingInfoService.selectSettingInfo(info); return settingInfo; } /** * 向华为发送请求 * @param strData 加密后的Data * @param signSecret 签名密钥 * @param requestUrl 请求url * @return 请求结果 */ private String sendRequest2HuaWei(String strData, String signSecret, String requestUrl) { Map 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 = HttpUtil.post(requestUrl, tokenRequest); return response; } /** * 获取桩列表 * @param stationId * @return */ private List getPileList(String stationId) { List equipmentLogicInfos = new ArrayList<>(); HWStationInfo .EquipmentLogicInfo equipmentLogicInfo = null; List pileBasicInfos = pileBasicInfoService.getPileListByStationId(stationId); if (CollectionUtils.isEmpty(pileBasicInfos)) { return new ArrayList<>(); } for (PileBasicInfo pileBasicInfo : pileBasicInfos) { String pileSn = pileBasicInfo.getSn(); equipmentLogicInfo = HWStationInfo.EquipmentLogicInfo.builder() .equipmentId(pileSn) // .equipmentType() .chargeHostESN(pileSn) .build(); // 获取枪口信息 List connectorInfoList = getConnectorInfoList(pileSn); if (CollectionUtils.isEmpty(connectorInfoList)) { continue; } equipmentLogicInfo.setConnectorInfoNum(connectorInfoList.size()); equipmentLogicInfo.setConnectorInfos(connectorInfoList); equipmentLogicInfos.add(equipmentLogicInfo); } return equipmentLogicInfos; } /** * 获取枪口列表 * @param pileSn * @return */ private List getConnectorInfoList(String pileSn) { List connectorInfoList = new ArrayList<>(); HWStationInfo.EquipmentLogicInfo .ConnectorInfo connectorInfo = null; List pileConnectorInfos = pileConnectorInfoService.selectPileConnectorInfoList(pileSn); if (CollectionUtils.isEmpty(pileConnectorInfos)) { return new ArrayList<>(); } for (PileConnectorInfo pileConnectorInfo : pileConnectorInfos) { connectorInfo = HWStationInfo.EquipmentLogicInfo.ConnectorInfo.builder() .connectorID(pileConnectorInfo.getPileConnectorCode()) .connectorNumber(pileConnectorInfo.getId()) .build(); connectorInfoList.add(connectorInfo); } return connectorInfoList; } }