diff --git a/jsowell-admin/src/main/java/com/jsowell/service/MemberService.java b/jsowell-admin/src/main/java/com/jsowell/service/MemberService.java index 3e96f7ed4..1040c8da1 100644 --- a/jsowell-admin/src/main/java/com/jsowell/service/MemberService.java +++ b/jsowell-admin/src/main/java/com/jsowell/service/MemberService.java @@ -364,7 +364,7 @@ public class MemberService { } // walletLogVO.setTotalAccountAmount(walletLogVO.getPrincipalBalance().add(walletLogVO.getGiftBalance())); } - log.info("查询用户余额信息 service方法 开始处理分页----"); + // log.info("查询用户余额信息 service方法 开始处理分页----"); List collect = list.stream() .skip((pageNum - 1) * pageSize) .limit(pageSize) @@ -381,7 +381,7 @@ public class MemberService { .total(total) .build(); vo.setPageResponse(pageResponse); - log.info("查询用户余额信息 service方法 end"); + // log.info("查询用户余额信息 service方法 end"); return vo; } diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/vo/huawei/QueryEquipAuthVO.java b/jsowell-pile/src/main/java/com/jsowell/pile/vo/huawei/QueryEquipAuthVO.java new file mode 100644 index 000000000..fd17f05aa --- /dev/null +++ b/jsowell-pile/src/main/java/com/jsowell/pile/vo/huawei/QueryEquipAuthVO.java @@ -0,0 +1,26 @@ +package com.jsowell.pile.vo.huawei; + +import com.alibaba.fastjson2.annotation.JSONField; +import lombok.Data; + +/** + * 请求设备认证VO + * + * @author Lemon + * @Date 2024/1/22 15:53:06 + */ +@Data +public class QueryEquipAuthVO { + + @JSONField(name = "EquipAuthSeq") + private String equipAuthSeq; + + @JSONField(name = "ConnectorID") + private String connectorID; + + @JSONField(name = "SuccStat") + private Integer succStat; + + @JSONField(name = "FailReason") + private Integer failReason; +} diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/huawei/HuaweiServiceV2.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/huawei/HuaweiServiceV2.java index e289693f6..fe9422887 100644 --- a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/huawei/HuaweiServiceV2.java +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/huawei/HuaweiServiceV2.java @@ -3,20 +3,21 @@ 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.util.DateUtils; import com.jsowell.common.util.StringUtils; +import com.jsowell.common.util.id.IdUtils; import com.jsowell.pile.domain.PileBasicInfo; import com.jsowell.pile.domain.PileConnectorInfo; +import com.jsowell.pile.domain.ThirdPartyPlatformConfig; import com.jsowell.pile.domain.ThirdPartySettingInfo; import com.jsowell.pile.domain.huawei.HWStationInfo; import com.jsowell.pile.dto.PushStationInfoDTO; -import com.jsowell.pile.service.PileBasicInfoService; -import com.jsowell.pile.service.PileConnectorInfoService; -import com.jsowell.pile.service.PileStationInfoService; -import com.jsowell.pile.service.ThirdPartySettingInfoService; +import com.jsowell.pile.service.*; +import com.jsowell.pile.vo.huawei.QueryEquipAuthVO; import com.jsowell.pile.vo.web.PileStationVO; import com.jsowell.thirdparty.lianlian.common.CommonResult; import com.jsowell.thirdparty.lianlian.domain.ConnectorStatusInfo; @@ -57,6 +58,9 @@ public class HuaweiServiceV2 { @Autowired private ThirdPartySettingInfoService thirdPartySettingInfoService; + @Autowired + private ThirdPartyPlatformConfigService thirdPartyPlatformConfigService; + @Autowired private RedisCache redisCache; @@ -179,11 +183,10 @@ public class HuaweiServiceV2 { * @return */ public List queryStationStatus(List stationIds) { - // 通过华为的type查询出密钥配置 - ThirdPartySettingInfo info = new ThirdPartySettingInfo(); - info.setType(ThirdPlatformTypeEnum.HUA_WEI.getCode()); - ThirdPartySettingInfo settingInfo = thirdPartySettingInfoService.selectSettingInfo(info); - + ThirdPartySettingInfo settingInfo = getHuaWeiSettingInfo(); + if (settingInfo == null) { + return null; + } String operatorSecret = settingInfo.getOperatorSecret(); String dataSecret = settingInfo.getDataSecret(); String dataSecretIv = settingInfo.getDataSecretIv(); @@ -220,12 +223,97 @@ public class HuaweiServiceV2 { } - + /** + * 接收设备接口状态变化推送 + * 需在Controller传入operatorId + * + * @param connectorStatusInfo + * @return + */ public Map receiveNotificationStationStatus(ConnectorStatusInfo connectorStatusInfo) { - return null; + 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; } + 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; + } + + /** + * 获取华为配置信息 + * @return + */ + private ThirdPartySettingInfo getHuaWeiSettingInfo() { + // 通过华为的type查询出密钥配置 + ThirdPartySettingInfo info = new ThirdPartySettingInfo(); + info.setType(ThirdPlatformTypeEnum.HUA_WEI.getCode()); + ThirdPartySettingInfo settingInfo = thirdPartySettingInfoService.selectSettingInfo(info); + return settingInfo; + } /** * 向华为发送请求 @@ -250,8 +338,11 @@ public class HuaweiServiceV2 { } - - + /** + * 获取桩列表 + * @param stationId + * @return + */ private List getPileList(String stationId) { List equipmentLogicInfos = new ArrayList<>(); @@ -283,6 +374,11 @@ public class HuaweiServiceV2 { return equipmentLogicInfos; } + /** + * 获取枪口列表 + * @param pileSn + * @return + */ private List getConnectorInfoList(String pileSn) { List connectorInfoList = new ArrayList<>(); diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/lianlian/domain/ConnectorStatusInfo.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/lianlian/domain/ConnectorStatusInfo.java index f60ec7762..79e4cc283 100644 --- a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/lianlian/domain/ConnectorStatusInfo.java +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/lianlian/domain/ConnectorStatusInfo.java @@ -42,4 +42,8 @@ public class ConnectorStatusInfo { * 地锁状态(0-未知;10-已解锁;50-占用) N */ private String LockStatus; + + + + private String operatorId; }