收藏
回答

小程序消息推送后台返回乱码?

private String sendMessage(String opendId, String msgtype, Map<String, String> contentMap) throws UnsupportedEncodingException {

        Map<String, Object> replyMessageMap = new HashMap<String, Object>();

        replyMessageMap.put("touser", opendId);

        replyMessageMap.put("msgtype", msgtype);

        replyMessageMap.put(msgtype, contentMap);

        String messageJson = JSONObject.toJSONString(replyMessageMap);

        messageJson = new String(messageJson.getBytes(), "UTF-8");

        System.out.println(WechatAppletInterfaceUtils.getAccessToken());

        System.out.println(messageJson);

        String url = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=" + WechatAppletInterfaceUtils.getAccessToken();

        System.out.println("url"+url);

        RestTemplate restTemplate = new RestTemplate();

        String result = restTemplate.postForEntity(url, messageJson, String.class).getBody();

        System.out.println(result);

        // 发送结果

        return result;

    }


请问怎么解决

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

1 个回答

  • Mr.Zhao
    Mr.Zhao
    2020-05-06
    RestTemplate restTemplate = new RestTemplate();
    restTemplate.getMessageConverters()
            .set(1, new StringHttpMessageConverter(StandardCharsets.UTF_8));
    

    2020-05-06
    有用
    回复
登录 后发表内容
问题标签