From 00779ea0f8374e5bbdffc8faa20d65e3c72616c2 Mon Sep 17 00:00:00 2001
From: Pu Zhibing <393733352@qq.com>
Date: 星期六, 02 十一月 2024 19:26:23 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'
---
ruoyi-service/ruoyi-payment/src/main/java/com/ruoyi/payment/wx/utils/WxAbstractPay.java | 82 +++++++++++++++++++++++++++++++++++++---
1 files changed, 75 insertions(+), 7 deletions(-)
diff --git a/ruoyi-service/ruoyi-payment/src/main/java/com/ruoyi/payment/wx/utils/WxAbstractPay.java b/ruoyi-service/ruoyi-payment/src/main/java/com/ruoyi/payment/wx/utils/WxAbstractPay.java
index a17e3bd..629c51f 100644
--- a/ruoyi-service/ruoyi-payment/src/main/java/com/ruoyi/payment/wx/utils/WxAbstractPay.java
+++ b/ruoyi-service/ruoyi-payment/src/main/java/com/ruoyi/payment/wx/utils/WxAbstractPay.java
@@ -1,9 +1,12 @@
package com.ruoyi.payment.wx.utils;
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.core.type.TypeReference;
import com.ruoyi.common.core.utils.WebUtils;
+import com.ruoyi.payment.wx.model.WxCloseOrderModel;
import com.ruoyi.payment.wx.model.WxPaymentInfoModel;
-import com.ruoyi.payment.wx.model.WxPaymentRefundModel;
+import com.ruoyi.payment.api.model.WxPaymentRefundModel;
import com.ruoyi.payment.wx.resp.NotifyV3PayDecodeRespBody;
import com.wechat.pay.contrib.apache.httpclient.auth.PrivateKeySigner;
import com.wechat.pay.contrib.apache.httpclient.auth.Verifier;
@@ -68,7 +71,7 @@
*/
protected String buildBaseParam(WxPaymentInfoModel requestBody, String notifyUrl) {
// 封装基础数据
- requestBody.setNotify_url(notifyUrl);
+ requestBody.setNotify_url(notifyUrl + requestBody.getNotify_url());
String reqBody = WxJsonUtils.toJsonString(requestBody);
return reqBody;
}
@@ -198,9 +201,46 @@
url
, socketTimeout
, connectTimeout);
- String repBody = result(httpClient, httpGet);
- NotifyV3PayDecodeRespBody body = WxJsonUtils.parseObject(repBody, NotifyV3PayDecodeRespBody.class);
- return body;
+ CloseableHttpResponse response = null;
+ try {
+ response = httpClient.execute(httpGet);
+ int statusCode = response.getStatusLine().getStatusCode();
+ String respBodyStr = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8);
+ if (WxUtils.getLogger().isDebugEnabled()) {
+ WxUtils.debug("请求成功:{}", respBodyStr);
+ }
+ if(404 == statusCode){
+ return null;
+ }
+ // 成功相应
+ if (STATUS_CODE == statusCode || OTHER_STATUS_CODE == statusCode ) {
+ NotifyV3PayDecodeRespBody body = WxJsonUtils.parseObject(respBodyStr, NotifyV3PayDecodeRespBody.class);
+ return body;
+ } else {
+ WxUtils.error("failed,resp code = {},return body = {}", statusCode, respBodyStr);
+ throw new RuntimeException(respBodyStr);
+ }
+ } catch (ConnectTimeoutException e) {
+ e.printStackTrace();
+ throw new RuntimeException("接口超时");
+ } catch (SocketTimeoutException e) {
+ e.printStackTrace();
+ throw new RuntimeException("读取接口数据超时");
+ } catch (IOException e) {
+ e.printStackTrace();
+ throw new RuntimeException("接口请求失败,请尝试检查网络环境或请求接口是否能正常访问");
+ } finally {
+ // 关闭响应
+ try {
+ if (response != null) {
+ //关闭结果集
+ response.getEntity().getContent().close();
+ response.close();
+ }
+ } catch (IOException e) {
+ throw new RuntimeException("关闭流异常");
+ }
+ }
}
/**
@@ -210,7 +250,7 @@
* @param mchid
* @return
*/
- public abstract NotifyV3PayDecodeRespBody query(String out_trade_no, String mchid);
+ public abstract NotifyV3PayDecodeRespBody query(String out_trade_no);
/**
@@ -220,6 +260,10 @@
* @return
*/
public abstract Map<String, Object> refund(WxPaymentRefundModel refundModel);
+
+
+
+ public abstract String close(String out_trade_no);
/**
* 订单退款
@@ -246,7 +290,6 @@
Map<String, Object> body = WxJsonUtils.parseObject(repBody, Map.class);
return body;
}
-
/**
* 请求结果
@@ -329,5 +372,30 @@
writer.close();
}
}
+
+
+ /**
+ * 关闭订单
+ * @param httpClient
+ * @param uri
+ * @param httpReadTimeoutMs
+ * @param httpConnectTimeoutMs
+ * @param closeModel
+ * @return
+ */
+ public String close(CloseableHttpClient httpClient,
+ String uri,
+ int httpReadTimeoutMs,
+ int httpConnectTimeoutMs,
+ WxCloseOrderModel closeModel) {
+ String reqBody = WxJsonUtils.toJsonString(closeModel);
+ //请求URL
+ HttpEntityEnclosingRequestBase httpPost = requestPost(
+ uri
+ , httpReadTimeoutMs
+ , httpConnectTimeoutMs, reqBody);
+ String repBody = result(httpClient, httpPost);
+ return repBody;
+ }
}
--
Gitblit v1.7.1