美文网首页
微信公众号开发--获取用户信息中文乱码的解决方案

微信公众号开发--获取用户信息中文乱码的解决方案

作者: 我乐你不乐 | 来源:发表于2017-02-14 13:52 被阅读0次

    https://api.weixin.qq.com/cgi-bin/user/info?access_token=ACCESS_TOKEN&openid=OPENID&lang=zh_CN

    将其中的access_token替换为我们的access_token

    openid为关注用户的openid就可以获取到用户的信息了。

    问题描述

    不过获取到的数据中文却是乱码

    {"openid":"oMzV3s_VLF5gRFZs6JLHckDj4WCk","nickname":"ä½ ä¸�ä¹�æ��ä¹�","sex":1,"language":"zh_CN","city":"西å®�","province":"é��西","country":"中å�½","headimgurl":"http:\/\/wx.qlogo.cn\/mmopen\/N9r0OBIzK7O30K7BZye4bLYb45nFmAtq9uqcWJ0j6qMuf1z6qtarnE4pVaaet9cw3x0xWicXFtTGvnia9f5HgvUN4lCW8iaRGqA\/0","privilege":[],"unionid":"oWBCXvwWv0gt86NdKBtvZqY3Pi44"}

    解决方案:

    String URL ="https://api.weixin.qq.com/cgi-bin/user/info?access_token=ACCESS_TOKEN&openid=OPENID&lang=zh_CN";

    // 原始json

    String jsonResult = HttpUtil.sendGet(URL.replace("OPENID", openid).replace("ACCESS_TOKEN", token));

    // 编码后的json

    String json =newString(jsonResult.getBytes("ISO-8859-1"),"UTF-8");

    处理后的数据:

    {"openid":"oMzV3s_VLF5gRFZs6JLHckDj4WCk","nickname":"你不乐我乐","sex":1,"language":"zh_CN","city":"西安","province":"陕西","country":"中国","headimgurl":"http:\/\/wx.qlogo.cn\/mmopen\/N9r0OBIzK7O30K7BZye4bLYb45nFmAtq9uqcWJ0j6qMuf1z6qtarnE4pVaaet9cw3x0xWicXFtTGvnia9f5HgvUN4lCW8iaRGqA\/0","privilege":[],"unionid":"oWBCXvwWv0gt86NdKBtvZqY3Pi44"}

    相关文章

      网友评论

          本文标题: 微信公众号开发--获取用户信息中文乱码的解决方案

          本文链接:https://www.haomeiwen.com/subject/bfmxwttx.html