通过接口
https://api.weixin.qq.com/cgi-bin/user/info?access_token=xxxxxxx&lang=zh_CN
返回的数据如下:
前提是必须绑定 微信开放平台
token如何获取呢
代码如下:
String tokenUrl = "https://api.weixin.qq.com/cgi-bin/token"; //get请求
String grant_type = "client_credential";
String appid = "xxxxxxxxx";
String secret = "xxxxxxxxx";
//获取token
StringBuilder sb = new StringBuilder();
sb.append(tokenUrl);
sb.append("?grant_type=" + grant_type);
sb.append("&appid=" + appid);
sb.append("&secret=" + secret);
HttpRequest httpRequest = HttpRequest.get(sb.toString());
JsonNode jsonNode = httpRequest.execute().asJsonNode();
String accessToken = jsonNode.get("access_token").asText();
System.out.println("获取的accessToken为:" + accessToken);
对于unionid的作用