From ca825fdfe67223b2eb8a3f9c14b4e60e2339efc6 Mon Sep 17 00:00:00 2001 From: xuhy <3313886187@qq.com> Date: 星期三, 25 九月 2024 11:25:24 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/master' --- ruoyi-service/ruoyi-payment/src/main/java/com/ruoyi/payment/wx/utils/WxAbstractPay.java | 48 +++++++++++++++++++++++++++++++++++++++++++----- 1 files changed, 43 insertions(+), 5 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 3a3d081..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,5 +1,7 @@ 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; @@ -69,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; } @@ -199,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("关闭流异常"); + } + } } /** @@ -251,7 +290,6 @@ Map<String, Object> body = WxJsonUtils.parseObject(repBody, Map.class); return body; } - /** * 请求结果 -- Gitblit v1.7.1