From b9276166e8179d2771ca4e5ba753259b44b4905e Mon Sep 17 00:00:00 2001 From: Guoqs Date: Mon, 1 Apr 2024 16:30:50 +0800 Subject: [PATCH] update --- .../lianlian/LianLianController.java | 19 +++--- .../service/LianLianPlatformServiceImpl.java | 60 +++++++++++++++++++ 2 files changed, 70 insertions(+), 9 deletions(-) diff --git a/jsowell-admin/src/main/java/com/jsowell/web/controller/thirdparty/lianlian/LianLianController.java b/jsowell-admin/src/main/java/com/jsowell/web/controller/thirdparty/lianlian/LianLianController.java index 56ec1f35f..2aab1e31c 100644 --- a/jsowell-admin/src/main/java/com/jsowell/web/controller/thirdparty/lianlian/LianLianController.java +++ b/jsowell-admin/src/main/java/com/jsowell/web/controller/thirdparty/lianlian/LianLianController.java @@ -351,6 +351,7 @@ public class LianLianController extends BaseController { /** * 请求设备认证 + * * @param request * @param dto * @return @@ -360,11 +361,11 @@ public class LianLianController extends BaseController { logger.info("联联平台请求设备认证 param:{}", JSON.toJSONString(dto)); try { // 校验令牌 - String token = request.getHeader("Authorization"); - if (!JWTUtils.checkThirdPartyToken(token)) { - // 校验失败 - return CommonResult.failed("令牌校验错误"); - } + // String token = request.getHeader("Authorization"); + // if (!JWTUtils.checkThirdPartyToken(token)) { + // // 校验失败 + // return CommonResult.failed("令牌校验错误"); + // } // 校验签名 // Map resultMap = lianLianService.checkoutSign(dto); // if (resultMap == null) { @@ -384,8 +385,9 @@ public class LianLianController extends BaseController { String dataSecretIV = platformConfig.getDataSecretIv(); // 解密data - byte[] plainText = Cryptos.aesDecrypt(Encodes.decodeBase64(dataString), dataSecret.getBytes(), dataSecretIV.getBytes()); - String dataStr = new String(plainText, StandardCharsets.UTF_8); + // byte[] plainText = Cryptos.aesDecrypt(Encodes.decodeBase64(dataString), dataSecret.getBytes(), dataSecretIV.getBytes()); + // String dataStr = new String(plainText, StandardCharsets.UTF_8); + String dataStr = Cryptos.decrypt(dto.getData(), dataSecret, dataSecretIV); // 转换成相应对象 QueryEquipmentDTO queryEquipmentDTO = JSONObject.parseObject(dataStr, QueryEquipmentDTO.class); queryEquipmentDTO.setOperatorID(dto.getOperatorID()); @@ -394,8 +396,7 @@ public class LianLianController extends BaseController { return CommonResult.success(0, "请求设备认证成功!", map.get("Data"), map.get("Sig")); } catch (Exception e) { - logger.info("联联平台请求设备认证 error:", e); - e.printStackTrace(); + logger.error("联联平台请求设备认证 error:", e); } return CommonResult.failed("请求设备认证发生异常"); } diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/lianlian/service/LianLianPlatformServiceImpl.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/lianlian/service/LianLianPlatformServiceImpl.java index 89282c6f6..a895d77af 100644 --- a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/lianlian/service/LianLianPlatformServiceImpl.java +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/lianlian/service/LianLianPlatformServiceImpl.java @@ -21,6 +21,7 @@ import com.jsowell.common.util.PageUtils; import com.jsowell.common.util.StringUtils; import com.jsowell.pile.domain.*; import com.jsowell.pile.dto.PushOrderSettlementDTO; +import com.jsowell.pile.dto.QueryEquipmentDTO; import com.jsowell.pile.dto.QueryStationInfoDTO; import com.jsowell.pile.service.*; import com.jsowell.pile.thirdparty.CommonParamsDTO; @@ -29,11 +30,14 @@ import com.jsowell.pile.vo.base.*; import com.jsowell.pile.vo.lianlian.AccumulativeInfoVO; import com.jsowell.pile.vo.lianlian.PushStationFeeVO; import com.jsowell.pile.vo.uniapp.BillingPriceVO; +import com.jsowell.pile.vo.web.PileConnectorInfoVO; import com.jsowell.pile.vo.web.PileStationVO; import com.jsowell.thirdparty.lianlian.domain.*; import com.jsowell.thirdparty.lianlian.vo.AccessTokenVO; +import com.jsowell.thirdparty.lianlian.vo.EquipmentAuthVO; import com.jsowell.thirdparty.platform.ThirdPartyPlatformService; 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 org.apache.commons.collections4.CollectionUtils; @@ -896,4 +900,60 @@ public class LianLianPlatformServiceImpl implements ThirdPartyPlatformService { return resultMap; } + /** + * 请求设备认证 + * + * @param dto + * @return + */ + @Override + public Map queryEquipAuth(QueryEquipmentDTO dto) { + Map 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; + } + // 根据桩编号查询数据 + // String merchantId = StringUtils.substring(equipAuthSeq, 0, 9); + String pileSn = StringUtils.substring(pileConnectorCode, 0, 14); + vo.setSuccStat(1); // 1-失败 0-成功 默认失败 + PileBasicInfo pileBasicInfo = pileBasicInfoService.selectPileBasicInfoBySN(pileSn); + if (pileBasicInfo != null) { + // 查询当前枪口数据 + PileConnectorInfoVO connectorInfo = pileConnectorInfoService.getPileConnectorInfoByConnectorCode(pileConnectorCode); + if (StringUtils.equals(PileConnectorDataBaseStatusEnum.OCCUPIED_NOT_CHARGED.getValue(), String.valueOf(connectorInfo.getStatus())) + || StringUtils.equals(PileConnectorDataBaseStatusEnum.OCCUPIED_CHARGING.getValue(), String.valueOf(connectorInfo.getStatus())) + || StringUtils.equals(PileConnectorDataBaseStatusEnum.OCCUPIED_APPOINTMENT_LOCK.getValue(), String.valueOf(connectorInfo.getStatus())) + ) { + vo.setSuccStat(0); + vo.setFailReason(0); + } else { + vo.setSuccStat(1); + vo.setFailReason(1); // 1- 此设备尚未插枪; + } + vo.setFailReasonMsg(""); + vo.setEquipAuthSeq(equipAuthSeq); + vo.setConnectorID(pileConnectorCode); + } else { + vo.setFailReason(2); // 设备检测失败 + 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); + + return resultMap; + } + }