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"}