String posturl = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="+access_token;
String JsonStr = "{\n" +
" \"touser\":\""+openid+"\",\n" +
" \"template_id\":\""+template_id1+"\",\n" +
" \"url\":\""+url+"\", \n" +
" \"data\":{\n" +
" \"thing2\":{\n" +
" \"value\":\"测试123\"\n" +
" },\n" +
" \"time4\": {\n" +
" \"value\":\""+tm+"\"\n" +
" }\n" +
" }\n" +
" }";
byte[] utf8Bytes = JsonStr.getBytes(StandardCharsets.UTF_8);
String utf8EncodedString = new String(utf8Bytes, StandardCharsets.UTF_8);
System.out.println(utf8EncodedString);
Map<String ,String > headers = new HashMap<>();
headers.put("Content-Type","application/json;charset=utf-8");
String resultJson = HttpUtil.post(posturl,utf8EncodedString,headers);
System.out.println(resultJson);
代码如上所示,System.out.println(utf8EncodedString);输出的内容显示正常,但是在微信小程序上查看的时候中文变成??
你好,自行排查转码问题,转码是自己的拼接