From c10d6358b9f014375a13821465bc978d0c0da22e Mon Sep 17 00:00:00 2001
From: linwe <872216996@qq.com>
Date: Wed, 29 May 2024 17:17:08 +0800
Subject: [PATCH] 通过E呼即办数据统计

---
 src/main/java/org/springblade/modules/pay/service/impl/WxPayServiceImpl.java |   47 +++++++++++++++++++++++------------------------
 1 files changed, 23 insertions(+), 24 deletions(-)

diff --git a/src/main/java/org/springblade/modules/pay/service/impl/WxPayServiceImpl.java b/src/main/java/org/springblade/modules/pay/service/impl/WxPayServiceImpl.java
index dfc021c..925189e 100644
--- a/src/main/java/org/springblade/modules/pay/service/impl/WxPayServiceImpl.java
+++ b/src/main/java/org/springblade/modules/pay/service/impl/WxPayServiceImpl.java
@@ -20,6 +20,7 @@
 import org.springblade.common.enums.wxpay.WxNotifyType;
 import org.springblade.common.enums.wxpay.WxRefundStatus;
 import org.springblade.common.enums.wxpay.WxTradeState;
+import org.springblade.common.exception.CustomException;
 import org.springblade.common.utils.HttpUtils;
 import org.springblade.common.utils.SpringUtils;
 import org.springblade.common.utils.WechatPay2ValidatorForRequest;
@@ -32,19 +33,17 @@
 import org.springblade.modules.pay.service.IPaymentInfoService;
 import org.springblade.modules.pay.service.IRefundInfoService;
 import org.springblade.modules.pay.service.IWxPayService;
-import org.springblade.modules.property.entity.PropertyChargeRecord;
-import org.springblade.modules.property.service.IPropertyChargeService;
 import org.springblade.modules.system.entity.User;
 import org.springblade.modules.system.service.IUserService;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
-import org.springframework.util.StringUtils;
 
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import java.io.FileInputStream;
 import java.io.IOException;
+import java.math.BigDecimal;
 import java.nio.charset.StandardCharsets;
 import java.security.*;
 import java.util.*;
@@ -52,19 +51,15 @@
 import java.util.concurrent.locks.ReentrantLock;
 
 @Service
-public class WxPayServiceImpl extends ServiceImpl<WxPayMapper,WxPayInfo> implements IWxPayService {
+public class WxPayServiceImpl extends ServiceImpl<WxPayMapper, WxPayInfo> implements IWxPayService {
 	private static Logger logger = LoggerFactory.getLogger(WxPayServiceImpl.class);
 
 
 	@Resource
 	private WxPayConfig wxPayConfig;
 
-	@Resource
-	private IPropertyChargeService iPropertyChargeService;
-
-
-	@Resource
-	private CloseableHttpClient wxPayClient;
+//	@Resource
+//	private CloseableHttpClient wxPayClient;
 
 	@Resource
 	private IOrderInfoService orderInfoService;
@@ -76,12 +71,6 @@
 	private IRefundInfoService refundsInfoService;
 
 	private final ReentrantLock lock = new ReentrantLock();
-
-
-	@Override
-	public Object getOpenId(String code) {
-		return null;
-	}
 
 	@Transactional(rollbackFor = Exception.class)
 	@Override
@@ -157,7 +146,7 @@
 		httpGet.setHeader("Accept", "application/json");
 
 		//完成签名并执行请求
-		CloseableHttpResponse response = wxPayClient.execute(httpGet);
+		CloseableHttpResponse response = null;//wxPayClient.execute(httpGet);
 
 		try {
 			String bodyAsString = EntityUtils.toString(response.getEntity());//响应体
@@ -269,7 +258,7 @@
 		httpPost.setHeader("Accept", "application/json");//设置响应报文格式
 
 		//完成签名并执行请求,并完成验签
-		CloseableHttpResponse response = wxPayClient.execute(httpPost);
+		CloseableHttpResponse response =null;// wxPayClient.execute(httpPost);
 
 		try {
 
@@ -315,7 +304,7 @@
 		httpGet.setHeader("Accept", "application/json");
 
 		//完成签名并执行请求
-		CloseableHttpResponse response = wxPayClient.execute(httpGet);
+		CloseableHttpResponse response = null;//wxPayClient.execute(httpGet);
 
 		try {
 			String bodyAsString = EntityUtils.toString(response.getEntity());
@@ -421,13 +410,15 @@
 	}
 
 
-
 	@Override
-	public Map<String, String> jsapiPay(Long properChargeRecordId) throws Exception {
+	public Map<String, String> jsapiPay(Long properChargeRecordId) throws IOException {
 
 		String prepayId = "";
 		//生成订单
-		OrderInfoEntity orderInfo = orderInfoService.getOne(Wrappers.<OrderInfoEntity>lambdaQuery().eq(OrderInfoEntity::getProperChargeRecordId,properChargeRecordId));
+		OrderInfoEntity orderInfo = orderInfoService.getOne(Wrappers.<OrderInfoEntity>lambdaQuery().eq(OrderInfoEntity::getProperChargeRecordId, properChargeRecordId));
+		if (orderInfo.getTotalFee() <= 0) {
+			throw new CustomException("支付金额不能低于等于0元");
+		}
 		IUserService userService = SpringUtils.getBean(IUserService.class);
 		User serviceOne = userService.getOne(Wrappers.<User>lambdaQuery().eq(User::getId, AuthUtil.getUserId()));
 
@@ -470,7 +461,7 @@
 		httpPost.setHeader("Accept", "application/json");
 
 		//完成签名并执行请求
-		CloseableHttpResponse response = wxPayClient.execute(httpPost);
+		CloseableHttpResponse response = null;//wxPayClient.execute(httpPost);
 
 		try {
 			String bodyAsString = EntityUtils.toString(response.getEntity());//响应体
@@ -503,6 +494,14 @@
 			payMap.put("paySign", paySign);
 			logger.info("返回参数 ===> {}" + gson.toJson(payMap));
 			return payMap;
+		} catch (IOException e) {
+			throw new RuntimeException(e);
+		} catch (SignatureException e) {
+			throw new RuntimeException(e);
+		} catch (NoSuchAlgorithmException e) {
+			throw new RuntimeException(e);
+		} catch (InvalidKeyException e) {
+			throw new RuntimeException(e);
 		} finally {
 			response.close();
 		}
@@ -592,7 +591,7 @@
 		httpPost.setHeader("Accept", "application/json");
 
 		//完成签名并执行请求
-		CloseableHttpResponse response = wxPayClient.execute(httpPost);
+		CloseableHttpResponse response = null;//wxPayClient.execute(httpPost);
 
 		try {
 			int statusCode = response.getStatusLine().getStatusCode();//响应状态码

--
Gitblit v1.9.3