收藏
回答

微信模板消息中文乱码怎么解决?

AppID
wx0a0b3ddb1851f6f3
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);输出的内容显示正常,但是在微信小程序上查看的时候中文变成??

回答关注问题邀请回答
收藏

1 个回答

登录 后发表内容
问题标签