|
|
@@ -0,0 +1,173 @@
|
|
|
+package com.zsElectric.boot.charging.service.impl;
|
|
|
+
|
|
|
+import com.google.gson.Gson;
|
|
|
+import com.zsElectric.boot.charging.service.ChargingReceptionService;
|
|
|
+import com.zsElectric.boot.charging.vo.*;
|
|
|
+import com.zsElectric.boot.common.constant.ConnectivityConstants;
|
|
|
+import com.zsElectric.boot.common.util.electric.ChargingUtil;
|
|
|
+import com.zsElectric.boot.common.util.electric.RequestParmsEntity;
|
|
|
+import com.zsElectric.boot.common.util.electric.ResponseParmsEntity;
|
|
|
+import com.zsElectric.boot.core.exception.BusinessException;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import static com.zsElectric.boot.common.constant.ConnectivityConstants.FAIL_REASON_NONE;
|
|
|
+import static com.zsElectric.boot.common.constant.ConnectivityConstants.STATUS_OK;
|
|
|
+import static com.zsElectric.boot.common.util.HmacMD5Util.genSign;
|
|
|
+import static com.zsElectric.boot.common.util.HmacMD5Util.verify;
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+@RequiredArgsConstructor
|
|
|
+public class ChargingReceptionServiceImpl implements ChargingReceptionService {
|
|
|
+
|
|
|
+ private final ChargingUtil chargingUtil;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ResponseParmsEntity chargeResponse(RequestParmsEntity requestDTO) {
|
|
|
+ log.info("接收推送启动充电结果请求参数:{}", requestDTO);
|
|
|
+ ChargingStatusResponseVO chargingStatusResponseVO;
|
|
|
+ // 响应参数 答复处理
|
|
|
+ ChargeResponseVO chargeResponseVO = new ChargeResponseVO();
|
|
|
+ String encryptData;
|
|
|
+ String genSign;
|
|
|
+ try {
|
|
|
+ String data = requestDTO.getOperatorID() + requestDTO.getData() + requestDTO.getTimeStamp() + requestDTO.getSeq();
|
|
|
+ if(verify(data, ConnectivityConstants.SIG_SECRET, requestDTO.getSig())){
|
|
|
+ String decryptData = chargingUtil.decryptData(requestDTO.getData());
|
|
|
+ log.info("解密后的数据:{}", decryptData);
|
|
|
+ chargingStatusResponseVO = new Gson().fromJson(decryptData, ChargingStatusResponseVO.class);
|
|
|
+ //todo 业务代码待处理
|
|
|
+
|
|
|
+
|
|
|
+ chargeResponseVO.setStartChargeSeq(chargingStatusResponseVO.getStartChargeSeq());
|
|
|
+ chargeResponseVO.setSuccStat(STATUS_OK);
|
|
|
+ chargeResponseVO.setFailReason(FAIL_REASON_NONE);
|
|
|
+ encryptData = chargingUtil.encryptData(new Gson().toJson(chargeResponseVO));
|
|
|
+ genSign = genSign(STATUS_OK, "请求成功", encryptData, ConnectivityConstants.SIG_SECRET);
|
|
|
+ }else {
|
|
|
+ log.error("数据验签失败");
|
|
|
+ throw new BusinessException("数据验签失败");
|
|
|
+ }
|
|
|
+ }catch (Exception e){
|
|
|
+ log.error("数据解密失败:{}", e.getMessage());
|
|
|
+ throw new BusinessException("数据解密失败:" + e.getMessage(), e);
|
|
|
+ }
|
|
|
+ return new ResponseParmsEntity()
|
|
|
+ .setRet(STATUS_OK)
|
|
|
+ .setMsg("请求成功")
|
|
|
+ .setData(encryptData)
|
|
|
+ .setSig(genSign);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ResponseParmsEntity chargeStatusResponse(RequestParmsEntity requestDTO) {
|
|
|
+ log.info("接收推送充电状态请求参数:{}", requestDTO);
|
|
|
+ EquipChargeStatusResponseVO equipChargeStatusResponseVO;
|
|
|
+ ChargeResponseVO chargeResponseVO = new ChargeResponseVO();
|
|
|
+ String encryptData;
|
|
|
+ String genSign;
|
|
|
+ try {
|
|
|
+ String data = requestDTO.getOperatorID() + requestDTO.getData() + requestDTO.getTimeStamp() + requestDTO.getSeq();
|
|
|
+ if(verify(data, ConnectivityConstants.SIG_SECRET, requestDTO.getSig())){
|
|
|
+ String decryptData = chargingUtil.decryptData(requestDTO.getData());
|
|
|
+ log.info("解密后的数据:{}", decryptData);
|
|
|
+ equipChargeStatusResponseVO = new Gson().fromJson(decryptData, EquipChargeStatusResponseVO.class);
|
|
|
+ //todo 业务代码待处理
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ chargeResponseVO.setStartChargeSeq(equipChargeStatusResponseVO.getStartChargeSeq());
|
|
|
+ chargeResponseVO.setSuccStat(STATUS_OK);
|
|
|
+ chargeResponseVO.setFailReason(FAIL_REASON_NONE);
|
|
|
+ encryptData = chargingUtil.encryptData(new Gson().toJson(chargeResponseVO));
|
|
|
+ genSign = genSign(STATUS_OK, "请求成功", encryptData, ConnectivityConstants.SIG_SECRET);
|
|
|
+ }else {
|
|
|
+ log.error("数据验签失败");
|
|
|
+ throw new BusinessException("数据验签失败");
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("数据解密失败:{}", e.getMessage());
|
|
|
+ throw new BusinessException("数据解密失败:" + e.getMessage(), e);
|
|
|
+ }
|
|
|
+ return new ResponseParmsEntity()
|
|
|
+ .setRet(STATUS_OK)
|
|
|
+ .setMsg("请求成功")
|
|
|
+ .setData(encryptData)
|
|
|
+ .setSig(genSign);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ResponseParmsEntity stopChargeResponse(RequestParmsEntity requestDTO) {
|
|
|
+ log.info("接收推送停止充电结果请求参数:{}", requestDTO);
|
|
|
+ StopChargingResponseVO stopChargingResponseVO;
|
|
|
+ ChargeResponseVO chargeResponseVO = new ChargeResponseVO();
|
|
|
+ String encryptData;
|
|
|
+ String genSign;
|
|
|
+ try {
|
|
|
+ String data = requestDTO.getOperatorID() + requestDTO.getData() + requestDTO.getTimeStamp() + requestDTO.getSeq();
|
|
|
+ if(verify(data, ConnectivityConstants.SIG_SECRET, requestDTO.getSig())){
|
|
|
+ String decryptData = chargingUtil.decryptData(requestDTO.getData());
|
|
|
+ log.info("解密后的数据:{}", decryptData);
|
|
|
+ stopChargingResponseVO = new Gson().fromJson(decryptData, StopChargingResponseVO.class);
|
|
|
+ //todo 业务代码待处理
|
|
|
+
|
|
|
+
|
|
|
+ chargeResponseVO.setStartChargeSeq(stopChargingResponseVO.getStartChargeSeq());
|
|
|
+ chargeResponseVO.setSuccStat(STATUS_OK);
|
|
|
+ chargeResponseVO.setFailReason(FAIL_REASON_NONE);
|
|
|
+ encryptData = chargingUtil.encryptData(new Gson().toJson(chargeResponseVO));
|
|
|
+ genSign = genSign(STATUS_OK, "请求成功", encryptData, ConnectivityConstants.SIG_SECRET);
|
|
|
+ }else {
|
|
|
+ log.error("数据验签失败");
|
|
|
+ throw new BusinessException("数据验签失败");
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("数据解密失败:{}", e.getMessage());
|
|
|
+ throw new BusinessException("数据解密失败:" + e.getMessage(), e);
|
|
|
+ }
|
|
|
+ return new ResponseParmsEntity()
|
|
|
+ .setRet(STATUS_OK)
|
|
|
+ .setMsg("请求成功")
|
|
|
+ .setData(encryptData)
|
|
|
+ .setSig(genSign);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ResponseParmsEntity chargeOrderResponse(RequestParmsEntity requestDTO) {
|
|
|
+ log.info("接收推送充电订单信息请求参数:{}", requestDTO);
|
|
|
+ ChargingOrderVO chargingOrderVO;
|
|
|
+ ChargeResponseVO chargeResponseVO = new ChargeResponseVO();
|
|
|
+ String encryptData;
|
|
|
+ String genSign;
|
|
|
+ try {
|
|
|
+ String data = requestDTO.getOperatorID() + requestDTO.getData() + requestDTO.getTimeStamp() + requestDTO.getSeq();
|
|
|
+ if(verify(data, ConnectivityConstants.SIG_SECRET, requestDTO.getSig())){
|
|
|
+ String decryptData = chargingUtil.decryptData(requestDTO.getData());
|
|
|
+ log.info("解密后的数据:{}", decryptData);
|
|
|
+ chargingOrderVO = new Gson().fromJson(decryptData, ChargingOrderVO.class);
|
|
|
+ //todo 业务代码待处理
|
|
|
+
|
|
|
+
|
|
|
+ chargeResponseVO.setStartChargeSeq(chargingOrderVO.getStartChargeSeq());
|
|
|
+ chargeResponseVO.setSuccStat(STATUS_OK);
|
|
|
+ chargeResponseVO.setFailReason(FAIL_REASON_NONE);
|
|
|
+ encryptData = chargingUtil.encryptData(new Gson().toJson(chargeResponseVO));
|
|
|
+ genSign = genSign(STATUS_OK, "请求成功", encryptData, ConnectivityConstants.SIG_SECRET);
|
|
|
+ }else {
|
|
|
+ log.error("数据验签失败");
|
|
|
+ throw new BusinessException("数据验签失败");
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("数据解密失败:{}", e.getMessage());
|
|
|
+ throw new BusinessException("数据解密失败:" + e.getMessage(), e);
|
|
|
+ }
|
|
|
+ return new ResponseParmsEntity()
|
|
|
+ .setRet(STATUS_OK)
|
|
|
+ .setMsg("请求成功")
|
|
|
+ .setData(encryptData)
|
|
|
+ .setSig(genSign);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|