From c3339221687168f0b7617f9074b15741f8df63b8 Mon Sep 17 00:00:00 2001
From: huanghongfa <huanghongfa123456>
Date: 星期五, 23 七月 2021 12:38:08 +0800
Subject: [PATCH] 测试中文乱码问题

---
 springcloud_k8s_panzhihuazhihuishequ/applets/src/main/java/com/panzhihua/applets/api/WxOfficialApi.java |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/springcloud_k8s_panzhihuazhihuishequ/applets/src/main/java/com/panzhihua/applets/api/WxOfficialApi.java b/springcloud_k8s_panzhihuazhihuishequ/applets/src/main/java/com/panzhihua/applets/api/WxOfficialApi.java
index 49d6628..375fd3f 100644
--- a/springcloud_k8s_panzhihuazhihuishequ/applets/src/main/java/com/panzhihua/applets/api/WxOfficialApi.java
+++ b/springcloud_k8s_panzhihuazhihuishequ/applets/src/main/java/com/panzhihua/applets/api/WxOfficialApi.java
@@ -13,6 +13,7 @@
 import java.net.MalformedURLException;
 import java.net.ProtocolException;
 import java.net.URL;
+import java.nio.charset.Charset;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -77,7 +78,7 @@
         String paramBody = JSON.toJSONString(map); // 这里用了Alibaba的fastjson
 
         OutputStream out = connection.getOutputStream();
-        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(out));
+        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(out,"utf-8"));
         bw.write(paramBody); // 向流中写入参数字符串
         bw.flush();
 
@@ -86,7 +87,7 @@
         int len = -1;
         StringBuffer sb = new StringBuffer();
         while((len = in.read(b)) != -1) {
-            sb.append(new String(b,0,len,"utf-8"));
+            sb.append(new String(b,0,len));
         }
 
         in.close();
@@ -94,7 +95,7 @@
     }
 
     @ApiOperation(value = "拉取公众号列表")
-    @GetMapping(value = "/list/noToken")
+    @GetMapping(value = "/list/noToken",produces="application/json;charset=utf-8")
     public R pageDiscuss() throws Exception{
         WxOfficialApi officialApi = new WxOfficialApi();
 

--
Gitblit v1.7.1