diff --git a/jsowell-admin/src/main/java/com/jsowell/api/thirdparty/HuaWeiController.java b/jsowell-admin/src/main/java/com/jsowell/api/thirdparty/HuaWeiController.java index d17be1ed5..1653d8ad9 100644 --- a/jsowell-admin/src/main/java/com/jsowell/api/thirdparty/HuaWeiController.java +++ b/jsowell-admin/src/main/java/com/jsowell/api/thirdparty/HuaWeiController.java @@ -1,31 +1,31 @@ package com.jsowell.api.thirdparty; - -import com.alibaba.fastjson2.JSON; -import com.alibaba.fastjson2.JSONObject; +// +// import com.alibaba.fastjson2.JSON; +// import com.alibaba.fastjson2.JSONObject; import com.jsowell.common.annotation.Anonymous; -import com.jsowell.common.core.controller.BaseController; +// import com.jsowell.common.core.controller.BaseController; import com.jsowell.common.enums.thirdparty.ThirdPlatformTypeEnum; -import com.jsowell.common.util.JWTUtils; -import com.jsowell.pile.dto.QueryEquipChargeStatusDTO; -import com.jsowell.pile.dto.QueryEquipmentDTO; -import com.jsowell.pile.dto.QueryStartChargeDTO; -import com.jsowell.pile.dto.QueryStationInfoDTO; -import com.jsowell.thirdparty.huawei.HuaWeiService; -import com.jsowell.thirdparty.lianlian.common.CommonResult; -import com.jsowell.pile.thirdparty.CommonParamsDTO; -import com.jsowell.thirdparty.platform.util.Cryptos; -import com.jsowell.thirdparty.platform.util.Encodes; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; +// import com.jsowell.common.util.JWTUtils; +// import com.jsowell.pile.dto.QueryEquipChargeStatusDTO; +// import com.jsowell.pile.dto.QueryEquipmentDTO; +// import com.jsowell.pile.dto.QueryStartChargeDTO; +// import com.jsowell.pile.dto.QueryStationInfoDTO; +// import com.jsowell.thirdparty.huawei.HuaWeiService; +// import com.jsowell.thirdparty.lianlian.common.CommonResult; +// import com.jsowell.pile.thirdparty.CommonParamsDTO; +// import com.jsowell.thirdparty.platform.util.Cryptos; +// import com.jsowell.thirdparty.platform.util.Encodes; +// import org.springframework.beans.factory.annotation.Autowired; +// import org.springframework.web.bind.annotation.PostMapping; +// import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; - -import javax.servlet.http.HttpServletRequest; -import java.io.UnsupportedEncodingException; -import java.nio.charset.StandardCharsets; -import java.util.Map; - +// +// import javax.servlet.http.HttpServletRequest; +// import java.io.UnsupportedEncodingException; +// import java.nio.charset.StandardCharsets; +// import java.util.Map; +// /** * 华为 Controller * @@ -37,279 +37,279 @@ import java.util.Map; @RequestMapping("/huawei") @Deprecated public class HuaWeiController extends ThirdPartyBaseController { - - private final String platformName = "华为平台"; - - private final String platformType = ThirdPlatformTypeEnum.HUA_WEI.getTypeCode(); - - @Autowired - private HuaWeiService huaWeiService; - - /** - * 获取token接口 - * http://localhost:8080/huawei/v1/query_token - */ - @PostMapping("/v1/query_token") - public CommonResult queryToken(@RequestBody CommonParamsDTO dto) { - logger.info("华为平台请求令牌 params:{}", JSON.toJSONString(dto)); - try { - Map map = huaWeiService.generateToken(dto); - logger.info("华为平台请求令牌 result:{}", JSON.toJSONString(map)); - return CommonResult.success(0, "请求令牌成功!", map.get("Data"), map.get("Sig")); - } catch (UnsupportedEncodingException e) { - logger.error("获取token接口 异常"); - return CommonResult.failed("获取token发生异常"); - } - } - - - /** - * 查询充电站信息 - * @param dto - */ - @RequestMapping("/v1/query_stations_info") - public CommonResult query_stations_info(HttpServletRequest request, @RequestBody CommonParamsDTO dto) { - logger.info("华为平台查询充电站信息 params:{}", JSON.toJSONString(dto)); - try { - // 校验令牌 - String token = request.getHeader("Authorization"); - if (!JWTUtils.checkThirdPartyToken(token)) { - // 校验失败 - return CommonResult.failed("令牌校验错误"); - } - // 校验签名 - Map resultMap = huaWeiService.checkoutSign(dto); - if (resultMap == null) { - // 签名错误 - return CommonResult.failed("签名校验错误"); - } - String operatorSecret = resultMap.get("OperatorSecret"); - String dataString = resultMap.get("Data"); - String dataSecret = resultMap.get("DataSecret"); - String dataSecretIV = resultMap.get("DataSecretIV"); - // 解密data - byte[] plainText = Cryptos.aesDecrypt(Encodes.decodeBase64(dataString), dataSecret.getBytes(), dataSecretIV.getBytes()); - String dataStr = new String(plainText, StandardCharsets.UTF_8); - // 转换成相应对象 - QueryStationInfoDTO queryStationInfoDTO = JSONObject.parseObject(dataStr, QueryStationInfoDTO.class); - queryStationInfoDTO.setOperatorId(dto.getOperatorID()); - Map map = huaWeiService.queryStationsInfo(queryStationInfoDTO); - return CommonResult.success(0, "查询充电站信息成功!", map.get("Data"), map.get("Sig")); - } catch (Exception e) { - logger.error("华为平台查询充电站信息 error", e); - } - return CommonResult.failed("查询充电站信息异常"); - } - - /** - * 华为平台查询统计信息 - * http://localhost:8080/huawei/v1/query_stations_stats - * @param dto - * @return - */ - @PostMapping("/v1/query_station_status") - public CommonResult queryStationStatus(HttpServletRequest request, @RequestBody CommonParamsDTO dto) { - logger.info("华为平台查询统计信息 params:{}", JSON.toJSONString(dto)); - try { - // 校验令牌 - String token = request.getHeader("Authorization"); - if (!JWTUtils.checkThirdPartyToken(token)) { - // 校验失败 - return CommonResult.failed("令牌校验错误"); - } - // 校验签名 - Map resultMap = huaWeiService.checkoutSign(dto); - if (resultMap == null) { - // 签名错误 - return CommonResult.failed("签名校验错误"); - } - String operatorSecret = resultMap.get("OperatorSecret"); - String dataString = resultMap.get("Data"); - String dataSecret = resultMap.get("DataSecret"); - String dataSecretIV = resultMap.get("DataSecretIV"); - - // 解密data - byte[] plainText = Cryptos.aesDecrypt(Encodes.decodeBase64(dataString), dataSecret.getBytes(), dataSecretIV.getBytes()); - String dataStr = new String(plainText, StandardCharsets.UTF_8); - // 转换成相应对象 - QueryStationInfoDTO queryStationInfoDTO = JSONObject.parseObject(dataStr, QueryStationInfoDTO.class); - queryStationInfoDTO.setOperatorId(dto.getOperatorID()); - Map map = huaWeiService.queryStationStatus(queryStationInfoDTO); - logger.info("华为平台查询统计信息 result:{}", JSON.toJSONString(map)); - return CommonResult.success(0, "查询统计信息成功!", map.get("Data"), map.get("Sig")); - } catch (Exception e) { - logger.info("华为平台查询统计信息 error:", e); - e.printStackTrace(); - } - return CommonResult.failed("查询统计信息发生异常"); - } - - - /** - * 请求设备认证 - * @param request - * @param dto - * @return - */ - @PostMapping("/v1/query_equip_auth") - public CommonResult query_equip_auth(HttpServletRequest request, @RequestBody CommonParamsDTO dto) { - logger.info("华为平台请求设备认证 param:{}", JSON.toJSONString(dto)); - try { - // 校验令牌 - String token = request.getHeader("Authorization"); - if (!JWTUtils.checkThirdPartyToken(token)) { - // 校验失败 - return CommonResult.failed("令牌校验错误"); - } - // 校验签名 - Map resultMap = huaWeiService.checkoutSign(dto); - if (resultMap == null) { - // 签名错误 - return CommonResult.failed("签名校验错误"); - } - String operatorSecret = resultMap.get("OperatorSecret"); - String dataString = resultMap.get("Data"); - String dataSecret = resultMap.get("DataSecret"); - String dataSecretIV = resultMap.get("DataSecretIV"); - // 解密data - byte[] plainText = Cryptos.aesDecrypt(Encodes.decodeBase64(dataString), dataSecret.getBytes(), dataSecretIV.getBytes()); - String dataStr = new String(plainText, StandardCharsets.UTF_8); - // 转换成相应对象 - QueryEquipmentDTO queryEquipmentDTO = JSONObject.parseObject(dataStr, QueryEquipmentDTO.class); - queryEquipmentDTO.setOperatorID(dto.getOperatorID()); - Map map = huaWeiService.queryEquipAuth(queryEquipmentDTO); - logger.info("华为平台请求设备认证 result:{}", JSON.toJSONString(map)); - return CommonResult.success(0, "请求设备认证成功!", map.get("Data"), map.get("Sig")); - } catch (Exception e) { - logger.info("华为平台请求设备认证 error:", e); - e.printStackTrace(); - } - return CommonResult.failed("请求设备认证发生异常"); - } - - /** - * 华为平台请求计费策略 - * http://localhost:8080/huawei/v1/query_equip_business_policy - * @param dto - * @return - */ - @PostMapping("/v1/request_equip_business_policy") - public CommonResult requestEquipBusinessPolicy(HttpServletRequest request, @RequestBody CommonParamsDTO dto) { - logger.info("华为平台请求计费策略 params:{}", JSON.toJSONString(dto)); - try { - // 校验令牌 - String token = request.getHeader("Authorization"); - if (!JWTUtils.checkThirdPartyToken(token)) { - // 校验失败 - return CommonResult.failed("令牌校验错误"); - } - // 校验签名 - Map resultMap = huaWeiService.checkoutSign(dto); - if (resultMap == null) { - // 签名错误 - return CommonResult.failed("签名校验错误"); - } - String operatorSecret = resultMap.get("OperatorSecret"); - String dataString = resultMap.get("Data"); - String dataSecret = resultMap.get("DataSecret"); - String dataSecretIV = resultMap.get("DataSecretIV"); - - // 解密data - byte[] plainText = Cryptos.aesDecrypt(Encodes.decodeBase64(dataString), dataSecret.getBytes(), dataSecretIV.getBytes()); - String dataStr = new String(plainText, StandardCharsets.UTF_8); - // 转换成相应对象 - QueryStartChargeDTO queryStartChargeDTO = JSONObject.parseObject(dataStr, QueryStartChargeDTO.class); - queryStartChargeDTO.setOperatorId(dto.getOperatorID()); - Map map = huaWeiService.requestEquipBusinessPolicy(queryStartChargeDTO); - logger.info("华为平台请求计费策略 result:{}", JSON.toJSONString(map)); - - return CommonResult.success(0, "请求计费策略成功!", map.get("Data"), map.get("Sig")); - } catch (Exception e) { - logger.info("华为平台请求计费策略 error:", e); - e.printStackTrace(); - } - return CommonResult.failed("请求计费策略发生异常"); - } - - /** - * 查询充电状态 - * http://localhost:8080/huawei/query_equip_charge_status/{startChargeSeq} - * @param dto - * @return - */ - @PostMapping("/v1/query_equip_charge_status") - public CommonResult query_equip_charge_status(HttpServletRequest request, @RequestBody CommonParamsDTO dto) { - logger.info("华为平台查询充电状态 params :{}", JSON.toJSONString(dto)); - try { - // 校验令牌 - String token = request.getHeader("Authorization"); - if (!JWTUtils.checkThirdPartyToken(token)) { - // 校验失败 - return CommonResult.failed("令牌校验错误"); - } - // 校验签名 - Map resultMap = huaWeiService.checkoutSign(dto); - if (resultMap == null) { - // 签名错误 - return CommonResult.failed("签名校验错误"); - } - String operatorSecret = resultMap.get("OperatorSecret"); - String dataString = resultMap.get("Data"); - String dataSecret = resultMap.get("DataSecret"); - String dataSecretIV = resultMap.get("DataSecretIV"); - // 解密data - byte[] plainText = Cryptos.aesDecrypt(Encodes.decodeBase64(dataString), dataSecret.getBytes(), dataSecretIV.getBytes()); - String dataStr = new String(plainText, StandardCharsets.UTF_8); - // 转换成相应对象 - QueryEquipChargeStatusDTO queryEquipChargeStatusDTO = JSONObject.parseObject(dataStr, QueryEquipChargeStatusDTO.class); - queryEquipChargeStatusDTO.setOperatorID(dto.getOperatorID()); - Map map = huaWeiService.queryEquipChargeStatus(queryEquipChargeStatusDTO); - logger.info("华为平台查询充电状态 result:{}", JSON.toJSONString(map)); - return CommonResult.success(0, "查询充电状态成功!", map.get("Data"), map.get("Sig")); - } catch (Exception e) { - logger.error("华为平台查询充电状态 error", e); - } - return CommonResult.failed("华为平台查询充电状态发生异常"); - } - - /** - * 请求停止充电 - * @param request - * @param dto - * @return - */ - @PostMapping("/v1/query_stop_charge") - public CommonResult query_stop_charge(HttpServletRequest request, @RequestBody CommonParamsDTO dto) { - logger.info("华为平台请求停止充电 params :{}", JSON.toJSONString(dto)); - try { - // 校验令牌 - String token = request.getHeader("Authorization"); - if (!JWTUtils.checkThirdPartyToken(token)) { - // 校验失败 - return CommonResult.failed("令牌校验错误"); - } - // 校验签名 - Map resultMap = huaWeiService.checkoutSign(dto); - if (resultMap == null) { - // 签名错误 - return CommonResult.failed("签名校验错误"); - } - String operatorSecret = resultMap.get("OperatorSecret"); - String dataString = resultMap.get("Data"); - String dataSecret = resultMap.get("DataSecret"); - String dataSecretIV = resultMap.get("DataSecretIV"); - // 解密data - byte[] plainText = Cryptos.aesDecrypt(Encodes.decodeBase64(dataString), dataSecret.getBytes(), dataSecretIV.getBytes()); - String dataStr = new String(plainText, StandardCharsets.UTF_8); - // 转换成相应对象 - QueryStartChargeDTO queryStartChargeDTO = JSONObject.parseObject(dataStr, QueryStartChargeDTO.class); - queryStartChargeDTO.setOperatorId(dto.getOperatorID()); - Map map = huaWeiService.queryStopCharge(queryStartChargeDTO); - logger.info("华为平台请求停止充电 result:{}", JSON.toJSONString(map)); - return CommonResult.success(0, "请求停止充电成功!", map.get("Data"), map.get("Sig")); - } catch (Exception e) { - logger.error("华为平台请求停止充电 error", e); - } - return CommonResult.failed("华为平台请求停止充电发生异常"); - } +// +// private final String platformName = "华为平台"; +// +// private final String platformType = ThirdPlatformTypeEnum.HUA_WEI.getTypeCode(); +// +// @Autowired +// private HuaWeiService huaWeiService; +// +// /** +// * 获取token接口 +// * http://localhost:8080/huawei/v1/query_token +// */ +// @PostMapping("/v1/query_token") +// public CommonResult queryToken(@RequestBody CommonParamsDTO dto) { +// logger.info("华为平台请求令牌 params:{}", JSON.toJSONString(dto)); +// try { +// Map map = huaWeiService.generateToken(dto); +// logger.info("华为平台请求令牌 result:{}", JSON.toJSONString(map)); +// return CommonResult.success(0, "请求令牌成功!", map.get("Data"), map.get("Sig")); +// } catch (UnsupportedEncodingException e) { +// logger.error("获取token接口 异常"); +// return CommonResult.failed("获取token发生异常"); +// } +// } +// +// +// /** +// * 查询充电站信息 +// * @param dto +// */ +// @RequestMapping("/v1/query_stations_info") +// public CommonResult query_stations_info(HttpServletRequest request, @RequestBody CommonParamsDTO dto) { +// logger.info("华为平台查询充电站信息 params:{}", JSON.toJSONString(dto)); +// try { +// // 校验令牌 +// String token = request.getHeader("Authorization"); +// if (!JWTUtils.checkThirdPartyToken(token)) { +// // 校验失败 +// return CommonResult.failed("令牌校验错误"); +// } +// // 校验签名 +// Map resultMap = huaWeiService.checkoutSign(dto); +// if (resultMap == null) { +// // 签名错误 +// return CommonResult.failed("签名校验错误"); +// } +// String operatorSecret = resultMap.get("OperatorSecret"); +// String dataString = resultMap.get("Data"); +// String dataSecret = resultMap.get("DataSecret"); +// String dataSecretIV = resultMap.get("DataSecretIV"); +// // 解密data +// byte[] plainText = Cryptos.aesDecrypt(Encodes.decodeBase64(dataString), dataSecret.getBytes(), dataSecretIV.getBytes()); +// String dataStr = new String(plainText, StandardCharsets.UTF_8); +// // 转换成相应对象 +// QueryStationInfoDTO queryStationInfoDTO = JSONObject.parseObject(dataStr, QueryStationInfoDTO.class); +// queryStationInfoDTO.setOperatorId(dto.getOperatorID()); +// Map map = huaWeiService.queryStationsInfo(queryStationInfoDTO); +// return CommonResult.success(0, "查询充电站信息成功!", map.get("Data"), map.get("Sig")); +// } catch (Exception e) { +// logger.error("华为平台查询充电站信息 error", e); +// } +// return CommonResult.failed("查询充电站信息异常"); +// } +// +// /** +// * 华为平台查询统计信息 +// * http://localhost:8080/huawei/v1/query_stations_stats +// * @param dto +// * @return +// */ +// @PostMapping("/v1/query_station_status") +// public CommonResult queryStationStatus(HttpServletRequest request, @RequestBody CommonParamsDTO dto) { +// logger.info("华为平台查询统计信息 params:{}", JSON.toJSONString(dto)); +// try { +// // 校验令牌 +// String token = request.getHeader("Authorization"); +// if (!JWTUtils.checkThirdPartyToken(token)) { +// // 校验失败 +// return CommonResult.failed("令牌校验错误"); +// } +// // 校验签名 +// Map resultMap = huaWeiService.checkoutSign(dto); +// if (resultMap == null) { +// // 签名错误 +// return CommonResult.failed("签名校验错误"); +// } +// String operatorSecret = resultMap.get("OperatorSecret"); +// String dataString = resultMap.get("Data"); +// String dataSecret = resultMap.get("DataSecret"); +// String dataSecretIV = resultMap.get("DataSecretIV"); +// +// // 解密data +// byte[] plainText = Cryptos.aesDecrypt(Encodes.decodeBase64(dataString), dataSecret.getBytes(), dataSecretIV.getBytes()); +// String dataStr = new String(plainText, StandardCharsets.UTF_8); +// // 转换成相应对象 +// QueryStationInfoDTO queryStationInfoDTO = JSONObject.parseObject(dataStr, QueryStationInfoDTO.class); +// queryStationInfoDTO.setOperatorId(dto.getOperatorID()); +// Map map = huaWeiService.queryStationStatus(queryStationInfoDTO); +// logger.info("华为平台查询统计信息 result:{}", JSON.toJSONString(map)); +// return CommonResult.success(0, "查询统计信息成功!", map.get("Data"), map.get("Sig")); +// } catch (Exception e) { +// logger.info("华为平台查询统计信息 error:", e); +// e.printStackTrace(); +// } +// return CommonResult.failed("查询统计信息发生异常"); +// } +// +// +// /** +// * 请求设备认证 +// * @param request +// * @param dto +// * @return +// */ +// @PostMapping("/v1/query_equip_auth") +// public CommonResult query_equip_auth(HttpServletRequest request, @RequestBody CommonParamsDTO dto) { +// logger.info("华为平台请求设备认证 param:{}", JSON.toJSONString(dto)); +// try { +// // 校验令牌 +// String token = request.getHeader("Authorization"); +// if (!JWTUtils.checkThirdPartyToken(token)) { +// // 校验失败 +// return CommonResult.failed("令牌校验错误"); +// } +// // 校验签名 +// Map resultMap = huaWeiService.checkoutSign(dto); +// if (resultMap == null) { +// // 签名错误 +// return CommonResult.failed("签名校验错误"); +// } +// String operatorSecret = resultMap.get("OperatorSecret"); +// String dataString = resultMap.get("Data"); +// String dataSecret = resultMap.get("DataSecret"); +// String dataSecretIV = resultMap.get("DataSecretIV"); +// // 解密data +// byte[] plainText = Cryptos.aesDecrypt(Encodes.decodeBase64(dataString), dataSecret.getBytes(), dataSecretIV.getBytes()); +// String dataStr = new String(plainText, StandardCharsets.UTF_8); +// // 转换成相应对象 +// QueryEquipmentDTO queryEquipmentDTO = JSONObject.parseObject(dataStr, QueryEquipmentDTO.class); +// queryEquipmentDTO.setOperatorID(dto.getOperatorID()); +// Map map = huaWeiService.queryEquipAuth(queryEquipmentDTO); +// logger.info("华为平台请求设备认证 result:{}", JSON.toJSONString(map)); +// return CommonResult.success(0, "请求设备认证成功!", map.get("Data"), map.get("Sig")); +// } catch (Exception e) { +// logger.info("华为平台请求设备认证 error:", e); +// e.printStackTrace(); +// } +// return CommonResult.failed("请求设备认证发生异常"); +// } +// +// /** +// * 华为平台请求计费策略 +// * http://localhost:8080/huawei/v1/query_equip_business_policy +// * @param dto +// * @return +// */ +// @PostMapping("/v1/request_equip_business_policy") +// public CommonResult requestEquipBusinessPolicy(HttpServletRequest request, @RequestBody CommonParamsDTO dto) { +// logger.info("华为平台请求计费策略 params:{}", JSON.toJSONString(dto)); +// try { +// // 校验令牌 +// String token = request.getHeader("Authorization"); +// if (!JWTUtils.checkThirdPartyToken(token)) { +// // 校验失败 +// return CommonResult.failed("令牌校验错误"); +// } +// // 校验签名 +// Map resultMap = huaWeiService.checkoutSign(dto); +// if (resultMap == null) { +// // 签名错误 +// return CommonResult.failed("签名校验错误"); +// } +// String operatorSecret = resultMap.get("OperatorSecret"); +// String dataString = resultMap.get("Data"); +// String dataSecret = resultMap.get("DataSecret"); +// String dataSecretIV = resultMap.get("DataSecretIV"); +// +// // 解密data +// byte[] plainText = Cryptos.aesDecrypt(Encodes.decodeBase64(dataString), dataSecret.getBytes(), dataSecretIV.getBytes()); +// String dataStr = new String(plainText, StandardCharsets.UTF_8); +// // 转换成相应对象 +// QueryStartChargeDTO queryStartChargeDTO = JSONObject.parseObject(dataStr, QueryStartChargeDTO.class); +// queryStartChargeDTO.setOperatorId(dto.getOperatorID()); +// Map map = huaWeiService.requestEquipBusinessPolicy(queryStartChargeDTO); +// logger.info("华为平台请求计费策略 result:{}", JSON.toJSONString(map)); +// +// return CommonResult.success(0, "请求计费策略成功!", map.get("Data"), map.get("Sig")); +// } catch (Exception e) { +// logger.info("华为平台请求计费策略 error:", e); +// e.printStackTrace(); +// } +// return CommonResult.failed("请求计费策略发生异常"); +// } +// +// /** +// * 查询充电状态 +// * http://localhost:8080/huawei/query_equip_charge_status/{startChargeSeq} +// * @param dto +// * @return +// */ +// @PostMapping("/v1/query_equip_charge_status") +// public CommonResult query_equip_charge_status(HttpServletRequest request, @RequestBody CommonParamsDTO dto) { +// logger.info("华为平台查询充电状态 params :{}", JSON.toJSONString(dto)); +// try { +// // 校验令牌 +// String token = request.getHeader("Authorization"); +// if (!JWTUtils.checkThirdPartyToken(token)) { +// // 校验失败 +// return CommonResult.failed("令牌校验错误"); +// } +// // 校验签名 +// Map resultMap = huaWeiService.checkoutSign(dto); +// if (resultMap == null) { +// // 签名错误 +// return CommonResult.failed("签名校验错误"); +// } +// String operatorSecret = resultMap.get("OperatorSecret"); +// String dataString = resultMap.get("Data"); +// String dataSecret = resultMap.get("DataSecret"); +// String dataSecretIV = resultMap.get("DataSecretIV"); +// // 解密data +// byte[] plainText = Cryptos.aesDecrypt(Encodes.decodeBase64(dataString), dataSecret.getBytes(), dataSecretIV.getBytes()); +// String dataStr = new String(plainText, StandardCharsets.UTF_8); +// // 转换成相应对象 +// QueryEquipChargeStatusDTO queryEquipChargeStatusDTO = JSONObject.parseObject(dataStr, QueryEquipChargeStatusDTO.class); +// queryEquipChargeStatusDTO.setOperatorID(dto.getOperatorID()); +// Map map = huaWeiService.queryEquipChargeStatus(queryEquipChargeStatusDTO); +// logger.info("华为平台查询充电状态 result:{}", JSON.toJSONString(map)); +// return CommonResult.success(0, "查询充电状态成功!", map.get("Data"), map.get("Sig")); +// } catch (Exception e) { +// logger.error("华为平台查询充电状态 error", e); +// } +// return CommonResult.failed("华为平台查询充电状态发生异常"); +// } +// +// /** +// * 请求停止充电 +// * @param request +// * @param dto +// * @return +// */ +// @PostMapping("/v1/query_stop_charge") +// public CommonResult query_stop_charge(HttpServletRequest request, @RequestBody CommonParamsDTO dto) { +// logger.info("华为平台请求停止充电 params :{}", JSON.toJSONString(dto)); +// try { +// // 校验令牌 +// String token = request.getHeader("Authorization"); +// if (!JWTUtils.checkThirdPartyToken(token)) { +// // 校验失败 +// return CommonResult.failed("令牌校验错误"); +// } +// // 校验签名 +// Map resultMap = huaWeiService.checkoutSign(dto); +// if (resultMap == null) { +// // 签名错误 +// return CommonResult.failed("签名校验错误"); +// } +// String operatorSecret = resultMap.get("OperatorSecret"); +// String dataString = resultMap.get("Data"); +// String dataSecret = resultMap.get("DataSecret"); +// String dataSecretIV = resultMap.get("DataSecretIV"); +// // 解密data +// byte[] plainText = Cryptos.aesDecrypt(Encodes.decodeBase64(dataString), dataSecret.getBytes(), dataSecretIV.getBytes()); +// String dataStr = new String(plainText, StandardCharsets.UTF_8); +// // 转换成相应对象 +// QueryStartChargeDTO queryStartChargeDTO = JSONObject.parseObject(dataStr, QueryStartChargeDTO.class); +// queryStartChargeDTO.setOperatorId(dto.getOperatorID()); +// Map map = huaWeiService.queryStopCharge(queryStartChargeDTO); +// logger.info("华为平台请求停止充电 result:{}", JSON.toJSONString(map)); +// return CommonResult.success(0, "请求停止充电成功!", map.get("Data"), map.get("Sig")); +// } catch (Exception e) { +// logger.error("华为平台请求停止充电 error", e); +// } +// return CommonResult.failed("华为平台请求停止充电发生异常"); +// } } diff --git a/jsowell-admin/src/main/java/com/jsowell/api/thirdparty/HuaWeiControllerV2.java b/jsowell-admin/src/main/java/com/jsowell/api/thirdparty/HuaWeiControllerV2.java index 136d0357e..a5c4364ae 100644 --- a/jsowell-admin/src/main/java/com/jsowell/api/thirdparty/HuaWeiControllerV2.java +++ b/jsowell-admin/src/main/java/com/jsowell/api/thirdparty/HuaWeiControllerV2.java @@ -1,33 +1,33 @@ package com.jsowell.api.thirdparty; - -import com.alibaba.fastjson2.JSON; -import com.alibaba.fastjson2.JSONObject; +// +// import com.alibaba.fastjson2.JSON; +// import com.alibaba.fastjson2.JSONObject; import com.jsowell.common.annotation.Anonymous; import com.jsowell.common.core.controller.BaseController; -import com.jsowell.common.response.RestApiResponse; -import com.jsowell.common.util.JWTUtils; -import com.jsowell.pile.dto.ThirdPartyCommonStartChargeDTO; -import com.jsowell.pile.dto.huawei.*; -import com.jsowell.pile.vo.huawei.QueryChargeStatusVO; -import com.jsowell.pile.vo.huawei.QueryEquipAuthVO; -import com.jsowell.pile.vo.huawei.QueryStartChargeVO; -import com.jsowell.thirdparty.common.CommonService; -import com.jsowell.thirdparty.huawei.HuaweiServiceV2; -import com.jsowell.thirdparty.lianlian.common.CommonResult; -import com.jsowell.thirdparty.lianlian.domain.ConnectorStatusInfo; -import com.jsowell.pile.thirdparty.CommonParamsDTO; -import com.jsowell.thirdparty.platform.util.Cryptos; -import com.jsowell.thirdparty.platform.util.Encodes; -import org.springframework.beans.factory.annotation.Autowired; +// import com.jsowell.common.response.RestApiResponse; +// import com.jsowell.common.util.JWTUtils; +// import com.jsowell.pile.dto.ThirdPartyCommonStartChargeDTO; +// import com.jsowell.pile.dto.huawei.*; +// import com.jsowell.pile.vo.huawei.QueryChargeStatusVO; +// import com.jsowell.pile.vo.huawei.QueryEquipAuthVO; +// import com.jsowell.pile.vo.huawei.QueryStartChargeVO; +// import com.jsowell.thirdparty.common.CommonService; +// import com.jsowell.thirdparty.huawei.HuaweiServiceV2; +// import com.jsowell.thirdparty.lianlian.common.CommonResult; +// import com.jsowell.thirdparty.lianlian.domain.ConnectorStatusInfo; +// import com.jsowell.pile.thirdparty.CommonParamsDTO; +// import com.jsowell.thirdparty.platform.util.Cryptos; +// import com.jsowell.thirdparty.platform.util.Encodes; +// import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; - -import javax.servlet.http.HttpServletRequest; -import java.io.UnsupportedEncodingException; -import java.nio.charset.StandardCharsets; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - +// +// import javax.servlet.http.HttpServletRequest; +// import java.io.UnsupportedEncodingException; +// import java.nio.charset.StandardCharsets; +// import java.util.LinkedHashMap; +// import java.util.List; +// import java.util.Map; +// /** * 华为 Controller V2 * @@ -39,362 +39,362 @@ import java.util.Map; @RequestMapping("/huawei") @Deprecated public class HuaWeiControllerV2 extends BaseController { - - @Autowired - private HuaweiServiceV2 huaweiServiceV2; - - @Autowired - private CommonService commonService; - - /** - * 获取token接口 - * http://localhost:8080/huawei/v1/query_token - */ - @PostMapping("/v2/query_token") - public CommonResult queryToken(@RequestBody CommonParamsDTO dto) { - logger.info("华为平台请求令牌 params:{}", JSON.toJSONString(dto)); - try { - Map map = huaweiServiceV2.generateToken(dto); - logger.info("华为平台请求令牌 result:{}", JSON.toJSONString(map)); - return CommonResult.success(0, "请求令牌成功!", map.get("Data"), map.get("Sig")); - } catch (UnsupportedEncodingException e) { - logger.error("获取token接口 异常"); - return CommonResult.failed("获取token发生异常"); - } - } - - /** - * 华为设备接口状态变化推送 - * @param dto - * @return - */ - @PostMapping("/v2/notification_stationStatus") - public CommonResult receiveNotificationStationStatus(HttpServletRequest request, @RequestBody CommonParamsDTO dto) { - logger.info("华为设备接口状态变化推送 params:{}", JSON.toJSONString(dto)); - String dataStr = checkAuth(request, dto); - // 转换成相应对象 - ConnectorStatusInfo connectorStatusInfo = JSONObject.parseObject(dataStr, ConnectorStatusInfo.class); - connectorStatusInfo.setOperatorId(dto.getOperatorID()); - Map map = huaweiServiceV2.receiveNotificationStationStatus(connectorStatusInfo); - logger.info("华为设备接口状态变化推送 result:{}", map); - return CommonResult.success(0, "设备接口状态变化推送成功!", map.get("Data"), map.get("Sig")); - } - - - /** - * 请求设备计费信息 - * @param request - * @param dto - * @return - */ - @PostMapping("/v2/request_equip_business_policy") - public CommonResult requestEquipBusinessPolicy(HttpServletRequest request, @RequestBody CommonParamsDTO dto) { - logger.info("华为请求设备计费信息 params:{}", JSON.toJSONString(dto)); - String dataStr = checkAuth(request, dto); - // 转换成相应对象 - RequestEquipBusinessPolicyDTO requestEquipBusinessPolicyDTO = JSONObject.parseObject(dataStr, RequestEquipBusinessPolicyDTO.class); - requestEquipBusinessPolicyDTO.setOperatorId(dto.getOperatorID()); - Map map = huaweiServiceV2.requestEquipBusinessPolicy(requestEquipBusinessPolicyDTO); - logger.info("华为请求设备计费信息 result:{}", map); - return CommonResult.success(0, "请求设备计费信息成功!", map.get("Data"), map.get("Sig")); - } - - - /** - * 接收启动充电结果 - * @param request - * @param dto - * @return - */ - @PostMapping("/v2/notification_start_charge_result") - public CommonResult receiveStartChargeResult(HttpServletRequest request, @RequestBody CommonParamsDTO dto) { - logger.info("接收华为启动充电结果 params:{}", JSON.toJSONString(dto)); - String dataStr = checkAuth(request, dto); - // 转换成相应对象 - ReceiveStartChargeResultDTO receiveStartChargeResultDTO = JSONObject.parseObject(dataStr, ReceiveStartChargeResultDTO.class); - // receiveStartChargeResultDTO.setOperatorId(dto.getOperatorID()); - Map map = huaweiServiceV2.receiveStartChargeResult(receiveStartChargeResultDTO); - logger.info("接收华为启动充电结果 result:{}", map); - return CommonResult.success(0, "推送启动充电结果成功!", map.get("Data"), map.get("Sig")); - } - - - /** - * 接收设备充电状态 - * @param request - * @param dto - * @return - */ - @PostMapping("/v2/notification_equip_charge_status") - public CommonResult receiveEquipChargeStatus(HttpServletRequest request, @RequestBody CommonParamsDTO dto) { - logger.info("接收华为设备充电状态 params:{}", JSON.toJSONString(dto)); - String dataStr = checkAuth(request, dto); - // 转换成相应对象 - ReceiveEquipChargeStatusDTO receiveEquipChargeStatusDTO = JSONObject.parseObject(dataStr, ReceiveEquipChargeStatusDTO.class); - // receiveEquipChargeStatusDTO.setOperatorId(dto.getOperatorID()); - Map map = huaweiServiceV2.receiveEquipChargeStatus(receiveEquipChargeStatusDTO); - logger.info("接收华为设备充电状态 result:{}", map); - return CommonResult.success(0, "接收设备充电状态成功!", map.get("Data"), map.get("Sig")); - } - - - /** - * 接收华为所推送的停止充电结果 - * @param request - * @param dto - * @return - */ - @PostMapping("/v2/notification_stop_charge_result") - public CommonResult receiveStopChargeResult(HttpServletRequest request, @RequestBody CommonParamsDTO dto) { - logger.info("接收华为停止充电结果 params:{}", JSON.toJSONString(dto)); - String dataStr = checkAuth(request, dto); - // 转换成相应对象 - ReceiveStopChargeResultVO receiveStopChargeResultVO = JSONObject.parseObject(dataStr, ReceiveStopChargeResultVO.class); - // receiveStopChargeResultVO.setOperatorId(dto.getOperatorID()); - Map map = huaweiServiceV2.receiveStopChargeResult(receiveStopChargeResultVO); - logger.info("接收华为停止充电结果 result:{}", map); - return CommonResult.success(0, "接收停止充电结果成功!", map.get("Data"), map.get("Sig")); - } - - /** - * 接收订单信息 - * @param request - * @param dto - * @return - */ - @PostMapping("/v2/notification_charge_order_info") - public CommonResult receiveOrderInfo(HttpServletRequest request, @RequestBody CommonParamsDTO dto) { - logger.info("接收华为订单信息 params:{}", JSON.toJSONString(dto)); - String dataStr = checkAuth(request, dto); - // 转换成相应对象 - ReceiveOrderInfoDTO receiveOrderInfoDTO = JSONObject.parseObject(dataStr, ReceiveOrderInfoDTO.class); - // receiveOrderInfoDTO.setOperatorId(dto.getOperatorID()); - Map map = huaweiServiceV2.receiveOrderInfo(receiveOrderInfoDTO); - logger.info("接收华为订单信息 result:{}", map); - return CommonResult.success(0, "接收订单信息成功!", map.get("Data"), map.get("Sig")); - } - - /** - * vin启动充电 - * @param request - * @param dto - * @return - */ - @PostMapping("/v2/insert_start_charge") - public CommonResult vinStartCharge(HttpServletRequest request, @RequestBody CommonParamsDTO dto) { - logger.info("华为vin启动充电 params:{}", JSON.toJSONString(dto)); - String dataStr = checkAuth(request, dto); - // 转换成相应对象 - VinStartChargeDTO vinStartChargeDTO = JSONObject.parseObject(dataStr, VinStartChargeDTO.class); - // receiveOrderInfoDTO.setOperatorId(dto.getOperatorID()); - Map resultMap = null; - try { - resultMap = huaweiServiceV2.vinStartCharge(vinStartChargeDTO); - } catch (Exception e) { - logger.error("华为vin启动充电 error", e); - } - logger.info("华为vin启动充电 resultMap:{}", resultMap); - if (resultMap != null) { - return CommonResult.success(0, "vin启动充电结果", resultMap.get("Data"), resultMap.get("Sig")); - }else { - return CommonResult.failed("vin启动充电 error"); - } - } - - /** - * 下发计费策略响应 - * @param request - * @param dto - * @return - */ - @PostMapping("/v2/notification_deliver_equip_business_policy_result") - public CommonResult receiveDeliverEquipBusinessPolicyResult(HttpServletRequest request, @RequestBody CommonParamsDTO dto){ - logger.info("华为下发计费策略响应 params:{}", JSON.toJSONString(dto)); - String dataStr = checkAuth(request, dto); - // 转换成相应对象 - DeliverBusinessPolicyResponseDTO deliverPolicyResponseDTO = JSONObject.parseObject(dataStr, DeliverBusinessPolicyResponseDTO.class); - // receiveOrderInfoDTO.setOperatorId(dto.getOperatorID()); - Map map = huaweiServiceV2.receiveDeliverEquipBusinessPolicyResult(deliverPolicyResponseDTO); - logger.info("华为下发计费策略响应 result:{}", map); - return CommonResult.success(0, "接收下发计费策略响应信息成功!", map.get("Data"), map.get("Sig")); - } - - - // ======================== 以上为 华为 --> 万车充 ======================== - // ======================== 下面为 万车充 --> 华为 ======================== - - - /** - * 平台充电设备编码同步 - * @param stationId - * @return - */ - @GetMapping("/v2/notification_operation_system_info/{stationId}") - public RestApiResponse notificationOperationSystemInfo(@PathVariable("stationId") String stationId) { - // logger.info("华为平台充电设备编码同步 stationId:{}", stationId); - RestApiResponse response = null; - String result = null; - try { - result = huaweiServiceV2.notificationOperationSystemInfo(stationId); - response = new RestApiResponse<>(result); - } catch (Exception e) { - logger.error("华为平台充电设备编码同步 error", e); - } - logger.info("华为平台充电设备编码同步 stationId:{}, result:{}", stationId, result); - return response; - } - - /** - * 设备接口状态查询 - * @param stationIds - * @return - */ - @PostMapping("/v2/query_station_status") - public RestApiResponse queryStationStatus(@RequestBody List stationIds) { - // logger.info("查询华为设备接口状态 stationIds:{}", stationIds); - RestApiResponse response = null; - Map map = new LinkedHashMap<>(); - try { - map = huaweiServiceV2.queryStationStatus(stationIds); - response = new RestApiResponse<>(map); - } catch (Exception e) { - logger.error("查询华为设备接口状态 error", e); - } - logger.info("查询华为设备接口状态 stationIds:{}, result:{}", stationIds, map); - return response; - } - - /** - * 请求设备认证 - * @param connectorId - * @return - */ - @PostMapping("/v2/query_equip_auth") - public RestApiResponse queryEquipAuth(@RequestBody String connectorId) { - // logger.info("请求华为设备认证 connectorId:{}", connectorId); - RestApiResponse response = null; - QueryEquipAuthVO vo = null; - try { - vo = huaweiServiceV2.queryEquipAuth(connectorId); - response = new RestApiResponse<>(vo); - } catch (Exception e) { - logger.error("请求华为设备认证 error", e); - } - logger.info("请求华为设备认证 connectorId:{}, result:{}", connectorId, JSON.toJSONString(vo)); - return response; - } - - /** - * 请求启动充电 - * @param dto - * @return - */ - @PostMapping("/v2/query_start_charge") - public RestApiResponse queryStartCharge(@RequestBody HWQueryStartChargeDTO dto) { - // logger.info("请求华为启动充电 param:{}", JSON.toJSONString(dto)); - RestApiResponse response = null; - QueryStartChargeVO vo = null; - try { - vo = huaweiServiceV2.queryStartCharge(dto); - response = new RestApiResponse<>(vo); - } catch (Exception e) { - logger.error("请求华为启动充电 error", e); - } - logger.info("请求华为启动充电 param:{}, result:{}", JSON.toJSONString(dto), JSON.toJSONString(vo)); - return response; - } - - - /** - * 查询充电状态 - * @param startChargeSeq - * @return - */ - @PostMapping("/v2/query_equip_charge_status") - public RestApiResponse queryChargeStatus(@RequestBody String startChargeSeq) { - // logger.info("查询华为充电状态 startChargeSeq:{}", startChargeSeq); - RestApiResponse response = null; - QueryChargeStatusVO vo = null; - try { - vo = huaweiServiceV2.queryChargeStatus(startChargeSeq); - response = new RestApiResponse<>(vo); - } catch (Exception e) { - logger.error("查询华为充电状态 error", e); - } - logger.info("查询华为充电状态 startChargeSeq:{}, result:{}", startChargeSeq, JSON.toJSONString(vo)); - return response; - } - - - /** - * 请求停止充电 - * @param startChargeSeq - * @return - */ - @PostMapping("/v2/query_stop_charge") - public RestApiResponse queryStopCharge(@RequestBody String startChargeSeq) { - // logger.info("请求华为停止充电 startChargeSeq:{}", startChargeSeq); - RestApiResponse response = null; - QueryStartChargeVO vo = null; - try { - vo = huaweiServiceV2.queryStopCharge(startChargeSeq); - response = new RestApiResponse<>(vo); - }catch (Exception e) { - logger.error("请求华为停止充电 error", e); - } - logger.info("请求华为停止充电 startChargeSeq:{}, result:{}", startChargeSeq, JSON.toJSONString(vo)); - return response; - } - - - - @PostMapping("/commonStartCharge") - public RestApiResponse commonStartCharge(@RequestBody ThirdPartyCommonStartChargeDTO dto) { - RestApiResponse response = null; - try { - String result = commonService.commonQueryStartCharge(dto); - response = new RestApiResponse<>(result); - } catch (Exception e) { - logger.error("统一启动充电接口 error", e); - } - logger.info("统一启动充电接口 params:{}, result:{}", JSON.toJSONString(dto), response); - return response; - } - - - - - - /** - * 校验令牌 - * @param request - * @param dto - * @return - */ - private String checkAuth(HttpServletRequest request, CommonParamsDTO dto) { - // 校验令牌 - String token = request.getHeader("Authorization"); - if (!JWTUtils.checkThirdPartyToken(token)) { - // 校验失败 - logger.error("令牌校验错误"); - return null; - } - // 校验签名 - Map resultMap = huaweiServiceV2.checkoutSign(dto); - if (resultMap == null) { - // 签名错误 - logger.error("令牌校验错误"); - return null; - } - String operatorSecret = resultMap.get("OperatorSecret"); - String dataString = resultMap.get("Data"); - String dataSecret = resultMap.get("DataSecret"); - String dataSecretIV = resultMap.get("DataSecretIV"); - // 解密data - byte[] plainText = Cryptos.aesDecrypt(Encodes.decodeBase64(dataString), dataSecret.getBytes(), dataSecretIV.getBytes()); - String dataStr = new String(plainText, StandardCharsets.UTF_8); - return dataStr; - } - - +// +// @Autowired +// private HuaweiServiceV2 huaweiServiceV2; +// +// @Autowired +// private CommonService commonService; +// +// /** +// * 获取token接口 +// * http://localhost:8080/huawei/v1/query_token +// */ +// // @PostMapping("/v2/query_token") +// // public CommonResult queryToken(@RequestBody CommonParamsDTO dto) { +// // logger.info("华为平台请求令牌 params:{}", JSON.toJSONString(dto)); +// // try { +// // Map map = huaweiServiceV2.generateToken(dto); +// // logger.info("华为平台请求令牌 result:{}", JSON.toJSONString(map)); +// // return CommonResult.success(0, "请求令牌成功!", map.get("Data"), map.get("Sig")); +// // } catch (UnsupportedEncodingException e) { +// // logger.error("获取token接口 异常"); +// // return CommonResult.failed("获取token发生异常"); +// // } +// // } +// +// /** +// * 华为设备接口状态变化推送 +// * @param dto +// * @return +// */ +// @PostMapping("/v2/notification_stationStatus") +// public CommonResult receiveNotificationStationStatus(HttpServletRequest request, @RequestBody CommonParamsDTO dto) { +// logger.info("华为设备接口状态变化推送 params:{}", JSON.toJSONString(dto)); +// String dataStr = checkAuth(request, dto); +// // 转换成相应对象 +// ConnectorStatusInfo connectorStatusInfo = JSONObject.parseObject(dataStr, ConnectorStatusInfo.class); +// connectorStatusInfo.setOperatorId(dto.getOperatorID()); +// Map map = huaweiServiceV2.receiveNotificationStationStatus(connectorStatusInfo); +// logger.info("华为设备接口状态变化推送 result:{}", map); +// return CommonResult.success(0, "设备接口状态变化推送成功!", map.get("Data"), map.get("Sig")); +// } +// +// +// /** +// * 请求设备计费信息 +// * @param request +// * @param dto +// * @return +// */ +// @PostMapping("/v2/request_equip_business_policy") +// public CommonResult requestEquipBusinessPolicy(HttpServletRequest request, @RequestBody CommonParamsDTO dto) { +// logger.info("华为请求设备计费信息 params:{}", JSON.toJSONString(dto)); +// String dataStr = checkAuth(request, dto); +// // 转换成相应对象 +// RequestEquipBusinessPolicyDTO requestEquipBusinessPolicyDTO = JSONObject.parseObject(dataStr, RequestEquipBusinessPolicyDTO.class); +// requestEquipBusinessPolicyDTO.setOperatorId(dto.getOperatorID()); +// Map map = huaweiServiceV2.requestEquipBusinessPolicy(requestEquipBusinessPolicyDTO); +// logger.info("华为请求设备计费信息 result:{}", map); +// return CommonResult.success(0, "请求设备计费信息成功!", map.get("Data"), map.get("Sig")); +// } +// +// +// /** +// * 接收启动充电结果 +// * @param request +// * @param dto +// * @return +// */ +// @PostMapping("/v2/notification_start_charge_result") +// public CommonResult receiveStartChargeResult(HttpServletRequest request, @RequestBody CommonParamsDTO dto) { +// logger.info("接收华为启动充电结果 params:{}", JSON.toJSONString(dto)); +// String dataStr = checkAuth(request, dto); +// // 转换成相应对象 +// ReceiveStartChargeResultDTO receiveStartChargeResultDTO = JSONObject.parseObject(dataStr, ReceiveStartChargeResultDTO.class); +// // receiveStartChargeResultDTO.setOperatorId(dto.getOperatorID()); +// Map map = huaweiServiceV2.receiveStartChargeResult(receiveStartChargeResultDTO); +// logger.info("接收华为启动充电结果 result:{}", map); +// return CommonResult.success(0, "推送启动充电结果成功!", map.get("Data"), map.get("Sig")); +// } +// +// +// /** +// * 接收设备充电状态 +// * @param request +// * @param dto +// * @return +// */ +// @PostMapping("/v2/notification_equip_charge_status") +// public CommonResult receiveEquipChargeStatus(HttpServletRequest request, @RequestBody CommonParamsDTO dto) { +// logger.info("接收华为设备充电状态 params:{}", JSON.toJSONString(dto)); +// String dataStr = checkAuth(request, dto); +// // 转换成相应对象 +// ReceiveEquipChargeStatusDTO receiveEquipChargeStatusDTO = JSONObject.parseObject(dataStr, ReceiveEquipChargeStatusDTO.class); +// // receiveEquipChargeStatusDTO.setOperatorId(dto.getOperatorID()); +// Map map = huaweiServiceV2.receiveEquipChargeStatus(receiveEquipChargeStatusDTO); +// logger.info("接收华为设备充电状态 result:{}", map); +// return CommonResult.success(0, "接收设备充电状态成功!", map.get("Data"), map.get("Sig")); +// } +// +// +// /** +// * 接收华为所推送的停止充电结果 +// * @param request +// * @param dto +// * @return +// */ +// @PostMapping("/v2/notification_stop_charge_result") +// public CommonResult receiveStopChargeResult(HttpServletRequest request, @RequestBody CommonParamsDTO dto) { +// logger.info("接收华为停止充电结果 params:{}", JSON.toJSONString(dto)); +// String dataStr = checkAuth(request, dto); +// // 转换成相应对象 +// ReceiveStopChargeResultVO receiveStopChargeResultVO = JSONObject.parseObject(dataStr, ReceiveStopChargeResultVO.class); +// // receiveStopChargeResultVO.setOperatorId(dto.getOperatorID()); +// Map map = huaweiServiceV2.receiveStopChargeResult(receiveStopChargeResultVO); +// logger.info("接收华为停止充电结果 result:{}", map); +// return CommonResult.success(0, "接收停止充电结果成功!", map.get("Data"), map.get("Sig")); +// } +// +// /** +// * 接收订单信息 +// * @param request +// * @param dto +// * @return +// */ +// @PostMapping("/v2/notification_charge_order_info") +// public CommonResult receiveOrderInfo(HttpServletRequest request, @RequestBody CommonParamsDTO dto) { +// logger.info("接收华为订单信息 params:{}", JSON.toJSONString(dto)); +// String dataStr = checkAuth(request, dto); +// // 转换成相应对象 +// ReceiveOrderInfoDTO receiveOrderInfoDTO = JSONObject.parseObject(dataStr, ReceiveOrderInfoDTO.class); +// // receiveOrderInfoDTO.setOperatorId(dto.getOperatorID()); +// Map map = huaweiServiceV2.receiveOrderInfo(receiveOrderInfoDTO); +// logger.info("接收华为订单信息 result:{}", map); +// return CommonResult.success(0, "接收订单信息成功!", map.get("Data"), map.get("Sig")); +// } +// +// /** +// * vin启动充电 +// * @param request +// * @param dto +// * @return +// */ +// @PostMapping("/v2/insert_start_charge") +// public CommonResult vinStartCharge(HttpServletRequest request, @RequestBody CommonParamsDTO dto) { +// logger.info("华为vin启动充电 params:{}", JSON.toJSONString(dto)); +// String dataStr = checkAuth(request, dto); +// // 转换成相应对象 +// VinStartChargeDTO vinStartChargeDTO = JSONObject.parseObject(dataStr, VinStartChargeDTO.class); +// // receiveOrderInfoDTO.setOperatorId(dto.getOperatorID()); +// Map resultMap = null; +// try { +// resultMap = huaweiServiceV2.vinStartCharge(vinStartChargeDTO); +// } catch (Exception e) { +// logger.error("华为vin启动充电 error", e); +// } +// logger.info("华为vin启动充电 resultMap:{}", resultMap); +// if (resultMap != null) { +// return CommonResult.success(0, "vin启动充电结果", resultMap.get("Data"), resultMap.get("Sig")); +// }else { +// return CommonResult.failed("vin启动充电 error"); +// } +// } +// +// /** +// * 下发计费策略响应 +// * @param request +// * @param dto +// * @return +// */ +// @PostMapping("/v2/notification_deliver_equip_business_policy_result") +// public CommonResult receiveDeliverEquipBusinessPolicyResult(HttpServletRequest request, @RequestBody CommonParamsDTO dto){ +// logger.info("华为下发计费策略响应 params:{}", JSON.toJSONString(dto)); +// String dataStr = checkAuth(request, dto); +// // 转换成相应对象 +// DeliverBusinessPolicyResponseDTO deliverPolicyResponseDTO = JSONObject.parseObject(dataStr, DeliverBusinessPolicyResponseDTO.class); +// // receiveOrderInfoDTO.setOperatorId(dto.getOperatorID()); +// Map map = huaweiServiceV2.receiveDeliverEquipBusinessPolicyResult(deliverPolicyResponseDTO); +// logger.info("华为下发计费策略响应 result:{}", map); +// return CommonResult.success(0, "接收下发计费策略响应信息成功!", map.get("Data"), map.get("Sig")); +// } +// +// +// // ======================== 以上为 华为 --> 万车充 ======================== +// // ======================== 下面为 万车充 --> 华为 ======================== +// +// +// /** +// * 平台充电设备编码同步 +// * @param stationId +// * @return +// */ +// @GetMapping("/v2/notification_operation_system_info/{stationId}") +// public RestApiResponse notificationOperationSystemInfo(@PathVariable("stationId") String stationId) { +// // logger.info("华为平台充电设备编码同步 stationId:{}", stationId); +// RestApiResponse response = null; +// String result = null; +// try { +// result = huaweiServiceV2.notificationOperationSystemInfo(stationId); +// response = new RestApiResponse<>(result); +// } catch (Exception e) { +// logger.error("华为平台充电设备编码同步 error", e); +// } +// logger.info("华为平台充电设备编码同步 stationId:{}, result:{}", stationId, result); +// return response; +// } +// +// /** +// * 设备接口状态查询 +// * @param stationIds +// * @return +// */ +// @PostMapping("/v2/query_station_status") +// public RestApiResponse queryStationStatus(@RequestBody List stationIds) { +// // logger.info("查询华为设备接口状态 stationIds:{}", stationIds); +// RestApiResponse response = null; +// Map map = new LinkedHashMap<>(); +// try { +// map = huaweiServiceV2.queryStationStatus(stationIds); +// response = new RestApiResponse<>(map); +// } catch (Exception e) { +// logger.error("查询华为设备接口状态 error", e); +// } +// logger.info("查询华为设备接口状态 stationIds:{}, result:{}", stationIds, map); +// return response; +// } +// +// /** +// * 请求设备认证 +// * @param connectorId +// * @return +// */ +// @PostMapping("/v2/query_equip_auth") +// public RestApiResponse queryEquipAuth(@RequestBody String connectorId) { +// // logger.info("请求华为设备认证 connectorId:{}", connectorId); +// RestApiResponse response = null; +// QueryEquipAuthVO vo = null; +// try { +// vo = huaweiServiceV2.queryEquipAuth(connectorId); +// response = new RestApiResponse<>(vo); +// } catch (Exception e) { +// logger.error("请求华为设备认证 error", e); +// } +// logger.info("请求华为设备认证 connectorId:{}, result:{}", connectorId, JSON.toJSONString(vo)); +// return response; +// } +// +// /** +// * 请求启动充电 +// * @param dto +// * @return +// */ +// @PostMapping("/v2/query_start_charge") +// public RestApiResponse queryStartCharge(@RequestBody HWQueryStartChargeDTO dto) { +// // logger.info("请求华为启动充电 param:{}", JSON.toJSONString(dto)); +// RestApiResponse response = null; +// QueryStartChargeVO vo = null; +// try { +// vo = huaweiServiceV2.queryStartCharge(dto); +// response = new RestApiResponse<>(vo); +// } catch (Exception e) { +// logger.error("请求华为启动充电 error", e); +// } +// logger.info("请求华为启动充电 param:{}, result:{}", JSON.toJSONString(dto), JSON.toJSONString(vo)); +// return response; +// } +// +// +// /** +// * 查询充电状态 +// * @param startChargeSeq +// * @return +// */ +// @PostMapping("/v2/query_equip_charge_status") +// public RestApiResponse queryChargeStatus(@RequestBody String startChargeSeq) { +// // logger.info("查询华为充电状态 startChargeSeq:{}", startChargeSeq); +// RestApiResponse response = null; +// QueryChargeStatusVO vo = null; +// try { +// vo = huaweiServiceV2.queryChargeStatus(startChargeSeq); +// response = new RestApiResponse<>(vo); +// } catch (Exception e) { +// logger.error("查询华为充电状态 error", e); +// } +// logger.info("查询华为充电状态 startChargeSeq:{}, result:{}", startChargeSeq, JSON.toJSONString(vo)); +// return response; +// } +// +// +// /** +// * 请求停止充电 +// * @param startChargeSeq +// * @return +// */ +// @PostMapping("/v2/query_stop_charge") +// public RestApiResponse queryStopCharge(@RequestBody String startChargeSeq) { +// // logger.info("请求华为停止充电 startChargeSeq:{}", startChargeSeq); +// RestApiResponse response = null; +// QueryStartChargeVO vo = null; +// try { +// vo = huaweiServiceV2.queryStopCharge(startChargeSeq); +// response = new RestApiResponse<>(vo); +// }catch (Exception e) { +// logger.error("请求华为停止充电 error", e); +// } +// logger.info("请求华为停止充电 startChargeSeq:{}, result:{}", startChargeSeq, JSON.toJSONString(vo)); +// return response; +// } +// +// +// +// @PostMapping("/commonStartCharge") +// public RestApiResponse commonStartCharge(@RequestBody ThirdPartyCommonStartChargeDTO dto) { +// RestApiResponse response = null; +// try { +// String result = commonService.commonQueryStartCharge(dto); +// response = new RestApiResponse<>(result); +// } catch (Exception e) { +// logger.error("统一启动充电接口 error", e); +// } +// logger.info("统一启动充电接口 params:{}, result:{}", JSON.toJSONString(dto), response); +// return response; +// } +// +// +// +// +// +// /** +// * 校验令牌 +// * @param request +// * @param dto +// * @return +// */ +// private String checkAuth(HttpServletRequest request, CommonParamsDTO dto) { +// // 校验令牌 +// String token = request.getHeader("Authorization"); +// if (!JWTUtils.checkThirdPartyToken(token)) { +// // 校验失败 +// logger.error("令牌校验错误"); +// return null; +// } +// // 校验签名 +// Map resultMap = huaweiServiceV2.checkoutSign(dto); +// if (resultMap == null) { +// // 签名错误 +// logger.error("令牌校验错误"); +// return null; +// } +// String operatorSecret = resultMap.get("OperatorSecret"); +// String dataString = resultMap.get("Data"); +// String dataSecret = resultMap.get("DataSecret"); +// String dataSecretIV = resultMap.get("DataSecretIV"); +// // 解密data +// byte[] plainText = Cryptos.aesDecrypt(Encodes.decodeBase64(dataString), dataSecret.getBytes(), dataSecretIV.getBytes()); +// String dataStr = new String(plainText, StandardCharsets.UTF_8); +// return dataStr; +// } +// +// } diff --git a/jsowell-admin/src/test/java/SpringBootTestController.java b/jsowell-admin/src/test/java/SpringBootTestController.java index 8e17a496a..98ac85f29 100644 --- a/jsowell-admin/src/test/java/SpringBootTestController.java +++ b/jsowell-admin/src/test/java/SpringBootTestController.java @@ -3104,7 +3104,7 @@ public class SpringBootTestController { CommonParamsDTO dto = JSONObject.parseObject(tokenRequest, CommonParamsDTO.class); - lianLianService.generateToken(dto); + // lianLianService.generateToken(dto); } @Test diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/ThirdPartyPlatformConfigService.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/ThirdPartyPlatformConfigService.java index dcc089870..657d52d1a 100644 --- a/jsowell-pile/src/main/java/com/jsowell/pile/service/ThirdPartyPlatformConfigService.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/ThirdPartyPlatformConfigService.java @@ -65,5 +65,5 @@ public interface ThirdPartyPlatformConfigService { * @param operatorId * @return */ - ThirdPartyPlatformConfig getInfoByOperatorId(String operatorId); + // ThirdPartyPlatformConfig getInfoByOperatorId(String operatorId); } diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/ThirdPartyPlatformConfigServiceImpl.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/ThirdPartyPlatformConfigServiceImpl.java index 7fbb93f1b..279317078 100644 --- a/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/ThirdPartyPlatformConfigServiceImpl.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/ThirdPartyPlatformConfigServiceImpl.java @@ -95,10 +95,10 @@ public class ThirdPartyPlatformConfigServiceImpl implements ThirdPartyPlatformCo * @param operatorId * @return */ - @Override - public ThirdPartyPlatformConfig getInfoByOperatorId(String operatorId) { - return thirdPartyPlatformConfigMapper.getInfoByOperatorId(operatorId); - } + // @Override + // public ThirdPartyPlatformConfig getInfoByOperatorId(String operatorId) { + // return thirdPartyPlatformConfigMapper.getInfoByOperatorId(operatorId); + // } /** * 查询第三方平台配置的密钥信息 diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/huawei/HuaWeiService.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/huawei/HuaWeiService.java index 6efb78588..059ec2a5c 100644 --- a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/huawei/HuaWeiService.java +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/huawei/HuaWeiService.java @@ -30,13 +30,13 @@ public interface HuaWeiService { * @param dto * @return */ - Map generateToken(CommonParamsDTO dto) throws UnsupportedEncodingException; + // Map generateToken(CommonParamsDTO dto) throws UnsupportedEncodingException; /** * 校验签名 * @param dto */ - Map checkoutSign(CommonParamsDTO dto); + // Map checkoutSign(CommonParamsDTO dto); /** * 查询站点信息 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 83bdafc83..20bb0c0a6 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 @@ -17,7 +17,9 @@ import com.jsowell.common.enums.thirdparty.huawei.StartFailedReasonEnum; import com.jsowell.common.enums.thirdparty.huawei.StopFailedReasonEnum; import com.jsowell.common.enums.ykc.OrderStatusEnum; import com.jsowell.common.enums.ykc.PileConnectorDataBaseStatusEnum; +import com.jsowell.common.enums.ykc.ReturnCodeEnum; import com.jsowell.common.enums.ykc.StartModeEnum; +import com.jsowell.common.exception.BusinessException; import com.jsowell.common.util.DateUtils; import com.jsowell.common.util.StringUtils; import com.jsowell.common.util.Threads; @@ -33,6 +35,7 @@ import com.jsowell.pile.service.*; import com.jsowell.pile.service.programlogic.AbstractProgramLogic; import com.jsowell.pile.service.programlogic.ProgramLogicFactory; import com.jsowell.pile.thirdparty.CommonParamsDTO; +import com.jsowell.pile.vo.ThirdPartySecretInfoVO; import com.jsowell.pile.vo.huawei.QueryChargeStatusVO; import com.jsowell.pile.vo.huawei.QueryEquipAuthVO; import com.jsowell.pile.vo.huawei.QueryStartChargeVO; @@ -44,6 +47,8 @@ import com.jsowell.thirdparty.lianlian.service.LianLianService; 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.ThirdPartyPlatformUtils; +import com.jsowell.thirdparty.service.ThirdpartySecretInfoService; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.CollectionUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -85,10 +90,7 @@ public class HuaweiServiceV2 { private PileBasicInfoService pileBasicInfoService; @Autowired - private ThirdPartySettingInfoService thirdPartySettingInfoService; - - @Autowired - private ThirdPartyPlatformConfigService thirdPartyPlatformConfigService; + private ThirdpartySecretInfoService thirdpartySecretInfoService; @Autowired private PileBillingTemplateService pileBillingTemplateService; @@ -123,13 +125,13 @@ public class HuaweiServiceV2 { // 通过华为的type查询出密钥配置 ThirdPartySettingInfo info = new ThirdPartySettingInfo(); info.setType(ThirdPlatformTypeEnum.HUA_WEI.getTypeCode()); - ThirdPartySettingInfo settingInfo = thirdPartySettingInfoService.selectSettingInfo(info); + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getHuaWeiPlatformSecretInfo(); - String operatorSecret = settingInfo.getOperatorSecret(); - String dataSecret = settingInfo.getDataSecret(); - String dataSecretIv = settingInfo.getDataSecretIv(); - String signSecret = settingInfo.getSignSecret(); - String urlAddress = settingInfo.getUrlAddress(); + String operatorSecret = thirdPartySecretInfoVO.getTheirOperatorSecret(); + String dataSecret = thirdPartySecretInfoVO.getTheirDataSecret(); + String dataSecretIv = thirdPartySecretInfoVO.getTheirDataSecretIv(); + String signSecret = thirdPartySecretInfoVO.getTheirSigSecret(); + String urlAddress = thirdPartySecretInfoVO.getTheirUrlPrefix(); String requestUrl = urlAddress + "query_token"; @@ -177,13 +179,13 @@ public class HuaweiServiceV2 { return token; } - public Map generateToken(CommonParamsDTO dto) throws UnsupportedEncodingException { - return lianLianService.generateToken(dto); - } + // public Map generateToken(CommonParamsDTO dto) throws UnsupportedEncodingException { + // return lianLianService.generateToken(dto); + // } - public Map checkoutSign(CommonParamsDTO dto) { - return lianLianService.checkoutSign(dto); - } + // public Map checkoutSign(CommonParamsDTO dto) { + // return lianLianService.checkoutSign(dto); + // } /** * 平台充电设备编码同步 @@ -292,10 +294,10 @@ public class HuaweiServiceV2 { if (status != 0) { setPileAlive(pileSn); } - ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(connectorStatusInfo.getOperatorId()); - if (configInfo == null) { - return null; - } + // ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(connectorStatusInfo.getOperatorId()); + // if (configInfo == null) { + // return null; + // } // 将枪口状态改为对应的状态 pileConnectorInfoService.updateConnectorStatus(pileConnectorCode, String.valueOf(status)); // 构造返回参数 @@ -352,10 +354,11 @@ public class HuaweiServiceV2 { String pileConnectorCode = dto.getConnectorID(); String equipBizSeq = dto.getEquipBizSeq(); // 根据枪口号查询计费模板,并返回信息 - ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorId()); - if (configInfo == null) { - return null; - } + // ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorId()); + // if (configInfo == null) { + // return null; + // } + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getHuaWeiPlatformSecretInfo(); // 截取桩号 // String pileSn = StringUtils.substring(pileConnectorCode, 0, 14); String pileSn = YKCUtils.getPileSn(pileConnectorCode); @@ -387,17 +390,8 @@ public class HuaweiServiceV2 { 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); - + Map resultMap = ThirdPartyPlatformUtils.generateResultMapV2(resultJson, thirdPartySecretInfoVO.getOurDataSecret(), + thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret()); return resultMap; } @@ -882,10 +876,8 @@ public class HuaweiServiceV2 { * @throws Exception */ public Map vinStartCharge(VinStartChargeDTO dto) throws Exception { - ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorId()); - if (configInfo == null) { - return null; - } + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getHuaWeiPlatformSecretInfo(); + int succStat = Constants.one; // 操作结果 int failReason = Constants.one; // 失败原因 JSONObject jsonObject = new JSONObject(); @@ -1018,18 +1010,6 @@ public class HuaweiServiceV2 { } - /** - * 获取华为配置信息 - * @return - */ - private ThirdPartySettingInfo getHuaWeiSettingInfo() { - // 通过华为的type查询出密钥配置 - ThirdPartySettingInfo info = new ThirdPartySettingInfo(); - info.setType(ThirdPlatformTypeEnum.HUA_WEI.getTypeCode()); - ThirdPartySettingInfo settingInfo = thirdPartySettingInfoService.selectSettingInfo(info); - return settingInfo; - } - /** * 向华为发送请求 * @param jsonString 封装好的json请求参数 @@ -1039,27 +1019,25 @@ public class HuaweiServiceV2 { */ private String sendMsg2HuaWei(String jsonString, String token, String requestName) { log.info("向华为发送请求 jsonString:{}, token:{}, requestName:{}", jsonString, token, requestName); - ThirdPartySettingInfo settingInfo = getHuaWeiSettingInfo(); - if (settingInfo == null) { - return null; - } + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getHuaWeiPlatformSecretInfo(); + //加密 byte[] encryptText = Cryptos.aesEncrypt(jsonString.getBytes(), - settingInfo.getDataSecret().getBytes(), settingInfo.getDataSecretIv().getBytes()); + thirdPartySecretInfoVO.getTheirDataSecret().getBytes(), thirdPartySecretInfoVO.getTheirDataSecretIv().getBytes()); String encryptData = Encodes.encodeBase64(encryptText); Map params = Maps.newLinkedHashMap(); - params.put("OperatorID", settingInfo.getOperatorId()); + params.put("OperatorID", thirdPartySecretInfoVO.getTheirOperatorId()); params.put("Data", encryptData); params.put("TimeStamp", DateUtils.parseDateToStr(DateUtils.YYYYMMDDHHMMSS, new Date())); params.put("Seq", "001"); - String sign = GBSignUtils.sign(params, settingInfo.getSignSecret()); + String sign = GBSignUtils.sign(params, thirdPartySecretInfoVO.getTheirSigSecret()); params.put("Sig", sign); String postData = JSON.toJSONString(params); // 请求url - String requestUrl = settingInfo.getUrlAddress() + requestName; + String requestUrl = thirdPartySecretInfoVO.getTheirUrlPrefix() + requestName; String hutoolRequest = HttpRequest.post(requestUrl) .header("Authorization", "Bearer " + token) .body(postData).execute().body(); @@ -1080,7 +1058,7 @@ public class HuaweiServiceV2 { String rData = (String) map.get("Data"); // 解密 byte[] plainText = Cryptos.aesDecrypt(Encodes.decodeBase64(rData), - settingInfo.getDataSecret().getBytes(), settingInfo.getDataSecretIv().getBytes()); + thirdPartySecretInfoVO.getTheirDataSecret().getBytes(), thirdPartySecretInfoVO.getTheirDataSecretIv().getBytes()); String plainData = new String(plainText, StandardCharsets.UTF_8); return plainData; } @@ -1093,19 +1071,17 @@ public class HuaweiServiceV2 { private Map getResultMap(JSONObject jsonObject) { log.info("加密华为数据 jsonObject:{}", jsonObject.toJSONString()); String operatorId = ThirdPartyOperatorIdEnum.HUA_WEI.getOperatorId(); - ThirdPartyPlatformConfig platformConfig = thirdPartyPlatformConfigService.getInfoByOperatorId(operatorId); - if (platformConfig == null) { - return null; - } + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getHuaWeiPlatformSecretInfo(); + Map resultMap = Maps.newLinkedHashMap(); // 加密数据 byte[] encryptText = Cryptos.aesEncrypt(jsonObject.toJSONString().getBytes(), - platformConfig.getDataSecret().getBytes(), platformConfig.getDataSecretIv().getBytes()); + thirdPartySecretInfoVO.getOurDataSecret().getBytes(), thirdPartySecretInfoVO.getOurDataSecretIv().getBytes()); String encryptData = Encodes.encodeBase64(encryptText); resultMap.put("Data", encryptData); // 生成sig - String resultSign = GBSignUtils.sign(resultMap, platformConfig.getSignSecret()); + String resultSign = GBSignUtils.sign(resultMap, thirdPartySecretInfoVO.getOurSigSecret()); resultMap.put("Sig", resultSign); return resultMap; @@ -1212,5 +1188,20 @@ public class HuaweiServiceV2 { return connectorInfoList; } + /** + * 获取华为平台配置密钥信息 + * + * @return + */ + private ThirdPartySecretInfoVO getHuaWeiPlatformSecretInfo() { + // 通过第三方平台类型查询相关配置信息 + ThirdPartySecretInfoVO thirdPartySecretInfoVO = thirdpartySecretInfoService.queryByThirdPlatformType(ThirdPlatformTypeEnum.HUA_WEI.getTypeCode()); + if (thirdPartySecretInfoVO == null) { + throw new BusinessException(ReturnCodeEnum.CODE_SELECT_INFO_IS_NULL); + } + thirdPartySecretInfoVO.setOurOperatorId(Constants.OPERATORID_JIANG_SU); + return thirdPartySecretInfoVO; + } + } diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/huawei/impl/HuaWeiServiceImpl.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/huawei/impl/HuaWeiServiceImpl.java index d80f2827b..ec535d8f3 100644 --- a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/huawei/impl/HuaWeiServiceImpl.java +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/huawei/impl/HuaWeiServiceImpl.java @@ -4,6 +4,7 @@ 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.enums.thirdparty.ThirdPlatformTypeEnum; import com.jsowell.common.enums.ykc.ReturnCodeEnum; import com.jsowell.common.enums.ykc.StartModeEnum; import com.jsowell.common.exception.BusinessException; @@ -18,14 +19,13 @@ import com.jsowell.pile.dto.huawei.ReceiveDeliverDTO; import com.jsowell.pile.dto.huawei.VinStartChargeDTO; import com.jsowell.pile.service.*; import com.jsowell.pile.thirdparty.CommonParamsDTO; +import com.jsowell.pile.vo.ThirdPartySecretInfoVO; import com.jsowell.pile.vo.base.ThirdPartyStationRelationVO; import com.jsowell.pile.vo.uniapp.customer.BillingPriceVO; import com.jsowell.pile.vo.web.PileStationVO; import com.jsowell.thirdparty.huawei.HuaWeiService; -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 com.jsowell.thirdparty.platform.util.*; +import com.jsowell.thirdparty.service.ThirdpartySecretInfoService; import com.jsowell.thirdparty.zhongdianlian.dto.ZDLGetTokenDTO; import com.jsowell.thirdparty.zhongdianlian.service.ZDLService; import lombok.extern.slf4j.Slf4j; @@ -72,10 +72,7 @@ public class HuaWeiServiceImpl implements HuaWeiService { private ThirdPartyStationRelationService thirdPartyStationRelationService; @Autowired - private ThirdPartySettingInfoService thirdPartySettingInfoService; - - @Autowired - private PileMerchantInfoService pileMerchantInfoService; + private ThirdpartySecretInfoService thirdpartySecretInfoService; @Autowired private MemberPlateNumberRelationService memberPlateNumberRelationService; @@ -104,19 +101,19 @@ public class HuaWeiServiceImpl implements HuaWeiService { * @param dto * @return */ - @Override - public Map generateToken(CommonParamsDTO dto) throws UnsupportedEncodingException { - return zdlService.generateToken(dto); - } + // @Override + // public Map generateToken(CommonParamsDTO dto) throws UnsupportedEncodingException { + // return zdlService.generateToken(dto); + // } /** * 校验签名 * @param dto */ - @Override - public Map checkoutSign(CommonParamsDTO dto) { - return zdlService.checkoutSign(dto); - } + // @Override + // public Map checkoutSign(CommonParamsDTO dto) { + // return zdlService.checkoutSign(dto); + // } /** * 查询站点信息 @@ -273,10 +270,7 @@ public class HuaWeiServiceImpl implements HuaWeiService { String pileConnectorCode = dto.getConnectorID(); String equipBizSeq = dto.getEquipBizSeq(); // 根据枪口号查询计费模板,并返回信息 - ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorId()); - if (configInfo == null) { - return null; - } + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getHuaWeiPlatformSecretInfo(); // 截取桩号 // String pileSn = StringUtils.substring(pileConnectorCode, 0, 14); String pileSn = YKCUtils.getPileSn(pileConnectorCode); @@ -308,17 +302,8 @@ public class HuaWeiServiceImpl implements HuaWeiService { 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); - + Map resultMap = ThirdPartyPlatformUtils.generateResultMapV2(resultJson, thirdPartySecretInfoVO.getOurDataSecret(), + thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret()); return resultMap; } @@ -446,10 +431,8 @@ public class HuaWeiServiceImpl implements HuaWeiService { */ @Override public Map receiveDeliverEquipBusinessPolicyResult(ReceiveDeliverDTO dto) { - ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorId()); - if (configInfo == null) { - return null; - } + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getHuaWeiPlatformSecretInfo(); + List chargePolicyInfoRets = dto.getChargePolicyInfoRets(); // 将下发失败的进行筛选、收集 List failedList = chargePolicyInfoRets.stream() @@ -466,17 +449,8 @@ public class HuaWeiServiceImpl implements HuaWeiService { map.put("FailReason", 0); // 加密 - Map resultMap = Maps.newLinkedHashMap(); - // 加密数据 - byte[] encryptText = Cryptos.aesEncrypt(JSON.toJSONString(map).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 resultMap = ThirdPartyPlatformUtils.generateResultMapV2(map, thirdPartySecretInfoVO.getOurDataSecret(), + thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret()); return resultMap; } @@ -492,10 +466,7 @@ public class HuaWeiServiceImpl implements HuaWeiService { */ @Override public Map vinStartCharge(VinStartChargeDTO dto) throws Exception { - ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorId()); - if (configInfo == null) { - return null; - } + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getHuaWeiPlatformSecretInfo(); Map paramMap = new LinkedHashMap<>(); String vinCode = dto.getVin(); @@ -533,17 +504,8 @@ public class HuaWeiServiceImpl implements HuaWeiService { paramMap.put("FailReason", failReason); // 加密 - Map resultMap = Maps.newLinkedHashMap(); - // 加密数据 - byte[] encryptText = Cryptos.aesEncrypt(JSON.toJSONString(paramMap).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 resultMap = ThirdPartyPlatformUtils.generateResultMapV2(map, thirdPartySecretInfoVO.getOurDataSecret(), + thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret()); return resultMap; } @@ -558,13 +520,14 @@ public class HuaWeiServiceImpl implements HuaWeiService { // 通过第三方配置类型查询相关配置信息 ThirdPartySettingInfo settingInfo = new ThirdPartySettingInfo(); settingInfo.setType(dto.getThirdPartyType()); - 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(); + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getHuaWeiPlatformSecretInfo(); + + String operatorId = thirdPartySecretInfoVO.getTheirOperatorId(); + String operatorSecret = thirdPartySecretInfoVO.getTheirOperatorSecret(); + String signSecret = thirdPartySecretInfoVO.getTheirSigSecret(); + String dataSecret = thirdPartySecretInfoVO.getTheirDataSecret(); + String dataSecretIv = thirdPartySecretInfoVO.getTheirDataSecretIv(); + String urlAddress = thirdPartySecretInfoVO.getTheirUrlPrefix(); List equipmentLogicInfos = new ArrayList<>(); @@ -655,4 +618,19 @@ public class HuaWeiServiceImpl implements HuaWeiService { return connectorInfoList; } + /** + * 获取华为平台配置密钥信息 + * + * @return + */ + private ThirdPartySecretInfoVO getHuaWeiPlatformSecretInfo() { + // 通过第三方平台类型查询相关配置信息 + ThirdPartySecretInfoVO thirdPartySecretInfoVO = thirdpartySecretInfoService.queryByThirdPlatformType(ThirdPlatformTypeEnum.HUA_WEI.getTypeCode()); + if (thirdPartySecretInfoVO == null) { + throw new BusinessException(ReturnCodeEnum.CODE_SELECT_INFO_IS_NULL); + } + thirdPartySecretInfoVO.setOurOperatorId(Constants.OPERATORID_JIANG_SU); + return thirdPartySecretInfoVO; + } + } 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 76d882ec3..bb3b1c9b6 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 @@ -166,11 +166,11 @@ public interface LianLianService { * @return * @throws UnsupportedEncodingException */ - Map generateToken(CommonParamsDTO dto) throws UnsupportedEncodingException; + // Map generateToken(CommonParamsDTO dto) throws UnsupportedEncodingException; /** * 校验签名 * @param dto */ - Map checkoutSign(CommonParamsDTO dto); + // Map checkoutSign(CommonParamsDTO 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 225f98c04..98ad3c88d 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 @@ -16,10 +16,8 @@ import com.jsowell.common.enums.lianlian.StationPaymentEnum; import com.jsowell.common.enums.thirdparty.BusinessInformationExchangeEnum; import com.jsowell.common.enums.thirdparty.ThirdPartyOperatorIdEnum; import com.jsowell.common.enums.thirdparty.ThirdPlatformTypeEnum; -import com.jsowell.common.enums.ykc.OrderPayModeEnum; -import com.jsowell.common.enums.ykc.OrderStatusEnum; -import com.jsowell.common.enums.ykc.PileConnectorDataBaseStatusEnum; -import com.jsowell.common.enums.ykc.PileStatusEnum; +import com.jsowell.common.enums.ykc.*; +import com.jsowell.common.exception.BusinessException; import com.jsowell.common.util.*; import com.jsowell.pile.domain.*; import com.jsowell.pile.domain.ykcCommond.StartChargingCommand; @@ -29,6 +27,7 @@ import com.jsowell.pile.thirdparty.CommonParamsDTO; import com.jsowell.pile.thirdparty.ConnectorInfo; import com.jsowell.pile.thirdparty.EquipmentInfo; import com.jsowell.pile.util.MerchantUtils; +import com.jsowell.pile.vo.ThirdPartySecretInfoVO; import com.jsowell.pile.vo.base.*; import com.jsowell.pile.vo.lianlian.AccumulativeInfoVO; import com.jsowell.pile.vo.lianlian.PushStationFeeVO; @@ -43,10 +42,8 @@ import com.jsowell.thirdparty.lianlian.vo.*; import com.jsowell.thirdparty.platform.common.ChargeDetail; import com.jsowell.thirdparty.platform.common.OrderInfo; import com.jsowell.thirdparty.platform.common.StationInfo; -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 com.jsowell.thirdparty.platform.util.*; +import com.jsowell.thirdparty.service.ThirdpartySecretInfoService; import com.jsowell.thirdparty.yongchengboche.dto.YCBCGetTokenDTO; import com.jsowell.thirdparty.yongchengboche.service.YCBCService; import org.apache.commons.collections4.CollectionUtils; @@ -103,10 +100,7 @@ public class LianLianServiceImpl implements LianLianService { private PileBillingTemplateService pileBillingTemplateService; @Autowired - private ThirdPartySettingInfoService thirdPartySettingInfoService; - - @Autowired - private ThirdPartyPlatformConfigService thirdPartyPlatformConfigService; + private ThirdpartySecretInfoService thirdpartySecretInfoService; @Autowired private ThirdPartyStationRelationService thirdPartyStationRelationService; @@ -134,14 +128,14 @@ public class LianLianServiceImpl implements LianLianService { // 通过第三方配置类型查询相关配置信息 ThirdPartySettingInfo settingInfo = new ThirdPartySettingInfo(); settingInfo.setType(dto.getThirdPartyType()); - ThirdPartySettingInfo thirdPartySettingInfo = thirdPartySettingInfoService.selectSettingInfo(settingInfo); + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getLianLianPlatformSecretInfo(); - String operatorId = thirdPartySettingInfo.getOperatorId(); - String operatorSecret = thirdPartySettingInfo.getOperatorSecret(); - String signSecret = thirdPartySettingInfo.getSignSecret(); - String dataSecret = thirdPartySettingInfo.getDataSecret(); - String dataSecretIv = thirdPartySettingInfo.getDataSecretIv(); - String urlAddress = thirdPartySettingInfo.getUrlAddress(); + String operatorId = thirdPartySecretInfoVO.getTheirOperatorId(); + String operatorSecret = thirdPartySecretInfoVO.getTheirOperatorSecret(); + String signSecret = thirdPartySecretInfoVO.getTheirSigSecret(); + String dataSecret = thirdPartySecretInfoVO.getTheirDataSecret(); + String dataSecretIv = thirdPartySecretInfoVO.getTheirDataSecretIv(); + String urlAddress = thirdPartySecretInfoVO.getTheirUrlPrefix(); // 组装联联平台所需要的数据格式 StationInfo info = StationInfo.builder() @@ -302,10 +296,8 @@ public class LianLianServiceImpl implements LianLianService { // 未查到数据 return null; } - ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorId()); - if (configInfo == null) { - return null; - } + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getLianLianPlatformSecretInfo(); + PageInfo pageInfo = new PageInfo<>(stationInfos); for (ThirdPartyStationInfoVO pileStationInfo : pageInfo.getList()) { StationInfo stationInfo = new StationInfo(); @@ -361,17 +353,8 @@ public class LianLianServiceImpl implements LianLianService { // .list(resultList) // .build(); // 加密 - Map resultMap = Maps.newLinkedHashMap(); - // 加密数据 - byte[] encryptText = Cryptos.aesEncrypt(JSON.toJSONString(map).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 resultMap = ThirdPartyPlatformUtils.generateResultMapV2(map, thirdPartySecretInfoVO.getOurDataSecret(), + thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret()); return resultMap; } @@ -387,10 +370,8 @@ public class LianLianServiceImpl implements LianLianService { List stationIds = dto.getStationIds(); List StationStatusInfos = new ArrayList<>(); List ConnectorStatusInfos = new ArrayList<>(); - ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorId()); - if (configInfo == null) { - return null; - } + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getLianLianPlatformSecretInfo(); + ConnectorStatusInfo connectorStatusInfo; for (String stationId : stationIds) { StationStatusInfo stationStatusInfo= new StationStatusInfo(); @@ -454,17 +435,8 @@ public class LianLianServiceImpl implements LianLianService { map.put("StationStatusInfos", collect); // 加密 - Map resultMap = Maps.newLinkedHashMap(); - // 加密数据 - byte[] encryptText = Cryptos.aesEncrypt(JSON.toJSONString(map).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 resultMap = ThirdPartyPlatformUtils.generateResultMapV2(map, thirdPartySecretInfoVO.getOurDataSecret(), + thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret()); return resultMap; } @@ -476,10 +448,8 @@ public class LianLianServiceImpl implements LianLianService { */ @Override public Map query_station_stats(QueryStationInfoDTO dto) { - ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorId()); - if (configInfo == null) { - return null; - } + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getLianLianPlatformSecretInfo(); + // 根据站点id 查出这段时间的充电量 List list = orderBasicInfoService.getAccumulativeInfoForLianLian(dto); if (CollectionUtils.isEmpty(list)) { @@ -553,17 +523,8 @@ public class LianLianServiceImpl implements LianLianService { map.put("StationStats", stationStatsInfo); // 加密 - Map resultMap = Maps.newLinkedHashMap(); - // 加密数据 - byte[] encryptText = Cryptos.aesEncrypt(JSON.toJSONString(map).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 resultMap = ThirdPartyPlatformUtils.generateResultMapV2(map, thirdPartySecretInfoVO.getOurDataSecret(), + thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret()); return resultMap; } @@ -575,16 +536,13 @@ public class LianLianServiceImpl implements LianLianService { */ @Override public Map query_equip_auth(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; - } + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getLianLianPlatformSecretInfo(); + // 根据桩编号查询数据 // String merchantId = StringUtils.substring(equipAuthSeq, 0, 9); // String pileSn = StringUtils.substring(pileConnectorCode, 0, 14); @@ -612,15 +570,8 @@ public class LianLianServiceImpl implements LianLianService { 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); - + Map resultMap = ThirdPartyPlatformUtils.generateResultMapV2(vo, thirdPartySecretInfoVO.getOurDataSecret(), + thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret()); return resultMap; } @@ -638,10 +589,8 @@ public class LianLianServiceImpl implements LianLianService { // 平台已存在订单 return null; } - ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorId()); - if (configInfo == null) { - return null; - } + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getLianLianPlatformSecretInfo(); + // 生成订单 Map map = orderBasicInfoService.generateOrderForThirdParty(dto); String orderCode = (String) map.get("orderCode"); @@ -675,19 +624,9 @@ public class LianLianServiceImpl implements LianLianService { } // 加密 - Map resultMap = Maps.newLinkedHashMap(); - // 加密数据 - 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); - + Map resultMap = ThirdPartyPlatformUtils.generateResultMapV2(map, thirdPartySecretInfoVO.getOurDataSecret(), + thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret()); return resultMap; - } @@ -707,11 +646,8 @@ public class LianLianServiceImpl implements LianLianService { if (orderInfo == null) { return null; } - ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(operatorID); - // logger.info(operatorName + "查询密钥信息 configInfo:{}", configInfo); - if (configInfo == null) { - return null; - } + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getLianLianPlatformSecretInfo(); + OrderDetail orderDetail = orderBasicInfoService.getOrderDetailByOrderCode(orderInfo.getOrderCode()); // 通过订单号查询实时数据 List realTimeData = orderBasicInfoService.getChargingRealTimeData(orderInfo.getTransactionCode()); @@ -762,17 +698,8 @@ public class LianLianServiceImpl implements LianLianService { } // 加密 - Map resultMap = Maps.newLinkedHashMap(); - // 加密数据 - 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); - + Map resultMap = ThirdPartyPlatformUtils.generateResultMapV2(vo, thirdPartySecretInfoVO.getOurDataSecret(), + thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret()); return resultMap; } @@ -793,10 +720,8 @@ public class LianLianServiceImpl implements LianLianService { if (orderInfo == null) { return null; } - ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorId()); - if (configInfo == null) { - return null; - } + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getLianLianPlatformSecretInfo(); + // 若状态为充电中,则发送停机指令 if (StringUtils.equals(OrderStatusEnum.IN_THE_CHARGING.getValue(), orderInfo.getOrderStatus())) { // 充电中 @@ -818,17 +743,8 @@ public class LianLianServiceImpl implements LianLianService { vo.setStartChargeSeqStat(3); } // 加密 - Map resultMap = Maps.newLinkedHashMap(); - // 加密数据 - 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); - + Map resultMap = ThirdPartyPlatformUtils.generateResultMapV2(vo, thirdPartySecretInfoVO.getOurDataSecret(), + thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret()); return resultMap; } @@ -1195,9 +1111,10 @@ public class LianLianServiceImpl implements LianLianService { } String data = map.get("Data"); // 解密data (此处解密需用 thirdparty_platform_config 的密钥配置) - ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(operatorIdByType); + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getLianLianPlatformSecretInfo(); + byte[] plainText = Cryptos.aesDecrypt(Encodes.decodeBase64(data), - configInfo.getDataSecret().getBytes(), configInfo.getDataSecretIv().getBytes()); + thirdPartySecretInfoVO.getOurDataSecret().getBytes(), thirdPartySecretInfoVO.getOurDataSecretIv().getBytes()); String dataStr = new String(plainText, StandardCharsets.UTF_8); // 转成对应的对象 QueryChargingStatusVO vo = JSONObject.parseObject(dataStr, QueryChargingStatusVO.class); @@ -1397,11 +1314,8 @@ public class LianLianServiceImpl implements LianLianService { if (orderInfo == null || orderDetail == null) { return null; } - // 通过operatorID 查出 operatorSecret - ThirdPartyPlatformConfig platformConfig = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorId()); - if (platformConfig == null) { - return null; - } + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getLianLianPlatformSecretInfo(); + // orderInfo 和 orderDetail 都不为空,再根据传过来的数据进行修改数据库信息 confirmResult = Constants.zero; orderDetail.setTotalUsedElectricity(dto.getTotalPower()); // 累计充电量 @@ -1414,12 +1328,12 @@ public class LianLianServiceImpl implements LianLianService { Map resultMap = Maps.newLinkedHashMap(); // 加密数据 byte[] encryptText = Cryptos.aesEncrypt(JSON.toJSONString(map).getBytes(), - platformConfig.getDataSecret().getBytes(), platformConfig.getDataSecretIv().getBytes()); + thirdPartySecretInfoVO.getOurDataSecret().getBytes(), thirdPartySecretInfoVO.getOurDataSecretIv().getBytes()); String encryptData = Encodes.encodeBase64(encryptText); resultMap.put("Data", encryptData); // 生成sig - String resultSign = GBSignUtils.sign(resultMap, platformConfig.getSignSecret()); + String resultSign = GBSignUtils.sign(resultMap, thirdPartySecretInfoVO.getOurSigSecret()); resultMap.put("Sig", resultSign); return resultMap; @@ -1670,107 +1584,104 @@ public class LianLianServiceImpl implements LianLianService { * @return * @throws UnsupportedEncodingException */ - @Override - public Map generateToken(CommonParamsDTO dto) throws UnsupportedEncodingException { - String operatorId = dto.getOperatorID(); - // 通过operatorId 查出 operatorSecret - ThirdPartyPlatformConfig platformConfig = thirdPartyPlatformConfigService.getInfoByOperatorId(operatorId); - if (platformConfig == null) { - return null; - } - String operatorSecret = platformConfig.getOperatorSecret(); - String dataSecret = platformConfig.getDataSecret(); - String dataSecretIv = platformConfig.getDataSecretIv(); - String signSecret = platformConfig.getSignSecret(); - // 校验签名 - Map checkResultMap = checkoutSign(dto); - if (checkResultMap == null) { - // 校验失败 - return null; - } - String dataString = checkResultMap.get("Data"); - // 解密data - byte[] plainText = Cryptos.aesDecrypt(Encodes.decodeBase64(dataString), dataSecret.getBytes(), dataSecretIv.getBytes()); - String dataStr = new String(plainText, StandardCharsets.UTF_8); - Map resMap = (Map) JSON.parse(dataStr); - String secret = resMap.get("OperatorSecret"); - - // 对比解出来的密钥是否和数据库中保存的一致 - if (!StringUtils.equals(operatorSecret, secret)) { - System.out.println("密钥不一致"); - return null; - } - System.out.println("密钥校验通过!! 密钥为: " + operatorSecret); - - // 生成token返回 eyJhbGciOiJIUzI1NiJ9.eyJqdGkiOiI0MjUwMTA3NjUiLCJpYXQiOjE2ODUwOTcxMTYsInN1YiI6IjEyMzEyMzEyMzEyM2FhYWEiLCJleHAiOjY4NjkwOTcxMTZ9.NyxOUIZmgsqtfex7oiMRR2LaWePTA56WHVMXIkWWt2w - long ttlMillis = 60 * 60 * 24 * 1000; - String token = JWTUtils.createToken(operatorId, operatorSecret, ttlMillis); - System.out.println("生成的token:" + token); - - // 组装返回参数 - AccessTokenVO vo = new AccessTokenVO(); - vo.setAccessToken(token); - vo.setOperatorID(operatorId); - vo.setTokenAvailableTime((int) (ttlMillis / 1000)); - vo.setFailReason(0); - vo.setSuccStat(0); - - Map resultMap = Maps.newLinkedHashMap(); - // 加密数据 - byte[] encryptText = Cryptos.aesEncrypt(JSON.toJSONString(vo).getBytes(), - dataSecret.getBytes(), dataSecretIv.getBytes()); - String encryptData = Encodes.encodeBase64(encryptText); - - resultMap.put("Data", encryptData); - // 生成sig - String resultSign = GBSignUtils.sign(resultMap, signSecret); - resultMap.put("Sig", resultSign); - - return resultMap; - } + // @Override + // public Map generateToken(CommonParamsDTO dto) throws UnsupportedEncodingException { + // String operatorId = dto.getOperatorID(); + // ThirdPartySecretInfoVO thirdPartySecretInfoVO = getLianLianPlatformSecretInfo(); + // + // String operatorSecret = thirdPartySecretInfoVO.getOurOperatorSecret(); + // String dataSecret = thirdPartySecretInfoVO.getOurDataSecret(); + // String dataSecretIv = thirdPartySecretInfoVO.getOurDataSecretIv(); + // String signSecret = thirdPartySecretInfoVO.getOurSigSecret(); + // // 校验签名 + // Map checkResultMap = checkoutSign(dto); + // if (checkResultMap == null) { + // // 校验失败 + // return null; + // } + // String dataString = checkResultMap.get("Data"); + // // 解密data + // byte[] plainText = Cryptos.aesDecrypt(Encodes.decodeBase64(dataString), dataSecret.getBytes(), dataSecretIv.getBytes()); + // String dataStr = new String(plainText, StandardCharsets.UTF_8); + // Map resMap = (Map) JSON.parse(dataStr); + // String secret = resMap.get("OperatorSecret"); + // + // // 对比解出来的密钥是否和数据库中保存的一致 + // if (!StringUtils.equals(operatorSecret, secret)) { + // System.out.println("密钥不一致"); + // return null; + // } + // System.out.println("密钥校验通过!! 密钥为: " + operatorSecret); + // + // // 生成token返回 eyJhbGciOiJIUzI1NiJ9.eyJqdGkiOiI0MjUwMTA3NjUiLCJpYXQiOjE2ODUwOTcxMTYsInN1YiI6IjEyMzEyMzEyMzEyM2FhYWEiLCJleHAiOjY4NjkwOTcxMTZ9.NyxOUIZmgsqtfex7oiMRR2LaWePTA56WHVMXIkWWt2w + // long ttlMillis = 60 * 60 * 24 * 1000; + // String token = JWTUtils.createToken(operatorId, operatorSecret, ttlMillis); + // System.out.println("生成的token:" + token); + // + // // 组装返回参数 + // AccessTokenVO vo = new AccessTokenVO(); + // vo.setAccessToken(token); + // vo.setOperatorID(operatorId); + // vo.setTokenAvailableTime((int) (ttlMillis / 1000)); + // vo.setFailReason(0); + // vo.setSuccStat(0); + // + // Map resultMap = Maps.newLinkedHashMap(); + // // 加密数据 + // byte[] encryptText = Cryptos.aesEncrypt(JSON.toJSONString(vo).getBytes(), + // dataSecret.getBytes(), dataSecretIv.getBytes()); + // String encryptData = Encodes.encodeBase64(encryptText); + // + // resultMap.put("Data", encryptData); + // // 生成sig + // String resultSign = GBSignUtils.sign(resultMap, signSecret); + // resultMap.put("Sig", resultSign); + // + // return resultMap; + // } /** * 校验签名并返回data(未解密) * @param dto */ - @Override - public Map checkoutSign(CommonParamsDTO dto){ - String operatorID = dto.getOperatorID(); - // 通过operatorID 查出 operatorSecret - ThirdPartyPlatformConfig platformConfig = thirdPartyPlatformConfigService.getInfoByOperatorId(operatorID); - if (platformConfig == null) { - return null; - } - String operatorSecret = platformConfig.getOperatorSecret(); - String signSecret = platformConfig.getSignSecret(); - - Map map = Maps.newLinkedHashMap(); - map.put("OperatorID", dto.getOperatorID()); - map.put("Data", dto.getData()); - map.put("TimeStamp", dto.getTimeStamp()); - map.put("Seq", dto.getSeq()); - String sign = GBSignUtils.sign(map, signSecret); - System.out.println(sign); - - // 验证签名 得到请求方传过来的签名sig->自己拿到请求体后,再按双方约定的协议生成一个sig->对比两个sig是否一致 - if (!StringUtils.equals(dto.getSig(), sign)) { - System.out.println("签名校验==失败"); - return null; - } - System.out.println("签名校验通过!!!"); - - // 解密data - // byte[] plainText = Cryptos.aesDecrypt(Encodes.decodeBase64(dto.getData()), operatorSecret.getBytes(), operatorSecret.getBytes()); - // String dataStr = new String(plainText, "UTF-8"); - // Map resMap = (Map) JSON.parse(dataStr); - // return resMap; - Map resultMap = new LinkedHashMap<>(); - resultMap.put("Data", dto.getData()); - resultMap.put("OperatorSecret", operatorSecret); - resultMap.put("DataSecret", platformConfig.getDataSecret()); - resultMap.put("DataSecretIV", platformConfig.getDataSecretIv()); - return resultMap; - } + // @Override + // public Map checkoutSign(CommonParamsDTO dto){ + // String operatorID = dto.getOperatorID(); + // // 通过operatorID 查出 operatorSecret + // ThirdPartyPlatformConfig platformConfig = thirdPartyPlatformConfigService.getInfoByOperatorId(operatorID); + // if (platformConfig == null) { + // return null; + // } + // String operatorSecret = platformConfig.getOperatorSecret(); + // String signSecret = platformConfig.getSignSecret(); + // + // Map map = Maps.newLinkedHashMap(); + // map.put("OperatorID", dto.getOperatorID()); + // map.put("Data", dto.getData()); + // map.put("TimeStamp", dto.getTimeStamp()); + // map.put("Seq", dto.getSeq()); + // String sign = GBSignUtils.sign(map, signSecret); + // System.out.println(sign); + // + // // 验证签名 得到请求方传过来的签名sig->自己拿到请求体后,再按双方约定的协议生成一个sig->对比两个sig是否一致 + // if (!StringUtils.equals(dto.getSig(), sign)) { + // System.out.println("签名校验==失败"); + // return null; + // } + // System.out.println("签名校验通过!!!"); + // + // // 解密data + // // byte[] plainText = Cryptos.aesDecrypt(Encodes.decodeBase64(dto.getData()), operatorSecret.getBytes(), operatorSecret.getBytes()); + // // String dataStr = new String(plainText, "UTF-8"); + // // Map resMap = (Map) JSON.parse(dataStr); + // // return resMap; + // Map resultMap = new LinkedHashMap<>(); + // resultMap.put("Data", dto.getData()); + // resultMap.put("OperatorSecret", operatorSecret); + // resultMap.put("DataSecret", platformConfig.getDataSecret()); + // resultMap.put("DataSecretIV", platformConfig.getDataSecretIv()); + // return resultMap; + // } /** * TODO 请求打印充电小票 @@ -1870,4 +1781,19 @@ public class LianLianServiceImpl implements LianLianService { return resultList; } + + /** + * 获取联联平台配置密钥信息 + * + * @return + */ + private ThirdPartySecretInfoVO getLianLianPlatformSecretInfo() { + // 通过第三方平台类型查询相关配置信息 + ThirdPartySecretInfoVO thirdPartySecretInfoVO = thirdpartySecretInfoService.queryByThirdPlatformType(ThirdPlatformTypeEnum.LIAN_LIAN_PLATFORM.getTypeCode()); + if (thirdPartySecretInfoVO == null) { + throw new BusinessException(ReturnCodeEnum.CODE_SELECT_INFO_IS_NULL); + } + thirdPartySecretInfoVO.setOurOperatorId(Constants.OPERATORID_JIANG_SU); + return thirdPartySecretInfoVO; + } } diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/nanrui/service/NRService.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/nanrui/service/NRService.java index 824f45993..08a7064fb 100644 --- a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/nanrui/service/NRService.java +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/nanrui/service/NRService.java @@ -33,13 +33,13 @@ public interface NRService { * @return * @throws UnsupportedEncodingException */ - Map generateToken(CommonParamsDTO dto) throws UnsupportedEncodingException; + // Map generateToken(CommonParamsDTO dto) throws UnsupportedEncodingException; /** * 校验签名 * @param dto */ - Map checkoutSign(CommonParamsDTO dto); + // Map checkoutSign(CommonParamsDTO dto); /** * 推送充电站信息 diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/nanrui/service/impl/NRServiceImpl.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/nanrui/service/impl/NRServiceImpl.java index 01e7ef62b..f4e490c82 100644 --- a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/nanrui/service/impl/NRServiceImpl.java +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/nanrui/service/impl/NRServiceImpl.java @@ -11,7 +11,10 @@ import com.jsowell.common.core.domain.ykc.RealTimeMonitorData; import com.jsowell.common.core.redis.RedisCache; import com.jsowell.common.enums.thirdparty.BusinessInformationExchangeEnum; import com.jsowell.common.enums.thirdparty.JiangSuConstructionEnum; +import com.jsowell.common.enums.thirdparty.ThirdPlatformTypeEnum; import com.jsowell.common.enums.ykc.PileStatusEnum; +import com.jsowell.common.enums.ykc.ReturnCodeEnum; +import com.jsowell.common.exception.BusinessException; import com.jsowell.common.util.DateUtils; import com.jsowell.common.util.PageUtils; import com.jsowell.common.util.StringUtils; @@ -24,6 +27,7 @@ import com.jsowell.pile.dto.QueryStationInfoDTO; import com.jsowell.pile.dto.nanrui.NRQueryOrderDTO; import com.jsowell.pile.dto.nanrui.PushAlarmInfoDTO; import com.jsowell.pile.service.*; +import com.jsowell.pile.vo.ThirdPartySecretInfoVO; import com.jsowell.pile.vo.base.MerchantInfoVO; import com.jsowell.pile.vo.base.ThirdPartyStationInfoVO; import com.jsowell.pile.vo.base.ThirdPartyStationRelationVO; @@ -35,12 +39,10 @@ import com.jsowell.pile.vo.web.PileStationVO; import com.jsowell.thirdparty.common.CommonService; import com.jsowell.pile.thirdparty.CommonParamsDTO; import com.jsowell.thirdparty.lianlian.service.LianLianService; -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 com.jsowell.thirdparty.platform.util.*; import com.jsowell.thirdparty.nanrui.domain.*; import com.jsowell.thirdparty.nanrui.service.NRService; +import com.jsowell.thirdparty.service.ThirdpartySecretInfoService; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.RandomStringUtils; @@ -88,10 +90,7 @@ public class NRServiceImpl implements NRService { private ThirdPartyStationRelationService thirdPartyStationRelationService; @Autowired - private ThirdPartyPlatformConfigService thirdPartyPlatformConfigService; - - @Autowired - private ThirdPartySettingInfoService thirdPartySettingInfoService; + private ThirdpartySecretInfoService thirdpartySecretInfoService; @Autowired private LianLianService lianLianService; @@ -120,15 +119,15 @@ public class NRServiceImpl implements NRService { dataSecretIv, signSecret, dataSecret); } - @Override - public Map generateToken(CommonParamsDTO dto) throws UnsupportedEncodingException { - return lianLianService.generateToken(dto); - } + // @Override + // public Map generateToken(CommonParamsDTO dto) throws UnsupportedEncodingException { + // return lianLianService.generateToken(dto); + // } - @Override - public Map checkoutSign(CommonParamsDTO dto) { - return lianLianService.checkoutSign(dto); - } + // @Override + // public Map checkoutSign(CommonParamsDTO dto) { + // return lianLianService.checkoutSign(dto); + // } /** * 推送充电站信息 @@ -254,14 +253,14 @@ public class NRServiceImpl implements NRService { // 通过第三方配置类型查询相关配置信息 ThirdPartySettingInfo settingInfo = new ThirdPartySettingInfo(); settingInfo.setType(dto.getThirdPartyType()); - ThirdPartySettingInfo thirdPartySettingInfo = thirdPartySettingInfoService.selectSettingInfo(settingInfo); + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getJiangSuPlatformSecretInfo(); - String operatorId = thirdPartySettingInfo.getOperatorId(); - String operatorSecret = thirdPartySettingInfo.getOperatorSecret(); - String signSecret = thirdPartySettingInfo.getSignSecret(); - String dataSecret = thirdPartySettingInfo.getDataSecret(); - String dataSecretIv = thirdPartySettingInfo.getDataSecretIv(); - String urlAddress = thirdPartySettingInfo.getUrlAddress(); + String operatorId = thirdPartySecretInfoVO.getTheirOperatorId(); + String operatorSecret = thirdPartySecretInfoVO.getTheirOperatorSecret(); + String signSecret = thirdPartySecretInfoVO.getTheirSigSecret(); + String dataSecret = thirdPartySecretInfoVO.getTheirDataSecret(); + String dataSecretIv = thirdPartySecretInfoVO.getTheirDataSecretIv(); + String urlAddress = thirdPartySecretInfoVO.getTheirUrlPrefix(); // 拼装南瑞平台所需参数 NRStationInfo nrStationInfo = NRStationInfo.builder() @@ -366,10 +365,8 @@ public class NRServiceImpl implements NRService { // 未查到数据 return null; } - ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorId()); - if (configInfo == null) { - return null; - } + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getJiangSuPlatformSecretInfo(); + PageInfo pageInfo = new PageInfo<>(stationInfos); for (ThirdPartyStationInfoVO pileStationInfo : pageInfo.getList()) { // 拼装参数 @@ -431,17 +428,8 @@ public class NRServiceImpl implements NRService { map.put("StationInfos", resultList); // 加密 - Map resultMap = Maps.newLinkedHashMap(); - // 加密数据 - byte[] encryptText = Cryptos.aesEncrypt(JSON.toJSONString(map).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 resultMap = ThirdPartyPlatformUtils.generateResultMapV2(map, thirdPartySecretInfoVO.getOurDataSecret(), + thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret()); return resultMap; } @@ -588,10 +576,8 @@ public class NRServiceImpl implements NRService { public Map query_station_status(QueryStationInfoDTO dto) { List stationIds = dto.getStationIds(); List resultList = new ArrayList<>(); - ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorId()); - if (configInfo == null) { - return null; - } + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getJiangSuPlatformSecretInfo(); + // 将 stationIdList 转换成 List List stationLongList = stationIds.stream() .map(Long::parseLong) @@ -651,17 +637,8 @@ public class NRServiceImpl implements NRService { map.put("StationStatusInfos", resultList); // 加密 - Map resultMap = Maps.newLinkedHashMap(); - // 加密数据 - byte[] encryptText = Cryptos.aesEncrypt(JSON.toJSONString(map).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 resultMap = ThirdPartyPlatformUtils.generateResultMapV2(map, thirdPartySecretInfoVO.getOurDataSecret(), + thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret()); return resultMap; } @@ -718,10 +695,8 @@ public class NRServiceImpl implements NRService { @Override public Map query_order_info(NRQueryOrderDTO dto) { List resultList = new ArrayList<>(); - ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorId()); - if (configInfo == null) { - return null; - } + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getJiangSuPlatformSecretInfo(); + List nrOrderInfos = orderBasicInfoService.getNROrderInfos(dto); if (CollectionUtils.isEmpty(nrOrderInfos)) { return Maps.newLinkedHashMap(); @@ -731,17 +706,8 @@ public class NRServiceImpl implements NRService { resultList.add(jiangSuOrderInfo); } // 加密 - Map resultMap = Maps.newLinkedHashMap(); - // 加密数据 - byte[] encryptText = Cryptos.aesEncrypt(JSON.toJSONString(resultList).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 resultMap = ThirdPartyPlatformUtils.generateResultMapV2(resultList, thirdPartySecretInfoVO.getOurDataSecret(), + thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret()); return resultMap; } @@ -872,4 +838,19 @@ public class NRServiceImpl implements NRService { } return resultList; } + + /** + * 获取江苏省平台配置密钥信息 + * + * @return + */ + private ThirdPartySecretInfoVO getJiangSuPlatformSecretInfo() { + // 通过第三方平台类型查询相关配置信息 + ThirdPartySecretInfoVO thirdPartySecretInfoVO = thirdpartySecretInfoService.queryByThirdPlatformType(ThirdPlatformTypeEnum.JIANG_SU_PLATFORM.getTypeCode()); + if (thirdPartySecretInfoVO == null) { + throw new BusinessException(ReturnCodeEnum.CODE_SELECT_INFO_IS_NULL); + } + thirdPartySecretInfoVO.setOurOperatorId(Constants.OPERATORID_JIANG_SU); + return thirdPartySecretInfoVO; + } } diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/ningxiajiaotou/service/NXJTService.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/ningxiajiaotou/service/NXJTService.java index d48d84112..53c1bbe2c 100644 --- a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/ningxiajiaotou/service/NXJTService.java +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/ningxiajiaotou/service/NXJTService.java @@ -21,7 +21,7 @@ public interface NXJTService { * @return * @throws UnsupportedEncodingException */ - Map generateToken(CommonParamsDTO dto) throws UnsupportedEncodingException; + // Map generateToken(CommonParamsDTO dto) throws UnsupportedEncodingException; /** diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/ningxiajiaotou/service/impl/NXJTServiceImpl.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/ningxiajiaotou/service/impl/NXJTServiceImpl.java index c062b58a8..a606117e7 100644 --- a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/ningxiajiaotou/service/impl/NXJTServiceImpl.java +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/ningxiajiaotou/service/impl/NXJTServiceImpl.java @@ -3,6 +3,10 @@ package com.jsowell.thirdparty.ningxiajiaotou.service.impl; import com.alibaba.fastjson2.JSON; import com.github.pagehelper.PageInfo; import com.google.common.collect.Maps; +import com.jsowell.common.constant.Constants; +import com.jsowell.common.enums.thirdparty.ThirdPlatformTypeEnum; +import com.jsowell.common.enums.ykc.ReturnCodeEnum; +import com.jsowell.common.exception.BusinessException; import com.jsowell.common.util.DateUtils; import com.jsowell.common.util.PageUtils; import com.jsowell.common.util.StringUtils; @@ -10,6 +14,7 @@ import com.jsowell.pile.domain.ThirdPartyPlatformConfig; import com.jsowell.pile.dto.ningxiajiaotou.NXJTQueryOrdersInfoDTO; import com.jsowell.pile.dto.ningxiajiaotou.NXJTQueryStationInfoDTO; import com.jsowell.pile.service.*; +import com.jsowell.pile.vo.ThirdPartySecretInfoVO; import com.jsowell.pile.vo.base.ConnectorInfoVO; import com.jsowell.pile.vo.ningxiajiaotou.NXJTOrderVO; import com.jsowell.pile.vo.ningxiajiaotou.NXJTStationInfoVO; @@ -20,6 +25,8 @@ 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.ningxiajiaotou.service.NXJTService; +import com.jsowell.thirdparty.platform.util.ThirdPartyPlatformUtils; +import com.jsowell.thirdparty.service.ThirdpartySecretInfoService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -43,7 +50,7 @@ public class NXJTServiceImpl implements NXJTService { private PileStationInfoService pileStationInfoService; @Autowired - private ThirdPartyPlatformConfigService thirdPartyPlatformConfigService; + private ThirdpartySecretInfoService thirdpartySecretInfoService; @Autowired private PileBasicInfoService pileBasicInfoService; @@ -60,10 +67,10 @@ public class NXJTServiceImpl implements NXJTService { * @return * @throws UnsupportedEncodingException */ - @Override - public Map generateToken(CommonParamsDTO dto) throws UnsupportedEncodingException { - return lianLianService.generateToken(dto); - } + // @Override + // public Map generateToken(CommonParamsDTO dto) throws UnsupportedEncodingException { + // return lianLianService.generateToken(dto); + // } /** * 获取令牌 @@ -90,10 +97,7 @@ public class NXJTServiceImpl implements NXJTService { int pageNo = dto.getPageNo() == null ? 1 : dto.getPageNo(); int pageSize = dto.getPageSize() == null ? 10 : dto.getPageSize(); - ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorId()); - if (configInfo == null) { - return null; - } + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getNXJTPlatformSecretInfo(); // 分页 PageUtils.startPage(pageNo, pageSize); List stationInfos = pileStationInfoService.NXJTQueryStationsInfo(dto); @@ -106,17 +110,8 @@ public class NXJTServiceImpl implements NXJTService { map.put("stationInfos", pageInfo.getList()); // 加密 - Map resultMap = Maps.newLinkedHashMap(); - // 加密数据 - byte[] encryptText = Cryptos.aesEncrypt(JSON.toJSONString(map).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 resultMap = ThirdPartyPlatformUtils.generateResultMapV2(map, thirdPartySecretInfoVO.getOurDataSecret(), + thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret()); return resultMap; } @@ -127,10 +122,8 @@ public class NXJTServiceImpl implements NXJTService { */ @Override public Map queryFreePileNumber(NXJTQueryStationInfoDTO dto) { - ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorId()); - if (configInfo == null) { - return null; - } + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getNXJTPlatformSecretInfo(); + long stationId = Long.parseLong(dto.getStationId()); List connectorList = pileConnectorInfoService.getUniAppConnectorList(stationId); // 先根据pileSn分组,获取设备总数 @@ -153,17 +146,8 @@ public class NXJTServiceImpl implements NXJTService { map.put("freePileNum", freePileNumber); // 加密 - Map resultMap = Maps.newLinkedHashMap(); - // 加密数据 - byte[] encryptText = Cryptos.aesEncrypt(JSON.toJSONString(map).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 resultMap = ThirdPartyPlatformUtils.generateResultMapV2(map, thirdPartySecretInfoVO.getOurDataSecret(), + thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret()); return resultMap; } @@ -178,10 +162,8 @@ public class NXJTServiceImpl implements NXJTService { int pageNo = dto.getPageNo() == null ? 1 : dto.getPageNo(); int pageSize = dto.getPageSize() == null ? 10 : dto.getPageSize(); - ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorId()); - if (configInfo == null) { - return null; - } + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getNXJTPlatformSecretInfo(); + // 如果开始时间、结束时间为空,则默认为一个月内 if (StringUtils.isBlank(dto.getStartTime()) && StringUtils.isBlank(dto.getEndTime())) { dto.setStartTime(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, DateUtils.addMonths(new Date(), -1))); @@ -212,17 +194,8 @@ public class NXJTServiceImpl implements NXJTService { map.put("orderInfos", resultList); // 加密 - Map resultMap = Maps.newLinkedHashMap(); - // 加密数据 - byte[] encryptText = Cryptos.aesEncrypt(JSON.toJSONString(map).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 resultMap = ThirdPartyPlatformUtils.generateResultMapV2(map, thirdPartySecretInfoVO.getOurDataSecret(), + thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret()); return resultMap; } @@ -238,4 +211,19 @@ public class NXJTServiceImpl implements NXJTService { return queryOrdersInfoByPlateNumber(dto); // return null; } + + /** + * 获取宁夏交投平台配置密钥信息 + * + * @return + */ + private ThirdPartySecretInfoVO getNXJTPlatformSecretInfo() { + // 通过第三方平台类型查询相关配置信息 + ThirdPartySecretInfoVO thirdPartySecretInfoVO = thirdpartySecretInfoService.queryByThirdPlatformType(ThirdPlatformTypeEnum.NING_XIA_JIAO_TOU.getTypeCode()); + if (thirdPartySecretInfoVO == null) { + throw new BusinessException(ReturnCodeEnum.CODE_SELECT_INFO_IS_NULL); + } + thirdPartySecretInfoVO.setOurOperatorId(Constants.OPERATORID_JIANG_SU); + return thirdPartySecretInfoVO; + } } diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/HaiNanPlatformServiceImpl.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/HaiNanPlatformServiceImpl.java index 157bb1623..6b5cdb512 100644 --- a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/HaiNanPlatformServiceImpl.java +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/HaiNanPlatformServiceImpl.java @@ -13,6 +13,8 @@ import com.jsowell.common.enums.thirdparty.ThirdPartyOperatorIdEnum; import com.jsowell.common.enums.thirdparty.ThirdPlatformTypeEnum; import com.jsowell.common.enums.ykc.OrderStatusEnum; import com.jsowell.common.enums.ykc.PileConnectorDataBaseStatusEnum; +import com.jsowell.common.enums.ykc.ReturnCodeEnum; +import com.jsowell.common.exception.BusinessException; import com.jsowell.common.util.*; import com.jsowell.pile.domain.*; import com.jsowell.pile.domain.ykcCommond.StartChargingCommand; @@ -37,10 +39,8 @@ import com.jsowell.thirdparty.lianlian.vo.QueryStopChargeVO; import com.jsowell.thirdparty.platform.service.ThirdPartyPlatformService; import com.jsowell.thirdparty.platform.factory.ThirdPartyPlatformFactory; import com.jsowell.thirdparty.platform.domain.HNStationInfo; -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 com.jsowell.thirdparty.platform.util.*; +import com.jsowell.thirdparty.service.ThirdpartySecretInfoService; import com.jsowell.thirdparty.zhongdianlian.service.ZDLService; import org.apache.commons.collections4.CollectionUtils; import org.slf4j.Logger; @@ -89,10 +89,7 @@ public class HaiNanPlatformServiceImpl implements ThirdPartyPlatformService { private OrderBasicInfoService orderBasicInfoService; @Autowired - private ThirdPartyPlatformConfigService thirdPartyPlatformConfigService; - - @Autowired - private ThirdPartySettingInfoService thirdPartySettingInfoService; + private ThirdpartySecretInfoService thirdpartySecretInfoService; @Resource private ThirdPartyStationRelationService thirdPartyStationRelationService; @@ -146,10 +143,8 @@ public class HaiNanPlatformServiceImpl implements ThirdPartyPlatformService { // 未查到数据 return null; } - ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorId()); - if (configInfo == null) { - return null; - } + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getHaiNanPlatformSecretInfo(); + PageInfo pageInfo = new PageInfo<>(stationInfos); List resultList = new ArrayList<>(); HNStationInfo stationInfo = null; @@ -211,13 +206,8 @@ public class HaiNanPlatformServiceImpl implements ThirdPartyPlatformService { map.put("ItemSize", resultList.size()); map.put("StationInfos", resultList); - Map resultMap = Maps.newLinkedHashMap(); - // 加密数据 - String encryptData = Cryptos.aesEncrypt(JSON.toJSONString(map), configInfo.getDataSecret(), configInfo.getDataSecretIv()); - resultMap.put("Data", encryptData); - // 生成sig - String resultSign = GBSignUtils.sign(resultMap, configInfo.getSignSecret()); - resultMap.put("Sig", resultSign); + Map resultMap = ThirdPartyPlatformUtils.generateResultMapV2(map, thirdPartySecretInfoVO.getOurDataSecret(), + thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret()); return resultMap; } @@ -415,10 +405,8 @@ public class HaiNanPlatformServiceImpl implements ThirdPartyPlatformService { List stationIds = dto.getStationIds(); List StationStatusInfos = new ArrayList<>(); List ConnectorStatusInfos = new ArrayList<>(); - ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorId()); - if (configInfo == null) { - return null; - } + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getHaiNanPlatformSecretInfo(); + ConnectorStatusInfo connectorStatusInfo; for (String stationId : stationIds) { StationStatusInfo stationStatusInfo = new StationStatusInfo(); @@ -481,13 +469,8 @@ public class HaiNanPlatformServiceImpl implements ThirdPartyPlatformService { map.put("Total", total); map.put("StationStatusInfos", collect); - Map resultMap = Maps.newLinkedHashMap(); - // 加密数据 - String encryptData = Cryptos.aesEncrypt(JSON.toJSONString(map), configInfo.getDataSecret(), configInfo.getDataSecretIv()); - resultMap.put("Data", encryptData); - // 生成sig - String resultSign = GBSignUtils.sign(resultMap, configInfo.getSignSecret()); - resultMap.put("Sig", resultSign); + Map resultMap = ThirdPartyPlatformUtils.generateResultMapV2(map, thirdPartySecretInfoVO.getOurDataSecret(), + thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret()); return resultMap; } @@ -499,10 +482,7 @@ public class HaiNanPlatformServiceImpl implements ThirdPartyPlatformService { @Override public Map queryStationStats(QueryStationInfoDTO dto) { // 查询信息 - ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorId()); - if (configInfo == null) { - return null; - } + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getHaiNanPlatformSecretInfo(); // 根据站点id 查出这段时间的充电量 List list = orderBasicInfoService.getAccumulativeInfoForLianLian(dto); if (CollectionUtils.isEmpty(list)) { @@ -575,13 +555,8 @@ public class HaiNanPlatformServiceImpl implements ThirdPartyPlatformService { Map map = new LinkedHashMap<>(); map.put("StationStats", stationStatsInfo); - Map resultMap = Maps.newLinkedHashMap(); - // 加密数据 - String encryptData = Cryptos.aesEncrypt(JSON.toJSONString(map), configInfo.getDataSecret(), configInfo.getDataSecretIv()); - resultMap.put("Data", encryptData); - // 生成sig - String resultSign = GBSignUtils.sign(resultMap, configInfo.getSignSecret()); - resultMap.put("Sig", resultSign); + Map resultMap = ThirdPartyPlatformUtils.generateResultMapV2(map, thirdPartySecretInfoVO.getOurDataSecret(), + thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret()); return resultMap; } @@ -598,10 +573,8 @@ public class HaiNanPlatformServiceImpl implements ThirdPartyPlatformService { String equipAuthSeq = dto.getEquipAuthSeq(); // MA1X78KH5202311071202015732 String pileConnectorCode = dto.getConnectorID(); // 先查询配置密钥相关信息 - ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorID()); - if (configInfo == null) { - return null; - } + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getHaiNanPlatformSecretInfo(); + // 根据桩编号查询数据 // String merchantId = StringUtils.substring(equipAuthSeq, 0, 9); // String pileSn = StringUtils.substring(pileConnectorCode, 0, 14); @@ -628,13 +601,8 @@ public class HaiNanPlatformServiceImpl implements ThirdPartyPlatformService { vo.setFailReason(2); // 设备检测失败 vo.setFailReasonMsg("未查到该桩的数据"); } - Map resultMap = Maps.newLinkedHashMap(); - // 加密数据 - String encryptData = Cryptos.aesEncrypt(JSON.toJSONString(vo), configInfo.getDataSecret(), configInfo.getDataSecretIv()); - resultMap.put("Data", encryptData); - // 生成sig - String resultSign = GBSignUtils.sign(resultMap, configInfo.getSignSecret()); - resultMap.put("Sig", resultSign); + Map resultMap = ThirdPartyPlatformUtils.generateResultMapV2(vo, thirdPartySecretInfoVO.getOurDataSecret(), + thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret()); return resultMap; } @@ -647,10 +615,8 @@ public class HaiNanPlatformServiceImpl implements ThirdPartyPlatformService { public Map queryEquipBusinessPolicy(QueryStartChargeDTO dto) { List policyInfoList = new ArrayList<>(); String pileConnectorCode = dto.getConnectorID(); - ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorId()); - if (configInfo == null) { - return null; - } + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getHaiNanPlatformSecretInfo(); + // 截取桩号 // String pileSn = StringUtils.substring(pileConnectorCode, 0, 14); String pileSn = YKCUtils.getPileSn(pileConnectorCode); @@ -686,13 +652,8 @@ public class HaiNanPlatformServiceImpl implements ThirdPartyPlatformService { .policyInfos(policyInfoList) .build(); - Map resultMap = Maps.newLinkedHashMap(); - // 加密数据 - String encryptData = Cryptos.aesEncrypt(JSON.toJSONString(vo), configInfo.getDataSecret(), configInfo.getDataSecretIv()); - resultMap.put("Data", encryptData); - // 生成sig - String resultSign = GBSignUtils.sign(resultMap, configInfo.getSignSecret()); - resultMap.put("Sig", resultSign); + Map resultMap = ThirdPartyPlatformUtils.generateResultMapV2(vo, thirdPartySecretInfoVO.getOurDataSecret(), + thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret()); return resultMap; } @@ -769,10 +730,7 @@ public class HaiNanPlatformServiceImpl implements ThirdPartyPlatformService { // 平台已存在订单 return null; } - ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorId()); - if (configInfo == null) { - return null; - } + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getHaiNanPlatformSecretInfo(); // 生成订单 Map map = orderBasicInfoService.generateOrderForThirdParty(dto); String orderCode = (String) map.get("orderCode"); @@ -805,13 +763,8 @@ public class HaiNanPlatformServiceImpl implements ThirdPartyPlatformService { vo.setStartChargeSeqStat(1); } - Map resultMap = Maps.newLinkedHashMap(); - // 加密数据 - String encryptData = Cryptos.aesEncrypt(JSON.toJSONString(vo), configInfo.getDataSecret(), configInfo.getDataSecretIv()); - resultMap.put("Data", encryptData); - // 生成sig - String resultSign = GBSignUtils.sign(resultMap, configInfo.getSignSecret()); - resultMap.put("Sig", resultSign); + Map resultMap = ThirdPartyPlatformUtils.generateResultMapV2(vo, thirdPartySecretInfoVO.getOurDataSecret(), + thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret()); return resultMap; } @@ -831,11 +784,7 @@ public class HaiNanPlatformServiceImpl implements ThirdPartyPlatformService { if (orderInfo == null) { return null; } - ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(operatorID); - // logger.info(operatorName + "查询密钥信息 configInfo:{}", configInfo); - if (configInfo == null) { - return null; - } + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getHaiNanPlatformSecretInfo(); OrderDetail orderDetail = orderBasicInfoService.getOrderDetailByOrderCode(orderInfo.getOrderCode()); // 通过订单号查询实时数据 List realTimeData = orderBasicInfoService.getChargingRealTimeData(orderInfo.getTransactionCode()); @@ -884,13 +833,8 @@ public class HaiNanPlatformServiceImpl implements ThirdPartyPlatformService { .build(); } - Map resultMap = Maps.newLinkedHashMap(); - // 加密数据 - String encryptData = Cryptos.aesEncrypt(JSON.toJSONString(vo), configInfo.getDataSecret(), configInfo.getDataSecretIv()); - resultMap.put("Data", encryptData); - // 生成sig - String resultSign = GBSignUtils.sign(resultMap, configInfo.getSignSecret()); - resultMap.put("Sig", resultSign); + Map resultMap = ThirdPartyPlatformUtils.generateResultMapV2(vo, thirdPartySecretInfoVO.getOurDataSecret(), + thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret()); return resultMap; } @@ -931,9 +875,9 @@ public class HaiNanPlatformServiceImpl implements ThirdPartyPlatformService { } String data = map.get("Data"); // 解密data (此处解密需用 thirdparty_platform_config 的密钥配置) - ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(operatorIdByType); + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getHaiNanPlatformSecretInfo(); byte[] plainText = Cryptos.aesDecrypt(Encodes.decodeBase64(data), - configInfo.getDataSecret().getBytes(), configInfo.getDataSecretIv().getBytes()); + thirdPartySecretInfoVO.getOurDataSecret().getBytes(), thirdPartySecretInfoVO.getOurDataSecretIv().getBytes()); String dataStr = new String(plainText, StandardCharsets.UTF_8); // 转成对应的对象 QueryChargingStatusVO vo = JSONObject.parseObject(dataStr, QueryChargingStatusVO.class); @@ -962,10 +906,8 @@ public class HaiNanPlatformServiceImpl implements ThirdPartyPlatformService { if (orderInfo == null) { return null; } - ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorId()); - if (configInfo == null) { - return null; - } + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getHaiNanPlatformSecretInfo(); + // 若状态为充电中,则发送停机指令 if (StringUtils.equals(OrderStatusEnum.IN_THE_CHARGING.getValue(), orderInfo.getOrderStatus())) { // 充电中 @@ -986,13 +928,8 @@ public class HaiNanPlatformServiceImpl implements ThirdPartyPlatformService { // 如果是新电途平台,则将 startChargeSeqStat 改为 3-停止中 vo.setStartChargeSeqStat(3); } - Map resultMap = Maps.newLinkedHashMap(); - // 加密数据 - String encryptData = Cryptos.aesEncrypt(JSON.toJSONString(vo), configInfo.getDataSecret(), configInfo.getDataSecretIv()); - resultMap.put("Data", encryptData); - // 生成sig - String resultSign = GBSignUtils.sign(resultMap, configInfo.getSignSecret()); - resultMap.put("Sig", resultSign); + Map resultMap = ThirdPartyPlatformUtils.generateResultMapV2(vo, thirdPartySecretInfoVO.getOurDataSecret(), + thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret()); return resultMap; } @@ -1042,5 +979,18 @@ public class HaiNanPlatformServiceImpl implements ThirdPartyPlatformService { return result; } - + /** + * 获取海南省平台配置密钥信息 + * + * @return + */ + private ThirdPartySecretInfoVO getHaiNanPlatformSecretInfo() { + // 通过第三方平台类型查询相关配置信息 + ThirdPartySecretInfoVO thirdPartySecretInfoVO = thirdpartySecretInfoService.queryByThirdPlatformType(ThirdPlatformTypeEnum.HAI_NAN_1_PLATFORM.getTypeCode()); + if (thirdPartySecretInfoVO == null) { + throw new BusinessException(ReturnCodeEnum.CODE_SELECT_INFO_IS_NULL); + } + thirdPartySecretInfoVO.setOurOperatorId(Constants.OPERATORID_JIANG_SU); + return thirdPartySecretInfoVO; + } } diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/LianLianPlatformServiceImpl.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/LianLianPlatformServiceImpl.java index 7e7b58cf1..e85d91f3a 100644 --- a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/LianLianPlatformServiceImpl.java +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/LianLianPlatformServiceImpl.java @@ -16,6 +16,7 @@ import com.jsowell.common.enums.thirdparty.ThirdPlatformTypeEnum; import com.jsowell.common.enums.ykc.OrderPayModeEnum; import com.jsowell.common.enums.ykc.OrderStatusEnum; import com.jsowell.common.enums.ykc.PileConnectorDataBaseStatusEnum; +import com.jsowell.common.enums.ykc.ReturnCodeEnum; import com.jsowell.common.exception.BusinessException; import com.jsowell.common.util.*; import com.jsowell.pile.domain.*; @@ -86,12 +87,6 @@ public class LianLianPlatformServiceImpl implements ThirdPartyPlatformService { @Autowired private OrderBasicInfoService orderBasicInfoService; - @Autowired - private ThirdPartyPlatformConfigService thirdPartyPlatformConfigService; - - @Autowired - private ThirdPartySettingInfoService thirdPartySettingInfoService; - @Resource private ThirdPartyStationRelationService thirdPartyStationRelationService; @@ -201,10 +196,8 @@ public class LianLianPlatformServiceImpl implements ThirdPartyPlatformService { // 未查到数据 return null; } - ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorId()); - if (configInfo == null) { - return null; - } + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getLianLianPlatformSecretInfo(); + PageInfo pageInfo = new PageInfo<>(stationInfos); List resultList = new ArrayList<>(); for (ThirdPartyStationInfoVO pileStationInfo : pageInfo.getList()) { @@ -256,13 +249,8 @@ public class LianLianPlatformServiceImpl implements ThirdPartyPlatformService { map.put("ItemSize", resultList.size()); map.put("StationInfos", resultList); - Map resultMap = Maps.newLinkedHashMap(); - // 加密数据 - String encryptData = Cryptos.aesEncrypt(JSON.toJSONString(map), configInfo.getDataSecret(), configInfo.getDataSecretIv()); - resultMap.put("Data", encryptData); - // 生成sig - String resultSign = GBSignUtils.sign(resultMap, configInfo.getSignSecret()); - resultMap.put("Sig", resultSign); + Map resultMap = ThirdPartyPlatformUtils.generateResultMapV2(map, thirdPartySecretInfoVO.getOurDataSecret(), + thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret()); return resultMap; } @@ -277,10 +265,8 @@ public class LianLianPlatformServiceImpl implements ThirdPartyPlatformService { List stationIds = dto.getStationIds(); List StationStatusInfos = new ArrayList<>(); List ConnectorStatusInfos = new ArrayList<>(); - ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorId()); - if (configInfo == null) { - return null; - } + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getLianLianPlatformSecretInfo(); + ConnectorStatusInfo connectorStatusInfo; for (String stationId : stationIds) { StationStatusInfo stationStatusInfo = new StationStatusInfo(); @@ -343,13 +329,8 @@ public class LianLianPlatformServiceImpl implements ThirdPartyPlatformService { map.put("Total", total); map.put("StationStatusInfos", collect); - Map resultMap = Maps.newLinkedHashMap(); - // 加密数据 - String encryptData = Cryptos.aesEncrypt(JSON.toJSONString(map), configInfo.getDataSecret(), configInfo.getDataSecretIv()); - resultMap.put("Data", encryptData); - // 生成sig - String resultSign = GBSignUtils.sign(resultMap, configInfo.getSignSecret()); - resultMap.put("Sig", resultSign); + Map resultMap = ThirdPartyPlatformUtils.generateResultMapV2(map, thirdPartySecretInfoVO.getOurDataSecret(), + thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret()); return resultMap; } @@ -361,10 +342,8 @@ public class LianLianPlatformServiceImpl implements ThirdPartyPlatformService { */ @Override public Map queryStationStats(QueryStationInfoDTO dto) { - ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorId()); - if (configInfo == null) { - return null; - } + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getLianLianPlatformSecretInfo(); + // 根据站点id 查出这段时间的充电量 List list = orderBasicInfoService.getAccumulativeInfoForLianLian(dto); if (CollectionUtils.isEmpty(list)) { @@ -437,13 +416,8 @@ public class LianLianPlatformServiceImpl implements ThirdPartyPlatformService { Map map = new LinkedHashMap<>(); map.put("StationStats", stationStatsInfo); - Map resultMap = Maps.newLinkedHashMap(); - // 加密数据 - String encryptData = Cryptos.aesEncrypt(JSON.toJSONString(map), configInfo.getDataSecret(), configInfo.getDataSecretIv()); - resultMap.put("Data", encryptData); - // 生成sig - String resultSign = GBSignUtils.sign(resultMap, configInfo.getSignSecret()); - resultMap.put("Sig", resultSign); + Map resultMap = ThirdPartyPlatformUtils.generateResultMapV2(map, thirdPartySecretInfoVO.getOurDataSecret(), + thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret()); return resultMap; } @@ -462,14 +436,14 @@ public class LianLianPlatformServiceImpl implements ThirdPartyPlatformService { // 通过第三方配置类型查询相关配置信息 ThirdPartySettingInfo settingInfo = new ThirdPartySettingInfo(); settingInfo.setType(thirdPlatformType); - ThirdPartySettingInfo thirdPartySettingInfo = thirdPartySettingInfoService.selectSettingInfo(settingInfo); + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getLianLianPlatformSecretInfo(); - String operatorId = thirdPartySettingInfo.getOperatorId(); - String operatorSecret = thirdPartySettingInfo.getOperatorSecret(); - String signSecret = thirdPartySettingInfo.getSignSecret(); - String dataSecret = thirdPartySettingInfo.getDataSecret(); - String dataSecretIv = thirdPartySettingInfo.getDataSecretIv(); - String urlAddress = thirdPartySettingInfo.getUrlAddress(); + String operatorId = thirdPartySecretInfoVO.getTheirOperatorId(); + String operatorSecret = thirdPartySecretInfoVO.getTheirOperatorSecret(); + String signSecret = thirdPartySecretInfoVO.getTheirSigSecret(); + String dataSecret = thirdPartySecretInfoVO.getTheirDataSecret(); + String dataSecretIv = thirdPartySecretInfoVO.getTheirDataSecretIv(); + String urlAddress = thirdPartySecretInfoVO.getTheirUrlPrefix(); // 组装联联平台所需要的数据格式 StationInfo info = StationInfo.builder() @@ -1103,10 +1077,8 @@ public class LianLianPlatformServiceImpl implements ThirdPartyPlatformService { return null; } // 通过operatorID 查出 operatorSecret - ThirdPartyPlatformConfig platformConfig = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorId()); - if (platformConfig == null) { - return null; - } + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getLianLianPlatformSecretInfo(); + // orderInfo 和 orderDetail 都不为空,再根据传过来的数据进行修改数据库信息 confirmResult = Constants.zero; orderDetail.setTotalUsedElectricity(dto.getTotalPower()); // 累计充电量 @@ -1116,10 +1088,10 @@ public class LianLianPlatformServiceImpl implements ThirdPartyPlatformService { Map resultMap = Maps.newLinkedHashMap(); // 加密数据 - String encrypt = Cryptos.encrypt(JSON.toJSONString(map), platformConfig.getDataSecret(), platformConfig.getDataSecretIv()); + String encrypt = Cryptos.encrypt(JSON.toJSONString(map), thirdPartySecretInfoVO.getOurDataSecret(), thirdPartySecretInfoVO.getOurDataSecretIv()); resultMap.put("Data", encrypt); // 生成sig - String resultSign = GBSignUtils.sign(resultMap, platformConfig.getSignSecret()); + String resultSign = GBSignUtils.sign(resultMap, thirdPartySecretInfoVO.getOurSigSecret()); resultMap.put("Sig", resultSign); return resultMap; } @@ -1132,16 +1104,13 @@ public class LianLianPlatformServiceImpl implements ThirdPartyPlatformService { */ @Override public Map queryEquipAuth(QueryEquipmentDTO dto) { - Map resultMap = Maps.newLinkedHashMap(); EquipmentAuthVO vo = new EquipmentAuthVO(); String equipAuthSeq = dto.getEquipAuthSeq(); // MA1X78KH5202311071202015732 String pileConnectorCode = ThirdPartyPlatformUtils.extractConnectorID(dto.getConnectorID()); // 先查询配置密钥相关信息 - ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorID()); - if (configInfo == null) { - return null; - } + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getLianLianPlatformSecretInfo(); + // 根据桩编号查询数据 // String merchantId = StringUtils.substring(equipAuthSeq, 0, 9); // String pileSn = StringUtils.substring(pileConnectorCode, 0, 14); @@ -1176,15 +1145,8 @@ public class LianLianPlatformServiceImpl implements ThirdPartyPlatformService { vo.setFailReason(failReason); // 设备检测失败 vo.setFailReasonMsg(failReasonMsg); // 加密数据 - 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); - + Map resultMap = ThirdPartyPlatformUtils.generateResultMapV2(vo, thirdPartySecretInfoVO.getOurDataSecret(), + thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret()); return resultMap; } @@ -1281,10 +1243,8 @@ public class LianLianPlatformServiceImpl implements ThirdPartyPlatformService { if (orderInfo == null) { return null; } - ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorId()); - if (configInfo == null) { - return null; - } + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getLianLianPlatformSecretInfo(); + // 若状态为充电中,则发送停机指令 if (StringUtils.equals(OrderStatusEnum.IN_THE_CHARGING.getValue(), orderInfo.getOrderStatus())) { // 充电中 @@ -1306,17 +1266,8 @@ public class LianLianPlatformServiceImpl implements ThirdPartyPlatformService { vo.setStartChargeSeqStat(3); } // 加密 - Map resultMap = Maps.newLinkedHashMap(); - // 加密数据 - 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); - + Map resultMap = ThirdPartyPlatformUtils.generateResultMapV2(vo, thirdPartySecretInfoVO.getOurDataSecret(), + thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret()); return resultMap; } @@ -1336,11 +1287,8 @@ public class LianLianPlatformServiceImpl implements ThirdPartyPlatformService { if (orderInfo == null) { return null; } - ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(operatorID); - // logger.info(operatorName + "查询密钥信息 configInfo:{}", configInfo); - if (configInfo == null) { - return null; - } + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getLianLianPlatformSecretInfo(); + OrderDetail orderDetail = orderBasicInfoService.getOrderDetailByOrderCode(orderInfo.getOrderCode()); // 通过订单号查询实时数据 List realTimeData = orderBasicInfoService.getChargingRealTimeData(orderInfo.getTransactionCode()); @@ -1391,18 +1339,23 @@ public class LianLianPlatformServiceImpl implements ThirdPartyPlatformService { } // 加密 - Map resultMap = Maps.newLinkedHashMap(); - // 加密数据 - 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); - + Map resultMap = ThirdPartyPlatformUtils.generateResultMapV2(vo, thirdPartySecretInfoVO.getOurDataSecret(), + thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret()); return resultMap; } + /** + * 获取联联平台配置密钥信息 + * + * @return + */ + private ThirdPartySecretInfoVO getLianLianPlatformSecretInfo() { + // 通过第三方平台类型查询相关配置信息 + ThirdPartySecretInfoVO thirdPartySecretInfoVO = thirdpartySecretInfoService.queryByThirdPlatformType(ThirdPlatformTypeEnum.LIAN_LIAN_PLATFORM.getTypeCode()); + if (thirdPartySecretInfoVO == null) { + throw new BusinessException(ReturnCodeEnum.CODE_SELECT_INFO_IS_NULL); + } + thirdPartySecretInfoVO.setOurOperatorId(Constants.OPERATORID_JIANG_SU); + return thirdPartySecretInfoVO; + } } diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/NeiMengGuPlatformServiceImpl.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/NeiMengGuPlatformServiceImpl.java index 160fbb385..5ca48cccd 100644 --- a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/NeiMengGuPlatformServiceImpl.java +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/NeiMengGuPlatformServiceImpl.java @@ -127,7 +127,7 @@ public class NeiMengGuPlatformServiceImpl implements ThirdPartyPlatformService { String operatorId = dto.getPlatformID(); // 通过operatorId 查出 operatorSecret - ThirdPartySecretInfoVO thirdPartySecretInfoVO = thirdpartySecretInfoService.queryByOperatorId(operatorId); + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getNeiMengGuPlatformSecretInfo(); if (thirdPartySecretInfoVO == null) { failReason = 1; succStat = 1; @@ -187,7 +187,7 @@ public class NeiMengGuPlatformServiceImpl implements ThirdPartyPlatformService { operatorInfos.add(supOperatorInfo); } } - ThirdPartySecretInfoVO thirdPartySecretInfoVO = thirdpartySecretInfoService.queryByThirdPlatformType(thirdPlatformType); + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getNeiMengGuPlatformSecretInfo(); // 组装结果集 Map map = Maps.newHashMap(); @@ -225,10 +225,8 @@ public class NeiMengGuPlatformServiceImpl implements ThirdPartyPlatformService { // 未查到数据 return null; } - ThirdPartySecretInfoVO thirdPartySecretInfoVO = thirdpartySecretInfoService.queryByThirdPlatformType(thirdPlatformType); - if (thirdPartySecretInfoVO == null) { - return null; - } + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getNeiMengGuPlatformSecretInfo(); + PageInfo pageInfo = new PageInfo<>(stationInfos); List resultList = new ArrayList<>(); for (ThirdPartyStationInfoVO pileStationInfo : pageInfo.getList()) { @@ -346,10 +344,8 @@ public class NeiMengGuPlatformServiceImpl implements ThirdPartyPlatformService { List stationIds = dto.getStationIds(); List StationStatusInfos = new ArrayList<>(); List connectorStatusInfos = new ArrayList<>(); - ThirdPartySecretInfoVO thirdPartySecretInfoVO = thirdpartySecretInfoService.queryByThirdPlatformType(thirdPlatformType); - if (thirdPartySecretInfoVO == null) { - return null; - } + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getNeiMengGuPlatformSecretInfo(); + ConnectorStatusInfo connectorStatusInfo; for (String stationId : stationIds) { StationStatusInfo stationStatusInfo = new StationStatusInfo(); @@ -417,10 +413,8 @@ public class NeiMengGuPlatformServiceImpl implements ThirdPartyPlatformService { public Map queryStationStatus(QueryStationInfoDTO dto) { List stationIds = dto.getStationIds(); List stationStatusInfos = Lists.newArrayList(); - ThirdPartySecretInfoVO thirdPartySecretInfoVO = thirdpartySecretInfoService.queryByThirdPlatformType(thirdPlatformType); - if (thirdPartySecretInfoVO == null) { - return null; - } + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getNeiMengGuPlatformSecretInfo(); + for (String stationId : stationIds) { // 查询站点的运营商信息 PileMerchantInfoVO pileMerchantInfoVO = pileMerchantInfoService.queryMerchantInfoByStationId(stationId); @@ -482,17 +476,15 @@ public class NeiMengGuPlatformServiceImpl implements ThirdPartyPlatformService { // String pileSn = StringUtils.substring(pileConnectorCode, 0, 14); String pileSn = YKCUtils.getPileSn(pileConnectorCode); PileStationVO stationVO = pileStationInfoService.getStationInfoByPileSn(pileSn); - // 通过站点id查询相关配置信息 - ThirdPartyStationRelationVO relationInfo = thirdPartyStationRelationService.selectRelationInfo(stationVO.getId()); - if (relationInfo == null) { - return null; - } - String operatorId = relationInfo.getOperatorId(); - String operatorSecret = relationInfo.getOperatorSecret(); - String signSecret = relationInfo.getSignSecret(); - String dataSecret = relationInfo.getDataSecret(); - String dataSecretIv = relationInfo.getDataSecretIv(); - String urlAddress = relationInfo.getUrlAddress(); + // 查询相关配置信息 + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getNeiMengGuPlatformSecretInfo(); + + String operatorId = thirdPartySecretInfoVO.getTheirOperatorId(); + String operatorSecret = thirdPartySecretInfoVO.getTheirOperatorSecret(); + String signSecret = thirdPartySecretInfoVO.getTheirSigSecret(); + String dataSecret = thirdPartySecretInfoVO.getTheirDataSecret(); + String dataSecretIv = thirdPartySecretInfoVO.getTheirDataSecretIv(); + String urlAddress = thirdPartySecretInfoVO.getTheirUrlPrefix(); String url = urlAddress + BusinessInformationExchangeEnum.NOTIFICATION_STATION_STATUS.getValue(); ConnectorStatusInfo info = ConnectorStatusInfo.builder() @@ -571,18 +563,15 @@ public class NeiMengGuPlatformServiceImpl implements ThirdPartyPlatformService { return null; } - // 通过站点id查询相关配置信息 - ThirdPartyStationRelationVO relationInfo = thirdPartyStationRelationService.selectRelationInfo(orderBasicInfo.getStationId()); - if (relationInfo == null) { - return null; - } + // 查询相关配置信息 + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getNeiMengGuPlatformSecretInfo(); - String operatorId = relationInfo.getOperatorId(); - String operatorSecret = relationInfo.getOperatorSecret(); - String signSecret = relationInfo.getSignSecret(); - String dataSecret = relationInfo.getDataSecret(); - String dataSecretIv = relationInfo.getDataSecretIv(); - String urlAddress = relationInfo.getUrlAddress(); + String operatorId = thirdPartySecretInfoVO.getTheirOperatorId(); + String operatorSecret = thirdPartySecretInfoVO.getTheirOperatorSecret(); + String signSecret = thirdPartySecretInfoVO.getTheirSigSecret(); + String dataSecret = thirdPartySecretInfoVO.getTheirDataSecret(); + String dataSecretIv = thirdPartySecretInfoVO.getTheirDataSecretIv(); + String urlAddress = thirdPartySecretInfoVO.getTheirUrlPrefix(); // 根据订单号查询订单详情 OrderDetail orderDetail = orderBasicInfoService.getOrderDetailByOrderCode(orderCode); @@ -696,38 +685,28 @@ public class NeiMengGuPlatformServiceImpl implements ThirdPartyPlatformService { public String notificationEquipChargeStatus(String orderCode) { // 根据订单号查询订单信息 OrderBasicInfo orderInfo = orderBasicInfoService.getOrderInfoByOrderCode(orderCode); - // 通过第三方平台类型查询相关配置信息 - ThirdPartyStationRelation relation = new ThirdPartyStationRelation(); - relation.setThirdPartyType(orderInfo.getThirdPartyType()); - ThirdPartyStationRelationVO relationInfo = thirdPartyStationRelationService.selectRelationInfo(relation); - // ThirdPartySettingInfo settingInfo = thirdPartySettingInfoService.getInfoByStationId(Long.parseLong(orderInfo.getStationId())); - if (relationInfo == null) { - return null; - } - String operatorId = relationInfo.getOperatorId(); - String operatorSecret = relationInfo.getOperatorSecret(); - String signSecret = relationInfo.getSignSecret(); - String dataSecret = relationInfo.getDataSecret(); - String dataSecretIv = relationInfo.getDataSecretIv(); - String urlAddress = relationInfo.getUrlAddress(); - String thirdPartyType = relationInfo.getThirdPartyType(); + // 查询相关配置信息 + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getNeiMengGuPlatformSecretInfo(); + + String operatorId = thirdPartySecretInfoVO.getTheirOperatorId(); + String operatorSecret = thirdPartySecretInfoVO.getTheirOperatorSecret(); + String signSecret = thirdPartySecretInfoVO.getTheirSigSecret(); + String dataSecret = thirdPartySecretInfoVO.getTheirDataSecret(); + String dataSecretIv = thirdPartySecretInfoVO.getTheirDataSecretIv(); + String urlAddress = thirdPartySecretInfoVO.getTheirUrlPrefix(); // 调用 查询充电状态方法 QueryEquipChargeStatusDTO dto = new QueryEquipChargeStatusDTO(); dto.setStartChargeSeq(orderCode); - // 根据type获取operatorId - String operatorIdByType = ThirdPartyOperatorIdEnum.getOperatorIdByType(thirdPartyType); - dto.setOperatorID(operatorIdByType); + dto.setOperatorID(thirdPartySecretInfoVO.getTheirOperatorId()); Map map = queryEquipChargeStatus(dto); if (map == null) { return null; } String data = map.get("Data"); // 解密data (此处解密需用 thirdparty_platform_config 的密钥配置) - ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(operatorIdByType); - ThirdPartySecretInfoVO thirdPartySecretInfoVO = thirdpartySecretInfoService.queryByThirdPlatformType(thirdPlatformType); byte[] plainText = Cryptos.aesDecrypt(Encodes.decodeBase64(data), - configInfo.getDataSecret().getBytes(), configInfo.getDataSecretIv().getBytes()); + thirdPartySecretInfoVO.getOurDataSecret().getBytes(), thirdPartySecretInfoVO.getOurDataSecretIv().getBytes()); String dataStr = new String(plainText, StandardCharsets.UTF_8); // 转成对应的对象 QueryChargingStatusVO vo = JSONObject.parseObject(dataStr, QueryChargingStatusVO.class); @@ -763,20 +742,17 @@ public class NeiMengGuPlatformServiceImpl implements ThirdPartyPlatformService { public String notificationChargeOrderInfoHistory(String orderCode) { // 根据订单号查询出信息 OrderBasicInfo orderBasicInfo = orderBasicInfoService.getOrderInfoByOrderCode(orderCode); - - // 通过站点id查询相关配置信息 - ThirdPartyStationRelationVO relationInfo = thirdPartyStationRelationService.selectRelationInfo(orderBasicInfo.getStationId()); - if (relationInfo == null) { - return null; - } OrderDetail orderDetail = orderBasicInfoService.getOrderDetailByOrderCode(orderCode); - String operatorId = relationInfo.getOperatorId(); - String operatorSecret = relationInfo.getOperatorSecret(); - String signSecret = relationInfo.getSignSecret(); - String dataSecret = relationInfo.getDataSecret(); - String dataSecretIv = relationInfo.getDataSecretIv(); - String urlAddress = relationInfo.getUrlAddress(); + // 查询相关配置信息 + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getNeiMengGuPlatformSecretInfo(); + + String operatorId = thirdPartySecretInfoVO.getTheirOperatorId(); + String operatorSecret = thirdPartySecretInfoVO.getTheirOperatorSecret(); + String signSecret = thirdPartySecretInfoVO.getTheirSigSecret(); + String dataSecret = thirdPartySecretInfoVO.getTheirDataSecret(); + String dataSecretIv = thirdPartySecretInfoVO.getTheirDataSecretIv(); + String urlAddress = thirdPartySecretInfoVO.getTheirUrlPrefix(); String url = urlAddress + "supervise_notification_charge_order_info_history"; @@ -898,5 +874,19 @@ public class NeiMengGuPlatformServiceImpl implements ThirdPartyPlatformService { return resultList; } + /** + * 获取内蒙古平台配置密钥信息 + * + * @return + */ + private ThirdPartySecretInfoVO getNeiMengGuPlatformSecretInfo() { + // 通过第三方平台类型查询相关配置信息 + ThirdPartySecretInfoVO thirdPartySecretInfoVO = thirdpartySecretInfoService.queryByThirdPlatformType(ThirdPlatformTypeEnum.NEI_MENG_GU_PLATFORM.getTypeCode()); + if (thirdPartySecretInfoVO == null) { + throw new BusinessException(ReturnCodeEnum.CODE_SELECT_INFO_IS_NULL); + } + thirdPartySecretInfoVO.setOurOperatorId(Constants.OPERATORID_JIANG_SU); + return thirdPartySecretInfoVO; + } } diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/QingHaiPlatformServiceImpl.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/QingHaiPlatformServiceImpl.java index c65121f23..b621f56c3 100644 --- a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/QingHaiPlatformServiceImpl.java +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/QingHaiPlatformServiceImpl.java @@ -6,6 +6,7 @@ import com.github.pagehelper.PageInfo; 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.BusinessInformationExchangeEnum; import com.jsowell.common.enums.thirdparty.ThirdPlatformTypeEnum; import com.jsowell.common.enums.ykc.OrderStatusEnum; @@ -21,6 +22,7 @@ import com.jsowell.pile.service.*; import com.jsowell.pile.thirdparty.CommonParamsDTO; import com.jsowell.pile.thirdparty.ZDLEquipmentInfo; import com.jsowell.pile.thirdparty.ZDLStationInfo; +import com.jsowell.pile.vo.ThirdPartySecretInfoVO; import com.jsowell.pile.vo.base.ThirdPartyStationInfoVO; import com.jsowell.pile.vo.base.ThirdPartyStationRelationVO; import com.jsowell.pile.vo.uniapp.customer.BillingPriceVO; @@ -50,6 +52,7 @@ import java.math.BigDecimal; import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; /** @@ -86,7 +89,7 @@ public class QingHaiPlatformServiceImpl implements ThirdPartyPlatformService { private PileMerchantInfoService pileMerchantInfoService; @Autowired - private ThirdPartyPlatformConfigService thirdPartyPlatformConfigService; + private RedisCache redisCache; Logger logger = LoggerFactory.getLogger(QingHaiPlatformServiceImpl.class); @@ -111,55 +114,56 @@ public class QingHaiPlatformServiceImpl implements ThirdPartyPlatformService { */ @Override public Map queryToken(CommonParamsDTO dto) { + AccessTokenVO vo = new AccessTokenVO(); + // 0:成功;1:失败 + int succStat = 0; + // 0:无;1:无此对接平台;2:密钥错误; 3~99:自定义 + int failReason = 0; + String operatorId = dto.getOperatorID(); + // token缓存key值 + String redisKey = operatorId + "_token:"; // 通过operatorId 查出 operatorSecret - ThirdPartyPlatformConfig platformConfig = thirdPartyPlatformConfigService.getInfoByOperatorId(operatorId); - if (platformConfig == null) { - throw new BusinessException("1", "无此对接平台"); - } - - String operatorSecret = platformConfig.getOperatorSecret(); - String dataSecret = platformConfig.getDataSecret(); - String dataSecretIv = platformConfig.getDataSecretIv(); - String signSecret = platformConfig.getSignSecret(); - - // 解密data 获取参数中的OperatorSecret - try { + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getQingHaiPlatformSecretInfo(); + if (thirdPartySecretInfoVO == null) { + failReason = 1; + succStat = 1; + } else { + String ourOperatorSecret = thirdPartySecretInfoVO.getOurOperatorSecret(); + String dataSecret = thirdPartySecretInfoVO.getOurDataSecret(); + String dataSecretIv = thirdPartySecretInfoVO.getOurDataSecretIv(); + // 解密data 获取参数中的OperatorSecret String decrypt = Cryptos.decrypt(dto.getData(), dataSecret, dataSecretIv); String inputOperatorSecret = null; if (StringUtils.isNotBlank(decrypt)) { inputOperatorSecret = JSON.parseObject(decrypt).getString("OperatorSecret"); } - if (!StringUtils.equals(operatorSecret, inputOperatorSecret)) { - throw new RuntimeException("密钥不一致"); + // 对比密钥 + if (!StringUtils.equals(ourOperatorSecret, inputOperatorSecret)) { + failReason = 1; + succStat = 1; + } else { + // 先查缓存中是否有已生成的token + String token = redisCache.getCacheObject(redisKey); + int expiredTime = (int) redisCache.getExpire(redisKey); + if (StringUtils.isBlank(token)) { + // 生成token + token = JWTUtils.createToken(operatorId, ourOperatorSecret, JWTUtils.ttlMillis); + expiredTime = (int) (JWTUtils.ttlMillis / 1000); + } + vo.setAccessToken(token); + vo.setTokenAvailableTime(expiredTime); + // 设置缓存 + redisCache.setCacheObject(redisKey, token, expiredTime, TimeUnit.SECONDS); } - } catch (RuntimeException e) { - throw new BusinessException("2", "密钥错误"); } - - // 生成token - String token = JWTUtils.createToken(operatorId, operatorSecret, JWTUtils.ttlMillis); - // 组装返回参数 - AccessTokenVO vo = new AccessTokenVO(); - vo.setAccessToken(token); vo.setOperatorID(operatorId); - vo.setTokenAvailableTime((int) (JWTUtils.ttlMillis / 1000)); - vo.setFailReason(0); - vo.setSuccStat(0); - - Map resultMap = Maps.newLinkedHashMap(); - // 加密数据 - byte[] encryptText = Cryptos.aesEncrypt(JSON.toJSONString(vo).getBytes(), - dataSecret.getBytes(), dataSecretIv.getBytes()); - String encryptData = Encodes.encodeBase64(encryptText); // data - resultMap.put("Ret", "0"); - resultMap.put("Msg", "请求令牌成功!"); - resultMap.put("Data", encryptData); - // 生成sig - String resultSign = GBSignUtils.sign(resultMap, signSecret); - resultMap.put("Sig", resultSign); + vo.setFailReason(failReason); + vo.setSuccStat(succStat); + Map resultMap = ThirdPartyPlatformUtils.generateResultMapV2(vo, thirdPartySecretInfoVO.getOurDataSecret(), + thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret()); return resultMap; } @@ -279,9 +283,10 @@ public class QingHaiPlatformServiceImpl implements ThirdPartyPlatformService { jsonObject.put("ItemSize", resultList.size()); jsonObject.put("StationInfos", resultList); + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getQingHaiPlatformSecretInfo(); // 加密 - Map resultMap = getResultMap(jsonObject); - + Map resultMap = ThirdPartyPlatformUtils.generateResultMapV2(jsonObject, thirdPartySecretInfoVO.getOurDataSecret(), + thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret()); return resultMap; } @@ -294,20 +299,17 @@ public class QingHaiPlatformServiceImpl implements ThirdPartyPlatformService { */ @Override public String notificationStationStatus(PushRealTimeInfoDTO dto) { - String thirdPartyType = dto.getThirdPartyType(); String status = dto.getStatus(); String pileConnectorCode = dto.getPileConnectorCode(); - ThirdPartyStationRelationVO settingInfo = getQingHaiSettingInfo(); - if (settingInfo == null) { - return null; - } - String operatorId = settingInfo.getOperatorId(); - String operatorSecret = settingInfo.getOperatorSecret(); - String signSecret = settingInfo.getSignSecret(); - String dataSecret = settingInfo.getDataSecret(); - String dataSecretIv = settingInfo.getDataSecretIv(); - String urlAddress = settingInfo.getUrlAddress(); + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getQingHaiPlatformSecretInfo(); + + String operatorId = thirdPartySecretInfoVO.getTheirOperatorId(); + String operatorSecret = thirdPartySecretInfoVO.getTheirOperatorSecret(); + String signSecret = thirdPartySecretInfoVO.getTheirSigSecret(); + String dataSecret = thirdPartySecretInfoVO.getTheirDataSecret(); + String dataSecretIv = thirdPartySecretInfoVO.getTheirDataSecretIv(); + String urlAddress = thirdPartySecretInfoVO.getTheirUrlPrefix(); String url = urlAddress + BusinessInformationExchangeEnum.NOTIFICATION_STATION_STATUS.getValue(); ConnectorStatusInfo info = ConnectorStatusInfo.builder() .connectorID(pileConnectorCode) @@ -331,16 +333,14 @@ public class QingHaiPlatformServiceImpl implements ThirdPartyPlatformService { public String notificationEquipChargeStatus(String orderCode) { // 根据订单号查询订单信息 OrderBasicInfo orderInfo = orderBasicInfoService.getOrderInfoByOrderCode(orderCode); - ThirdPartyStationRelationVO settingInfo = getQingHaiSettingInfo(); - if (settingInfo == null) { - return null; - } - String operatorId = settingInfo.getOperatorId(); - String operatorSecret = settingInfo.getOperatorSecret(); - String signSecret = settingInfo.getSignSecret(); - String dataSecret = settingInfo.getDataSecret(); - String dataSecretIv = settingInfo.getDataSecretIv(); - String urlAddress = settingInfo.getUrlAddress(); + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getQingHaiPlatformSecretInfo(); + + String operatorId = thirdPartySecretInfoVO.getTheirOperatorId(); + String operatorSecret = thirdPartySecretInfoVO.getTheirOperatorSecret(); + String signSecret = thirdPartySecretInfoVO.getTheirSigSecret(); + String dataSecret = thirdPartySecretInfoVO.getTheirDataSecret(); + String dataSecretIv = thirdPartySecretInfoVO.getTheirDataSecretIv(); + String urlAddress = thirdPartySecretInfoVO.getTheirUrlPrefix(); String url = urlAddress + "notification_equip_charge_status"; @@ -490,16 +490,14 @@ public class QingHaiPlatformServiceImpl implements ThirdPartyPlatformService { list.add(supStationPowerInfo); // 获取推送配置密钥信息 - ThirdPartyStationRelationVO settingInfo = getQingHaiSettingInfo(); - if (settingInfo == null) { - return null; - } - String operatorId = settingInfo.getOperatorId(); - String operatorSecret = settingInfo.getOperatorSecret(); - String signSecret = settingInfo.getSignSecret(); - String dataSecret = settingInfo.getDataSecret(); - String dataSecretIv = settingInfo.getDataSecretIv(); - String urlAddress = settingInfo.getUrlAddress(); + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getQingHaiPlatformSecretInfo(); + + String operatorId = thirdPartySecretInfoVO.getTheirOperatorId(); + String operatorSecret = thirdPartySecretInfoVO.getTheirOperatorSecret(); + String signSecret = thirdPartySecretInfoVO.getTheirSigSecret(); + String dataSecret = thirdPartySecretInfoVO.getTheirDataSecret(); + String dataSecretIv = thirdPartySecretInfoVO.getTheirDataSecretIv(); + String urlAddress = thirdPartySecretInfoVO.getTheirUrlPrefix(); String url = urlAddress + "supervise_notification_realtime_power_info"; // 获取令牌 @@ -526,10 +524,8 @@ public class QingHaiPlatformServiceImpl implements ThirdPartyPlatformService { public Map queryEquipBusinessPolicy(QueryStartChargeDTO dto) { List policyInfoList = new ArrayList<>(); String pileConnectorCode = dto.getConnectorID(); - ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorId()); - if (configInfo == null) { - return null; - } + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getQingHaiPlatformSecretInfo(); + // 截取桩号 // String pileSn = StringUtils.substring(pileConnectorCode, 0, 14); String pileSn = YKCUtils.getPileSn(pileConnectorCode); @@ -574,7 +570,8 @@ public class QingHaiPlatformServiceImpl implements ThirdPartyPlatformService { jsonObject.put("PolicyInfos", policyInfoList); // 加密 - Map resultMap = getResultMap(jsonObject); + Map resultMap = ThirdPartyPlatformUtils.generateResultMapV2(jsonObject, thirdPartySecretInfoVO.getOurDataSecret(), + thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret()); return resultMap; } @@ -633,16 +630,14 @@ public class QingHaiPlatformServiceImpl implements ThirdPartyPlatformService { } // 获取推送配置密钥信息 - ThirdPartyStationRelationVO settingInfo = getQingHaiSettingInfo(); - if (settingInfo == null) { - return null; - } - String operatorId = settingInfo.getOperatorId(); - String operatorSecret = settingInfo.getOperatorSecret(); - String signSecret = settingInfo.getSignSecret(); - String dataSecret = settingInfo.getDataSecret(); - String dataSecretIv = settingInfo.getDataSecretIv(); - String urlAddress = settingInfo.getUrlAddress(); + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getQingHaiPlatformSecretInfo(); + + String operatorId = thirdPartySecretInfoVO.getTheirOperatorId(); + String operatorSecret = thirdPartySecretInfoVO.getTheirOperatorSecret(); + String signSecret = thirdPartySecretInfoVO.getTheirSigSecret(); + String dataSecret = thirdPartySecretInfoVO.getTheirDataSecret(); + String dataSecretIv = thirdPartySecretInfoVO.getTheirDataSecretIv(); + String urlAddress = thirdPartySecretInfoVO.getTheirUrlPrefix(); String url = urlAddress + "notification_charge_order_info"; // 获取令牌 @@ -657,42 +652,19 @@ public class QingHaiPlatformServiceImpl implements ThirdPartyPlatformService { return result; } - - // 获取青海平台配置密钥信息 - private ThirdPartyStationRelationVO getQingHaiSettingInfo() { - // 通过第三方平台类型查询相关配置信息 - ThirdPartyStationRelation relation = new ThirdPartyStationRelation(); - relation.setThirdPartyType(ThirdPlatformTypeEnum.QING_HAI_PLATFORM.getTypeCode()); - ThirdPartyStationRelationVO relationInfo = thirdPartyStationRelationService.selectRelationInfo(relation); - return relationInfo; - } - - /** - * 将需要发送至对接平台的的返回参数加密返回 + * 获取青海省平台配置密钥信息 * - * @param jsonObject * @return */ - private Map getResultMap(JSONObject jsonObject) { - String operatorId = ThirdPlatformTypeEnum.QING_HAI_PLATFORM.getOperatorId(); - ThirdPartyPlatformConfig platformConfig = thirdPartyPlatformConfigService.getInfoByOperatorId(operatorId); - if (platformConfig == null) { - return null; + private ThirdPartySecretInfoVO getQingHaiPlatformSecretInfo() { + // 通过第三方平台类型查询相关配置信息 + ThirdPartySecretInfoVO thirdPartySecretInfoVO = thirdpartySecretInfoService.queryByThirdPlatformType(ThirdPlatformTypeEnum.QING_HAI_PLATFORM.getTypeCode()); + if (thirdPartySecretInfoVO == null) { + throw new BusinessException(ReturnCodeEnum.CODE_SELECT_INFO_IS_NULL); } - Map resultMap = Maps.newLinkedHashMap(); - // 加密数据 - byte[] encryptText = Cryptos.aesEncrypt(jsonObject.toJSONString().getBytes(), - platformConfig.getDataSecret().getBytes(), platformConfig.getDataSecretIv().getBytes()); - String encryptData = Encodes.encodeBase64(encryptText); - resultMap.put("Ret", "0"); - resultMap.put("Msg", "请求令牌成功!"); - resultMap.put("Data", encryptData); - // 生成sig - String resultSign = GBSignUtils.sign(resultMap, platformConfig.getSignSecret()); - resultMap.put("Sig", resultSign); - - return resultMap; + thirdPartySecretInfoVO.setOurOperatorId(Constants.OPERATORID_JIANG_SU); + return thirdPartySecretInfoVO; } } diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/XinDiantuPlatfromServiceImpl.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/XinDiantuPlatfromServiceImpl.java index 661a9531c..de0bfba7b 100644 --- a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/XinDiantuPlatfromServiceImpl.java +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/XinDiantuPlatfromServiceImpl.java @@ -313,16 +313,13 @@ public class XinDiantuPlatfromServiceImpl implements ThirdPartyPlatformService { */ @Override public Map queryEquipAuth(QueryEquipmentDTO dto) { - Map resultMap = Maps.newLinkedHashMap(); EquipmentAuthVO vo = new EquipmentAuthVO(); String equipAuthSeq = dto.getEquipAuthSeq(); // MA1X78KH5202311071202015732 String pileConnectorCode = ThirdPartyPlatformUtils.extractConnectorID(dto.getConnectorID()); // 先查询配置密钥相关信息 - ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorID()); - if (configInfo == null) { - return null; - } + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getXinDiantuPlatformSecretInfo(); + // 根据桩编号查询数据 // String merchantId = StringUtils.substring(equipAuthSeq, 0, 9); // String pileSn = StringUtils.substring(pileConnectorCode, 0, 14); @@ -356,16 +353,9 @@ public class XinDiantuPlatfromServiceImpl implements ThirdPartyPlatformService { vo.setSuccStat(succStat); vo.setFailReason(failReason); // 设备检测失败 vo.setFailReasonMsg(failReasonMsg); - // 加密数据 - 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); + Map resultMap = ThirdPartyPlatformUtils.generateResultMapV2(vo, thirdPartySecretInfoVO.getOurDataSecret(), + thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret()); return resultMap; } diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/YongChengbochePlatfromServiceImpl.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/YongChengbochePlatfromServiceImpl.java index 7dcd8cbf1..1a84b03f9 100644 --- a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/YongChengbochePlatfromServiceImpl.java +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/YongChengbochePlatfromServiceImpl.java @@ -73,9 +73,6 @@ public class YongChengbochePlatfromServiceImpl implements ThirdPartyPlatformServ @Autowired private PileMerchantInfoService pileMerchantInfoService; - @Autowired - private ThirdPartyPlatformConfigService thirdPartyPlatformConfigService; - @Autowired private PileConnectorInfoService pileConnectorInfoService; @@ -88,9 +85,6 @@ public class YongChengbochePlatfromServiceImpl implements ThirdPartyPlatformServ @Autowired private PileRemoteService pileRemoteService; - @Autowired - private ThirdPartyStationRelationService thirdPartyStationRelationService; - @Override public void afterPropertiesSet() throws Exception { ThirdPartyPlatformFactory.register(thirdPlatformType, this); @@ -142,7 +136,8 @@ public class YongChengbochePlatfromServiceImpl implements ThirdPartyPlatformServ vo.setFailReason(failReason); vo.setSuccStat(succStat); - Map resultMap = ThirdPartyPlatformUtils.generateResultMap(vo, thirdPartySecretInfoVO); + Map resultMap = ThirdPartyPlatformUtils.generateResultMapV2(vo, thirdPartySecretInfoVO.getOurDataSecret(), + thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret()); return resultMap; } @@ -215,7 +210,8 @@ public class YongChengbochePlatfromServiceImpl implements ThirdPartyPlatformServ map.put("PageCount", pageInfo.getPages()); map.put("ItemSize", pageInfo.getTotal()); map.put("StationInfos", resultList); - Map resultMap = ThirdPartyPlatformUtils.generateResultMap(map, thirdPartySecretInfoVO); + Map resultMap = ThirdPartyPlatformUtils.generateResultMapV2(map, thirdPartySecretInfoVO.getOurDataSecret(), + thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret()); return resultMap; } @@ -230,10 +226,8 @@ public class YongChengbochePlatfromServiceImpl implements ThirdPartyPlatformServ List stationIds = dto.getStationIds(); List StationStatusInfos = new ArrayList<>(); List ConnectorStatusInfos = new ArrayList<>(); - ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorId()); - if (configInfo == null) { - return null; - } + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getYongChengbochePlatformSecretInfo(); + ConnectorStatusInfo connectorStatusInfo; for (String stationId : stationIds) { StationStatusInfo stationStatusInfo = new StationStatusInfo(); @@ -296,13 +290,8 @@ public class YongChengbochePlatfromServiceImpl implements ThirdPartyPlatformServ map.put("Total", total); map.put("StationStatusInfos", collect); - Map resultMap = Maps.newLinkedHashMap(); - // 加密数据 - String encryptData = Cryptos.aesEncrypt(JSON.toJSONString(map), configInfo.getDataSecret(), configInfo.getDataSecretIv()); - resultMap.put("Data", encryptData); - // 生成sig - String resultSign = GBSignUtils.sign(resultMap, configInfo.getSignSecret()); - resultMap.put("Sig", resultSign); + Map resultMap = ThirdPartyPlatformUtils.generateResultMapV2(map, thirdPartySecretInfoVO.getOurDataSecret(), + thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret()); return resultMap; } @@ -357,7 +346,7 @@ public class YongChengbochePlatfromServiceImpl implements ThirdPartyPlatformServ public Map queryEquipBusinessPolicy(QueryStartChargeDTO dto) { List policyInfoList = new ArrayList<>(); String pileConnectorCode = dto.getConnectorID(); - ThirdPartySecretInfoVO yongChengbochePlatformSecretInfo = getYongChengbochePlatformSecretInfo(); + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getYongChengbochePlatformSecretInfo(); // 截取桩号 // String pileSn = StringUtils.substring(pileConnectorCode, 0, 14); @@ -394,7 +383,9 @@ public class YongChengbochePlatfromServiceImpl implements ThirdPartyPlatformServ .policyInfos(policyInfoList) .build(); - return ThirdPartyPlatformUtils.generateResultMap(vo, yongChengbochePlatformSecretInfo); + Map resultMap = ThirdPartyPlatformUtils.generateResultMapV2(vo, thirdPartySecretInfoVO.getOurDataSecret(), + thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret()); + return resultMap; } /** @@ -405,16 +396,12 @@ public class YongChengbochePlatfromServiceImpl implements ThirdPartyPlatformServ */ @Override public Map queryEquipAuth(QueryEquipmentDTO dto) { - Map resultMap = Maps.newLinkedHashMap(); EquipmentAuthVO vo = new EquipmentAuthVO(); String equipAuthSeq = dto.getEquipAuthSeq(); // MA1X78KH5202311071202015732 String pileConnectorCode = ThirdPartyPlatformUtils.extractConnectorID(dto.getConnectorID()); // 先查询配置密钥相关信息 - ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorID()); - if (configInfo == null) { - return null; - } + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getYongChengbochePlatformSecretInfo(); // 根据桩编号查询数据 // String merchantId = StringUtils.substring(equipAuthSeq, 0, 9); // String pileSn = StringUtils.substring(pileConnectorCode, 0, 14); @@ -449,15 +436,8 @@ public class YongChengbochePlatfromServiceImpl implements ThirdPartyPlatformServ vo.setFailReason(failReason); // 设备检测失败 vo.setFailReasonMsg(failReasonMsg); // 加密数据 - 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); - + Map resultMap = ThirdPartyPlatformUtils.generateResultMapV2(vo, thirdPartySecretInfoVO.getOurDataSecret(), + thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret()); return resultMap; } @@ -476,7 +456,7 @@ public class YongChengbochePlatfromServiceImpl implements ThirdPartyPlatformServ // 平台已存在订单 return null; } - ThirdPartySecretInfoVO yongChengbochePlatformSecretInfoVO = getYongChengbochePlatformSecretInfo(); + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getYongChengbochePlatformSecretInfo(); // 生成订单 Map map = orderBasicInfoService.generateOrderForThirdParty(dto); String orderCode = (String) map.get("orderCode"); @@ -503,7 +483,9 @@ public class YongChengbochePlatfromServiceImpl implements ThirdPartyPlatformServ .failReason(0) .build(); - return ThirdPartyPlatformUtils.generateResultMap(vo, yongChengbochePlatformSecretInfoVO); + Map resultMap = ThirdPartyPlatformUtils.generateResultMapV2(vo, thirdPartySecretInfoVO.getOurDataSecret(), + thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret()); + return resultMap; } /** @@ -560,7 +542,7 @@ public class YongChengbochePlatfromServiceImpl implements ThirdPartyPlatformServ if (orderInfo == null) { return null; } - ThirdPartySecretInfoVO yongChengbochePlatformSecretInfoVO = getYongChengbochePlatformSecretInfo(); + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getYongChengbochePlatformSecretInfo(); OrderDetail orderDetail = orderBasicInfoService.getOrderDetailByOrderCode(orderInfo.getOrderCode()); // 通过订单号查询实时数据 List realTimeData = orderBasicInfoService.getChargingRealTimeData(orderInfo.getTransactionCode()); @@ -609,7 +591,9 @@ public class YongChengbochePlatfromServiceImpl implements ThirdPartyPlatformServ .build(); } - return ThirdPartyPlatformUtils.generateResultMap(vo, yongChengbochePlatformSecretInfoVO); + Map resultMap = ThirdPartyPlatformUtils.generateResultMapV2(vo, thirdPartySecretInfoVO.getOurDataSecret(), + thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret()); + return resultMap; } /** @@ -687,7 +671,7 @@ public class YongChengbochePlatfromServiceImpl implements ThirdPartyPlatformServ QueryStopChargeVO vo = new QueryStopChargeVO(); String orderCode = dto.getStartChargeSeq(); - ThirdPartySecretInfoVO yongChengbochePlatformSecretInfo = getYongChengbochePlatformSecretInfo(); + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getYongChengbochePlatformSecretInfo(); // 根据订单号查询订单信息 OrderBasicInfo orderInfo = orderBasicInfoService.getOrderInfoByOrderCode(orderCode); if (orderInfo == null) { @@ -703,7 +687,9 @@ public class YongChengbochePlatfromServiceImpl implements ThirdPartyPlatformServ vo.setSuccStat(0); vo.setFailReason(0); - return ThirdPartyPlatformUtils.generateResultMap(vo, yongChengbochePlatformSecretInfo); + Map resultMap = ThirdPartyPlatformUtils.generateResultMapV2(vo, thirdPartySecretInfoVO.getOurDataSecret(), + thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret()); + return resultMap; } /** diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/xindiantu/service/XDTService.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/xindiantu/service/XDTService.java index 5f17b4b37..4ec039657 100644 --- a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/xindiantu/service/XDTService.java +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/xindiantu/service/XDTService.java @@ -26,13 +26,13 @@ public interface XDTService { * @param dto * @return */ - Map generateToken(CommonParamsDTO dto) throws UnsupportedEncodingException; + // Map generateToken(CommonParamsDTO dto) throws UnsupportedEncodingException; /** * 校验签名 * @param dto */ - Map checkoutSign(CommonParamsDTO dto); + // Map checkoutSign(CommonParamsDTO dto); /** * 查询站点信息 diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/xindiantu/service/impl/XDTServiceImpl.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/xindiantu/service/impl/XDTServiceImpl.java index 29837bc17..ca09b5971 100644 --- a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/xindiantu/service/impl/XDTServiceImpl.java +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/xindiantu/service/impl/XDTServiceImpl.java @@ -55,15 +55,15 @@ public class XDTServiceImpl implements XDTService { * @param dto * @return */ - @Override - public Map generateToken(CommonParamsDTO dto) throws UnsupportedEncodingException { - return zdlService.generateToken(dto); - } + // @Override + // public Map generateToken(CommonParamsDTO dto) throws UnsupportedEncodingException { + // return zdlService.generateToken(dto); + // } - @Override - public Map checkoutSign(CommonParamsDTO dto) { - return zdlService.checkoutSign(dto); - } + // @Override + // public Map checkoutSign(CommonParamsDTO dto) { + // return zdlService.checkoutSign(dto); + // } /** * 查询站点信息 diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/yongchengboche/service/YCBCService.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/yongchengboche/service/YCBCService.java index 09811ae7c..d5f280030 100644 --- a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/yongchengboche/service/YCBCService.java +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/yongchengboche/service/YCBCService.java @@ -26,7 +26,7 @@ public interface YCBCService { * @param dto * @return */ - Map generateToken(CommonParamsDTO dto) throws UnsupportedEncodingException; + // Map generateToken(CommonParamsDTO dto) throws UnsupportedEncodingException; /** * 查询站点信息 diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/yongchengboche/service/impl/YCBCServiceImpl.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/yongchengboche/service/impl/YCBCServiceImpl.java index a5d9a1315..ce3bba6bc 100644 --- a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/yongchengboche/service/impl/YCBCServiceImpl.java +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/yongchengboche/service/impl/YCBCServiceImpl.java @@ -143,10 +143,10 @@ public class YCBCServiceImpl implements YCBCService { * @return * @throws UnsupportedEncodingException */ - @Override - public Map generateToken(CommonParamsDTO dto) throws UnsupportedEncodingException { - return zdlService.generateToken(dto); - } + // @Override + // public Map generateToken(CommonParamsDTO dto) throws UnsupportedEncodingException { + // return zdlService.generateToken(dto); + // } /** * 获取充电站信息 diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/zhongdianlian/service/ZDLService.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/zhongdianlian/service/ZDLService.java index dbace3541..759f2f27a 100644 --- a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/zhongdianlian/service/ZDLService.java +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/zhongdianlian/service/ZDLService.java @@ -74,7 +74,7 @@ public interface ZDLService { * @param dto * @return */ - Map generateToken(CommonParamsDTO dto) throws UnsupportedEncodingException; + // Map generateToken(CommonParamsDTO dto) throws UnsupportedEncodingException; /** * 请求设备认证 @@ -134,5 +134,5 @@ public interface ZDLService { * 校验签名 * @param dto */ - Map checkoutSign(CommonParamsDTO dto); + // Map checkoutSign(CommonParamsDTO dto); } diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/zhongdianlian/service/impl/ZDLServiceImpl.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/zhongdianlian/service/impl/ZDLServiceImpl.java index 7177528d5..51ef89753 100644 --- a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/zhongdianlian/service/impl/ZDLServiceImpl.java +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/zhongdianlian/service/impl/ZDLServiceImpl.java @@ -7,12 +7,15 @@ import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.jsowell.common.constant.Constants; import com.jsowell.common.enums.thirdparty.ThirdPlatformTypeEnum; +import com.jsowell.common.enums.ykc.ReturnCodeEnum; +import com.jsowell.common.exception.BusinessException; import com.jsowell.common.util.PageUtils; import com.jsowell.common.util.StringUtils; import com.jsowell.common.util.YKCUtils; import com.jsowell.pile.domain.*; import com.jsowell.pile.dto.*; import com.jsowell.pile.service.*; +import com.jsowell.pile.vo.ThirdPartySecretInfoVO; import com.jsowell.pile.vo.base.MerchantInfoVO; import com.jsowell.pile.vo.base.ThirdPartyStationInfoVO; import com.jsowell.pile.vo.base.ThirdPartyStationRelationVO; @@ -22,10 +25,8 @@ import com.jsowell.pile.vo.zdl.EquipBusinessPolicyVO; import com.jsowell.thirdparty.common.CommonService; import com.jsowell.pile.thirdparty.CommonParamsDTO; import com.jsowell.thirdparty.lianlian.service.LianLianService; -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 com.jsowell.thirdparty.platform.util.*; +import com.jsowell.thirdparty.service.ThirdpartySecretInfoService; import com.jsowell.thirdparty.yongchengboche.dto.YCBCGetTokenDTO; import com.jsowell.thirdparty.yongchengboche.service.YCBCService; import com.jsowell.pile.thirdparty.ZDLConnectorInfo; @@ -63,9 +64,6 @@ public class ZDLServiceImpl implements ZDLService { @Autowired private PileStationInfoService pileStationInfoService; - @Autowired - private ThirdPartyPlatformConfigService thirdPartyPlatformConfigService; - @Autowired private PileBasicInfoService pileBasicInfoService; @@ -85,7 +83,7 @@ public class ZDLServiceImpl implements ZDLService { private PileBillingTemplateService pileBillingTemplateService; @Autowired - private ThirdPartySettingInfoService thirdPartySettingInfoService; + private ThirdpartySecretInfoService thirdpartySecretInfoService; @Autowired private CommonService commonService; @@ -208,14 +206,14 @@ public class ZDLServiceImpl implements ZDLService { // 通过第三方配置类型查询相关配置信息 ThirdPartySettingInfo settingInfo = new ThirdPartySettingInfo(); settingInfo.setType(dto.getThirdPartyType()); - ThirdPartySettingInfo thirdPartySettingInfo = thirdPartySettingInfoService.selectSettingInfo(settingInfo); + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getNingBoPlatformSecretInfo(); - String operatorId = thirdPartySettingInfo.getOperatorId(); - String operatorSecret = thirdPartySettingInfo.getOperatorSecret(); - String signSecret = thirdPartySettingInfo.getSignSecret(); - String dataSecret = thirdPartySettingInfo.getDataSecret(); - String dataSecretIv = thirdPartySettingInfo.getDataSecretIv(); - String urlAddress = thirdPartySettingInfo.getUrlAddress(); + String operatorId = thirdPartySecretInfoVO.getTheirOperatorId(); + String operatorSecret = thirdPartySecretInfoVO.getTheirOperatorSecret(); + String signSecret = thirdPartySecretInfoVO.getTheirSigSecret(); + String dataSecret = thirdPartySecretInfoVO.getTheirDataSecret(); + String dataSecretIv = thirdPartySecretInfoVO.getTheirDataSecretIv(); + String urlAddress = thirdPartySecretInfoVO.getTheirUrlPrefix(); // 组装中电联平台所需要的数据格式 ZDLStationInfo info = ZDLStationInfo.builder() @@ -348,10 +346,8 @@ public class ZDLServiceImpl implements ZDLService { // 未查到数据 return null; } - ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorId()); - if (configInfo == null) { - return null; - } + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getNingBoPlatformSecretInfo(); + PageInfo pageInfo = new PageInfo<>(stationInfos); for (ThirdPartyStationInfoVO pileStationInfo : pageInfo.getList()) { ZDLStationInfo stationInfo = new ZDLStationInfo(); @@ -402,18 +398,8 @@ public class ZDLServiceImpl implements ZDLService { map.put("ItemSize", resultList.size()); map.put("StationInfos", resultList); - // 加密 - Map resultMap = Maps.newLinkedHashMap(); - // 加密数据 - byte[] encryptText = Cryptos.aesEncrypt(JSON.toJSONString(map).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 resultMap = ThirdPartyPlatformUtils.generateResultMapV2(map, thirdPartySecretInfoVO.getOurDataSecret(), + thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret()); return resultMap; } @@ -465,10 +451,10 @@ public class ZDLServiceImpl implements ZDLService { * @param dto * @return */ - @Override - public Map generateToken(CommonParamsDTO dto) throws UnsupportedEncodingException { - return lianLianService.generateToken(dto); - } + // @Override + // public Map generateToken(CommonParamsDTO dto) throws UnsupportedEncodingException { + // return lianLianService.generateToken(dto); + // } /** * 请求设备认证 @@ -499,10 +485,8 @@ public class ZDLServiceImpl implements ZDLService { public Map queryEquipBusinessPolicy(QueryStartChargeDTO dto) { List policyInfoList = new ArrayList<>(); String pileConnectorCode = dto.getConnectorID(); - ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorId()); - if (configInfo == null) { - return null; - } + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getNingBoPlatformSecretInfo(); + // 截取桩号 // String pileSn = StringUtils.substring(pileConnectorCode, 0, 14); String pileSn = YKCUtils.getPileSn(pileConnectorCode); @@ -539,18 +523,8 @@ public class ZDLServiceImpl implements ZDLService { .build(); - // 加密 - Map resultMap = Maps.newLinkedHashMap(); - // 加密数据 - 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); - + Map resultMap = ThirdPartyPlatformUtils.generateResultMapV2(vo, thirdPartySecretInfoVO.getOurDataSecret(), + thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret()); return resultMap; } @@ -596,10 +570,10 @@ public class ZDLServiceImpl implements ZDLService { * 校验签名 * @param dto */ - @Override - public Map checkoutSign(CommonParamsDTO dto) { - return lianLianService.checkoutSign(dto); - } + // @Override + // public Map checkoutSign(CommonParamsDTO dto) { + // return lianLianService.checkoutSign(dto); + // } /** * 推送充电状态 @@ -681,4 +655,19 @@ public class ZDLServiceImpl implements ZDLService { return resultList; } + + /** + * 获取宁波平台配置密钥信息 + * + * @return + */ + private ThirdPartySecretInfoVO getNingBoPlatformSecretInfo() { + // 通过第三方平台类型查询相关配置信息 + ThirdPartySecretInfoVO thirdPartySecretInfoVO = thirdpartySecretInfoService.queryByThirdPlatformType(ThirdPlatformTypeEnum.NING_BO_PLATFORM.getTypeCode()); + if (thirdPartySecretInfoVO == null) { + throw new BusinessException(ReturnCodeEnum.CODE_SELECT_INFO_IS_NULL); + } + thirdPartySecretInfoVO.setOurOperatorId(Constants.OPERATORID_JIANG_SU); + return thirdPartySecretInfoVO; + } }