From 65e3fa13dce818f591ed421ae73413dc8687cbf6 Mon Sep 17 00:00:00 2001 From: Memory-9527 <30432849+Memory-9527@users.noreply.github.com> Date: Thu, 10 Apr 2025 21:36:02 +0800 Subject: [PATCH 1/4] fix issues #352 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 使用ApacheHttpClientAdapter 发送post请求时指定ContentType参数为UTF-8,解决微信客户端接收的时候中文乱码,返回验签校验失败的问题 --- .../pay/java/core/http/apache/ApacheHttpClientAdapter.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/com/wechat/pay/java/core/http/apache/ApacheHttpClientAdapter.java b/core/src/main/java/com/wechat/pay/java/core/http/apache/ApacheHttpClientAdapter.java index bb21ba09..549f780f 100644 --- a/core/src/main/java/com/wechat/pay/java/core/http/apache/ApacheHttpClientAdapter.java +++ b/core/src/main/java/com/wechat/pay/java/core/http/apache/ApacheHttpClientAdapter.java @@ -104,11 +104,11 @@ private HttpEntity buildApacheHttpEntity( if (wechatPayRequestBody == null) { return new StringEntity("", ""); } - + // 指定ContentType参数为UTF-8, fix issues #352 if (wechatPayRequestBody instanceof JsonRequestBody) { return new StringEntity( ((JsonRequestBody) wechatPayRequestBody).getBody(), - ContentType.create(wechatPayRequestBody.getContentType())); + ContentType.create(wechatPayRequestBody.getContentType(),"UTF-8")); } if (wechatPayRequestBody instanceof FileRequestBody) { FileRequestBody fileRequestBody = (FileRequestBody) wechatPayRequestBody; From cbf28945c000a61d078c4a7d5a6841635c5cdddb Mon Sep 17 00:00:00 2001 From: Memory-9527 <30432849+Memory-9527@users.noreply.github.com> Date: Fri, 11 Apr 2025 14:32:51 +0800 Subject: [PATCH 2/4] fix issues #352 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 使用ApacheHttpClientAdapter 发送post请求时指定ContentType参数为UTF-8,解决微信客户端接收的时候中文乱码,返回验签校验失败的问题 --- .../pay/java/core/http/apache/ApacheHttpClientAdapter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/com/wechat/pay/java/core/http/apache/ApacheHttpClientAdapter.java b/core/src/main/java/com/wechat/pay/java/core/http/apache/ApacheHttpClientAdapter.java index 549f780f..059c7610 100644 --- a/core/src/main/java/com/wechat/pay/java/core/http/apache/ApacheHttpClientAdapter.java +++ b/core/src/main/java/com/wechat/pay/java/core/http/apache/ApacheHttpClientAdapter.java @@ -108,7 +108,7 @@ private HttpEntity buildApacheHttpEntity( if (wechatPayRequestBody instanceof JsonRequestBody) { return new StringEntity( ((JsonRequestBody) wechatPayRequestBody).getBody(), - ContentType.create(wechatPayRequestBody.getContentType(),"UTF-8")); + ContentType.create(wechatPayRequestBody.getContentType(), StandardCharsets.UTF_8)); } if (wechatPayRequestBody instanceof FileRequestBody) { FileRequestBody fileRequestBody = (FileRequestBody) wechatPayRequestBody; From acbb75c74bf779ba1470ebf9b66ba001345ebec8 Mon Sep 17 00:00:00 2001 From: Memory-9527 <30432849+Memory-9527@users.noreply.github.com> Date: Fri, 11 Apr 2025 19:34:55 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E6=8C=87=E5=AE=9AContentType=E5=8F=82=E6=95=B0=E6=96=B9?= =?UTF-8?q?=E6=B3=95=E5=90=8E=E5=BF=98=E8=AE=B0=E6=B7=BB=E5=8A=A0import?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pay/java/core/http/apache/ApacheHttpClientAdapter.java | 1 + 1 file changed, 1 insertion(+) diff --git a/core/src/main/java/com/wechat/pay/java/core/http/apache/ApacheHttpClientAdapter.java b/core/src/main/java/com/wechat/pay/java/core/http/apache/ApacheHttpClientAdapter.java index 059c7610..a1b3868c 100644 --- a/core/src/main/java/com/wechat/pay/java/core/http/apache/ApacheHttpClientAdapter.java +++ b/core/src/main/java/com/wechat/pay/java/core/http/apache/ApacheHttpClientAdapter.java @@ -15,6 +15,7 @@ import com.wechat.pay.java.core.http.OriginalResponse; import java.io.IOException; import java.io.InputStream; +import java.nio.charset.StandardCharsets; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import org.apache.http.Header; From 01a5b8a059be56df37452bca8222b91acd91e11d Mon Sep 17 00:00:00 2001 From: Memory-9527 <30432849+Memory-9527@users.noreply.github.com> Date: Fri, 11 Apr 2025 20:07:47 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=8C=87=E5=AE=9AContentType=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E4=B8=BAUTF-8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pay/java/core/http/ApacheHttpClientAdapterTest.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/core/src/test/java/com/wechat/pay/java/core/http/ApacheHttpClientAdapterTest.java b/core/src/test/java/com/wechat/pay/java/core/http/ApacheHttpClientAdapterTest.java index c331bf44..864e9d0d 100644 --- a/core/src/test/java/com/wechat/pay/java/core/http/ApacheHttpClientAdapterTest.java +++ b/core/src/test/java/com/wechat/pay/java/core/http/ApacheHttpClientAdapterTest.java @@ -11,6 +11,7 @@ import java.io.IOException; import java.io.InputStream; import java.net.URI; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Paths; import org.apache.http.Header; @@ -253,7 +254,7 @@ public void process(org.apache.http.HttpRequest request, HttpContext context) HttpEntity entity = new StringEntity( JSON_REQUEST_BODY.getBody(), - ContentType.create(JSON_REQUEST_BODY.getContentType())); + ContentType.create(JSON_REQUEST_BODY.getContentType(), StandardCharsets.UTF_8)); Assert.assertEquals( entity.getContentType().getValue(), reqEntity.getContentType().getValue()); Assert.assertEquals(entity.getContentLength(), reqEntity.getContentLength()); @@ -1057,7 +1058,7 @@ public void process(org.apache.http.HttpRequest request, HttpContext context) HttpEntity entity = new StringEntity( JSON_REQUEST_BODY.getBody(), - ContentType.create(JSON_REQUEST_BODY.getContentType())); + ContentType.create(JSON_REQUEST_BODY.getContentType(), StandardCharsets.UTF_8)); Assert.assertEquals( entity.getContentType().getValue(), reqEntity.getContentType().getValue()); Assert.assertEquals(entity.getContentLength(), reqEntity.getContentLength());