From 81da61b828e29b7745e1382dfbbaeb685dc083ef Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期二, 23 一月 2024 17:17:55 +0800 Subject: [PATCH] 抖音转链修改 --- utils/src/main/java/org/yeshi/utils/wx/WXPayV3Util.java | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 40 insertions(+), 2 deletions(-) diff --git a/utils/src/main/java/org/yeshi/utils/wx/WXPayV3Util.java b/utils/src/main/java/org/yeshi/utils/wx/WXPayV3Util.java index f137533..d9b5448 100644 --- a/utils/src/main/java/org/yeshi/utils/wx/WXPayV3Util.java +++ b/utils/src/main/java/org/yeshi/utils/wx/WXPayV3Util.java @@ -11,6 +11,7 @@ import org.apache.commons.io.Charsets; import org.apache.commons.io.IOUtils; import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; import org.apache.http.entity.ContentType; import org.apache.http.entity.StringEntity; @@ -65,7 +66,7 @@ */ private static JSONObject request(String url, String requestData, WXAPPInfo app) throws Exception { HttpPost httpPost = new HttpPost(url); - + HttpGet httpGet=new HttpGet(url); if (StringUtil.isNullOrEmpty(requestData)) { requestData = "{}"; @@ -81,6 +82,43 @@ //瀹屾垚绛惧悕骞舵墽琛岃姹� CloseableHttpClient httpClient = getHttpClient(app); CloseableHttpResponse response = httpClient.execute(httpPost); + try { + int statusCode = response.getStatusLine().getStatusCode(); + if (statusCode == 200) { + System.out.println("success,return body = " + EntityUtils.toString(response.getEntity())); + String result = EntityUtils.toString(response.getEntity()); + JSONObject resultJson = JSONObject.fromObject(result); + return resultJson; + } else if (statusCode == 204) { + System.out.println("success"); + } else { + System.out.println("failed,resp code = " + statusCode + ",return body = " + EntityUtils.toString(response.getEntity())); + throw new Exception("request failed"); + } + } finally { + response.close(); + } + return null; + } + + + private static JSONObject requestGet(String url, String requestData, WXAPPInfo app) throws Exception { + HttpGet httpGet=new HttpGet(url); + + if (StringUtil.isNullOrEmpty(requestData)) { + requestData = "{}"; + } + +// if (!StringUtil.isNullOrEmpty(requestData)) { +// StringEntity entity = new StringEntity(requestData, ContentType.APPLICATION_JSON.withCharset(Charset.forName("UTF-8"))); +// entity.setContentType("application/json;charset=utf-8"); +// httpPost.setEntity(entity); +// } + httpGet.setHeader("Accept", "application/json;charset=utf-8"); + + //瀹屾垚绛惧悕骞舵墽琛岃姹� + CloseableHttpClient httpClient = getHttpClient(app); + CloseableHttpResponse response = httpClient.execute(httpGet); try { int statusCode = response.getStatusLine().getStatusCode(); if (statusCode == 200) { @@ -188,7 +226,7 @@ */ public static WXPayOrderInfoV3 getPayOrderInfo(String orderNo, WXAPPInfo app) throws Exception { String url = String.format("https://api.mch.weixin.qq.com/v3/pay/transactions/out-trade-no/%s?mchid=%s", URLEncoder.encode(orderNo), app.getMchId()); - JSONObject result = request(url, "", app); + JSONObject result = requestGet(url, "", app); if (result == null) return null; return new Gson().fromJson(result.toString(), WXPayOrderInfoV3.class); -- Gitblit v1.8.0