fix: 修复微信服务号中文乱码问题

This commit is contained in:
椰子 2021-07-19 16:36:24 +08:00
parent df19957523
commit 0b5f8be3b5

View File

@ -4,18 +4,25 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.cicdi.notify.*;
import com.cicdi.notify.wechat.WechatProvider;
import org.apache.http.Consts;
import org.apache.http.Header;
import org.apache.http.HttpHeaders;
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.client.utils.URIBuilder;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.message.BasicHeader;
import org.apache.http.util.EntityUtils;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.time.Duration;
import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;
@ -87,8 +94,8 @@ public class WechatSubscriptionNotifier implements Notifier<WechatSubscriptionTe
.addParameter("access_token", getToken())
.build();
HttpPost httpPost = new HttpPost(sendMessageURI);
httpPost.setHeader("Content-Type", "application/json;charset=utf8");
StringEntity requestBody = new StringEntity(template.createJsonRequest());
httpPost.setHeader("Content-Type", "application/json; charset=UTF-8");
StringEntity requestBody = new StringEntity(template.createJsonRequest(), ContentType.APPLICATION_JSON);
httpPost.setEntity(requestBody);
CloseableHttpResponse response = httpClient.execute(httpPost);
JSONObject responseJson = JSON.parseObject(EntityUtils.toString(response.getEntity()));