企业微信发送消息中文乱码问题

源自:http://www.jylt.cc/#/detail?id=22b368caddb4929122007686fd24f07b

问题复现

Map body = new HashMap<>(16);
body.put("touser", userid);
body.put("msgtype", "text");
body.put("agentid", agentId);

Map text = new HashMap<>(16);
text.put("content", content);
body.put("text", text);

String s = JSONObject.toJSONString(body);

String sendMessageApi = QyApiConstant.getSendMessageApi(qyAppList.getSecret());
String response = restTemplateStatic.postForObject(sendMessageApi, s, String.class);

这个时候发送出去的消息中文字符是乱码的。

解决方案

参数直接使用对象,而不能转换成json字符串。

Map body = new HashMap<>(16);
body.put("touser", userid);
body.put("msgtype", "text");
body.put("agentid", agentId);

Map text = new HashMap<>(16);
text.put("content", content);
body.put("text", text);

String sendMessageApi = QyApiConstant.getSendMessageApi(qyAppList.getSecret());
String response = restTemplateStatic.postForObject(sendMessageApi, body, String.class);	

你可能感兴趣的:(#,企业微信,java)