新增 宁波点行平台Controller

This commit is contained in:
Lemon
2024-05-10 15:27:59 +08:00
parent 2f5cb3bd74
commit 68f4b8c651
7 changed files with 221 additions and 25 deletions

File diff suppressed because one or more lines are too long

View File

@@ -16,9 +16,13 @@ import com.jsowell.thirdparty.lianlian.vo.LianLianResultVO;
import com.jsowell.thirdparty.platform.util.Cryptos;
import com.jsowell.thirdparty.platform.util.Encodes;
import com.jsowell.thirdparty.platform.util.GBSignUtils;
import org.bouncycastle.crypto.CryptoException;
import org.springframework.beans.factory.InitializingBean;
import java.nio.charset.StandardCharsets;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.spec.InvalidKeySpecException;
import java.util.*;
/**
@@ -275,7 +279,7 @@ public interface ThirdPartyPlatformService extends InitializingBean {
* @param orderCode 订单编号
* @throws UnsupportedOperationException 未实现异常
*/
default String notificationChargeOrderInfo(String orderCode) {
default String notificationChargeOrderInfo(String orderCode) throws NoSuchAlgorithmException, InvalidKeySpecException, NoSuchProviderException, CryptoException {
throw new UnsupportedOperationException("This method is not yet implemented");
}

View File

@@ -0,0 +1,92 @@
package com.jsowell.thirdparty.platform.ningbodianxing.service;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson2.JSONObject;
import com.jsowell.common.enums.thirdparty.BusinessInformationExchangeEnum;
import com.jsowell.common.enums.thirdparty.ThirdPlatformTypeEnum;
import com.jsowell.common.exception.BusinessException;
import com.jsowell.common.util.DateUtils;
import com.jsowell.common.util.Sm2Util;
import com.jsowell.common.util.http.HttpUtils;
import com.jsowell.pile.domain.OrderBasicInfo;
import com.jsowell.pile.service.OrderBasicInfoService;
import com.jsowell.pile.vo.ThirdPartySecretInfoVO;
import com.jsowell.thirdparty.platform.ThirdPartyPlatformService;
import com.jsowell.thirdparty.platform.factory.ThirdPartyPlatformFactory;
import com.jsowell.thirdparty.service.ThirdpartySecretInfoService;
import org.bouncycastle.crypto.CryptoException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.spec.InvalidKeySpecException;
/**
* 宁波点行平台
*
* @author Lemon
* @Date 2024/5/9 10:18:12
*/
@Service
public class DianXingPlatformServiceImpl implements ThirdPartyPlatformService {
@Autowired
private OrderBasicInfoService orderBasicInfoService;
@Autowired
private ThirdpartySecretInfoService thirdpartySecretInfoService;
Logger logger = LoggerFactory.getLogger(this.getClass());
// 平台类型
private final String thirdPlatformType = ThirdPlatformTypeEnum.DIAN_XING_PLATFORM.getTypeCode();
@Override
public void afterPropertiesSet() throws Exception {
ThirdPartyPlatformFactory.register(thirdPlatformType, this);
}
/**
* 推送订单接口
* @param orderCode 订单编号
* @return
*/
@Override
public String notificationChargeOrderInfo(String orderCode) throws NoSuchAlgorithmException, InvalidKeySpecException, NoSuchProviderException, CryptoException {
// 通过订单编号查询订单信息
OrderBasicInfo orderBasicInfo = orderBasicInfoService.getOrderInfoByOrderCode(orderCode);
if (orderBasicInfo == null) {
throw new BusinessException("", "未查询到该订单信息");
}
String plateNum = orderBasicInfo.getPlateNumber() == null ? "" : orderBasicInfo.getPlateNumber();
// 拼装订单信息 JSON 参数
JSONObject jsonObject = new JSONObject();
jsonObject.put("outTradeId", orderBasicInfo.getOrderCode()); // 充电桩平台订单号
jsonObject.put("plateNum", plateNum); // 车牌号
jsonObject.put("startTime", orderBasicInfo.getChargeStartTime()); // 充电开始时间,格式 yyyy-MM-dd HH:mm:ss
jsonObject.put("endTime", orderBasicInfo.getChargeEndTime()); // 充电结束时间,
jsonObject.put("payAmount", orderBasicInfo.getPayAmount()); // 支付金额,格式为小数点后保留 2 位
jsonObject.put("recordTime", DateUtils.getDateTime()); // 记录上报时间
// 查询出该平台的配置参数
ThirdPartySecretInfoVO thirdPartySecretInfoVO = thirdpartySecretInfoService.queryByThirdPlatformType(thirdPlatformType);
if (thirdPartySecretInfoVO == null) {
throw new BusinessException("", "无此平台配置信息");
}
// 加密参数(方法中已将 sign 放入参数中并返回)
String recordInfoStr = Sm2Util.generateEncryptedRequestInfo(jsonObject, thirdPartySecretInfoVO.getTheirPublicSecret(), thirdPartySecretInfoVO.getOurPrivateSecret());
String tpToken = "4121d1c9121a41d894ed5082d264db30";
// 发送请求
String url = thirdPartySecretInfoVO.getTheirUrlPrefix();
JSONObject postParam = new JSONObject();
postParam.put("recordInfo", recordInfoStr);
String result = HttpUtils.sendPostTpToken(url, postParam.toJSONString(), tpToken);
return result;
}
}