diff --git a/jsowell-admin/src/main/java/com/jsowell/lianlian/LianLianController.java b/jsowell-admin/src/main/java/com/jsowell/lianlian/LianLianController.java index 122fb3ecc..f5dc8d49c 100644 --- a/jsowell-admin/src/main/java/com/jsowell/lianlian/LianLianController.java +++ b/jsowell-admin/src/main/java/com/jsowell/lianlian/LianLianController.java @@ -237,22 +237,62 @@ public class LianLianController extends BaseController { * @param dto * @return */ - @PostMapping("/query_equip_auth") - public RestApiResponse query_equip_auth(@RequestBody QueryEquipmentDTO dto) { - logger.info("联联平台请求设备认证 params :{}", JSONObject.toJSONString(dto)); - RestApiResponse response; + // @PostMapping("/query_equip_auth") + // public RestApiResponse query_equip_auth(@RequestBody QueryEquipmentDTO dto) { + // logger.info("联联平台请求设备认证 params :{}", JSONObject.toJSONString(dto)); + // RestApiResponse response; + // try { + // EquipmentAuthVO equipmentAuthVO = lianLianService.query_equip_auth(dto); + // response = new RestApiResponse<>(equipmentAuthVO); + // }catch (BusinessException e) { + // logger.error("联联平台请求设备认证 error",e); + // response = new RestApiResponse<>(e.getCode(), e.getMessage()); + // } catch (Exception e) { + // logger.error("联联平台请求设备认证 error", e); + // response = new RestApiResponse<>(e); + // } + // logger.info("联联平台请求设备认证 result :{}", response); + // return response; + // } + + /** + * 请求设备认证 + * @param request + * @param dto + * @return + */ + @PostMapping("/v1/query_equip_auth") + public CommonResult query_equip_auth(HttpServletRequest request, @RequestBody CommonParamsDTO dto) { + logger.info("联联平台请求设备认证 param:{}", JSONObject.toJSONString(dto)); try { - EquipmentAuthVO equipmentAuthVO = lianLianService.query_equip_auth(dto); - response = new RestApiResponse<>(equipmentAuthVO); - }catch (BusinessException e) { - logger.error("联联平台请求设备认证 error",e); - response = new RestApiResponse<>(e.getCode(), e.getMessage()); + // 校验令牌 + String token = request.getHeader("Authorization"); + if (!JWTUtils.checkThirdPartyToken(token)) { + // 校验失败 + return CommonResult.failed("令牌校验错误"); + } + // 校验签名 + Map resultMap = lianLianService.checkoutSign(dto); + if (resultMap == null) { + // 签名错误 + return CommonResult.failed("签名校验错误"); + } + String operatorSecret = resultMap.get("OperatorSecret"); + String dataString = resultMap.get("Data"); + // 解密data + byte[] plainText = Cryptos.aesDecrypt(Encodes.decodeBase64(dataString), operatorSecret.getBytes(), operatorSecret.getBytes()); + String dataStr = new String(plainText, "UTF-8"); + // 转换成相应对象 + QueryEquipmentDTO queryEquipmentDTO = JSONObject.parseObject(dataStr, QueryEquipmentDTO.class); + queryEquipmentDTO.setOperatorID(dto.getOperatorID()); + Map map = lianLianService.query_equip_auth(queryEquipmentDTO); + + return CommonResult.success(0, "请求设备认证成功!", map.get("Data"), map.get("Sig")); } catch (Exception e) { - logger.error("联联平台请求设备认证 error", e); - response = new RestApiResponse<>(e); + logger.info("联联平台请求设备认证 error:", e); + e.printStackTrace(); } - logger.info("联联平台请求设备认证 result :{}", response); - return response; + return CommonResult.failed("请求设备认证发生异常"); } /** diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/dto/QueryEquipmentDTO.java b/jsowell-pile/src/main/java/com/jsowell/pile/dto/QueryEquipmentDTO.java index 587697ea6..b2fc0f30d 100644 --- a/jsowell-pile/src/main/java/com/jsowell/pile/dto/QueryEquipmentDTO.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/dto/QueryEquipmentDTO.java @@ -24,4 +24,7 @@ public class QueryEquipmentDTO { */ @JsonProperty(value = "ConnectorID") private String ConnectorID; + + @JsonProperty(value = "OperatorID") + private String OperatorID; } diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/lianlian/service/LianLianService.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/lianlian/service/LianLianService.java index 17519a186..be1102bca 100644 --- a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/lianlian/service/LianLianService.java +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/lianlian/service/LianLianService.java @@ -53,7 +53,7 @@ public interface LianLianService { * @param dto * @return */ - EquipmentAuthVO query_equip_auth(QueryEquipmentDTO dto); + Map query_equip_auth(QueryEquipmentDTO dto); /** * 请求开始充电 diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/lianlian/service/impl/LianLianServiceImpl.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/lianlian/service/impl/LianLianServiceImpl.java index 3de1e1e2d..527a9654b 100644 --- a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/lianlian/service/impl/LianLianServiceImpl.java +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/lianlian/service/impl/LianLianServiceImpl.java @@ -492,7 +492,7 @@ public class LianLianServiceImpl implements LianLianService { * @return */ @Override - public EquipmentAuthVO query_equip_auth(QueryEquipmentDTO dto) { + public Map query_equip_auth(QueryEquipmentDTO dto) { EquipmentAuthVO vo = new EquipmentAuthVO(); String equipAuthSeq = dto.getEquipAuthSeq(); @@ -506,7 +506,11 @@ public class LianLianServiceImpl implements LianLianService { if (pileBasicInfo == null) { vo.setFailReason(2); // 设备检测失败 vo.setFailReasonMsg("未查到该桩的数据"); - throw new BusinessException("", ""); + return null; + } + DockingPlatformConfig configInfo = dockingPlatformConfigService.getInfoByOperatorId(dto.getOperatorID()); + if (configInfo == null) { + return null; } if (pileBasicInfo.getMerchantId() == Long.parseLong(merchantId)) { vo.setSuccStat(0); @@ -526,7 +530,19 @@ public class LianLianServiceImpl implements LianLianService { vo.setEquipAuthSeq(equipAuthSeq); vo.setConnectorID(pileConnectorCode); - return vo; + // 加密 + Map resultMap = Maps.newLinkedHashMap(); + // 加密数据 + byte[] encryptText = Cryptos.aesEncrypt(JSONObject.toJSONString(vo).getBytes(), + configInfo.getOperatorSecret().getBytes(), configInfo.getDataSecretIv().getBytes()); + String encryptData = Encodes.encodeBase64(encryptText); + + resultMap.put("Data", encryptData); + // 生成sig + String resultSign = GBSignUtils.sign(resultMap, configInfo.getOperatorSecret()); + resultMap.put("Sig", resultSign); + + return resultMap; } diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/lianlian/vo/LianLianPageResponse.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/lianlian/vo/LianLianPageResponse.java deleted file mode 100644 index ffc963a3e..000000000 --- a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/lianlian/vo/LianLianPageResponse.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.jsowell.thirdparty.lianlian.vo; - -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; - -import java.io.Serializable; -import java.util.List; - -/** - * 联联平台分页反参 - * - * @author JS-ZZA - * @date 2023/4/10 15:24 - */ -@Data -@NoArgsConstructor -@AllArgsConstructor -@Builder -public class LianLianPageResponse implements Serializable { - - private static final long serialVersionUID = -8425633122529553009L; - /** - * 当前页数 - */ - private int PageNo; - - /** - * 页码总数 - */ - private int PageCount; - - /** - * 总记录条数 - */ - private int ItemSize; - - /** - * 数据集合 - */ - private List list; -}