公众号如何通过openid获取unionid

通过接口

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

返回的数据如下:

前提是必须绑定 微信开放平台

token如何获取呢

代码如下:

java 复制代码
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的作用

相关推荐
流烟默8 小时前
vue和微信小程序处理markdown格式数据
前端·vue.js·微信小程序
乔冠宇13 小时前
微信小程序中将图片截图为正方形(自动居中)
微信小程序·小程序·typescript·uniapp
V+zmm1013416 小时前
在线办公小程序(springboot论文源码调试讲解)
vue.js·spring boot·微信小程序·小程序·毕业设计
V+zmm1013417 小时前
自驾游拼团小程序的设计与实现(ssm论文源码调试讲解)
java·数据库·微信小程序·小程序·毕业设计
黑马源码库miui520861 天前
挪车小程序挪车二维码php+uniapp
微信小程序·小程序·微信公众平台
盛夏绽放1 天前
微信小程序地图map全方位解析
微信小程序·小程序
初尘屿风1 天前
基于微信小程序的电影院订票选座系统的设计与实现,SSM+Vue+毕业论文+开题报告+任务书+指导搭建视频
vue.js·微信小程序·小程序
韩召华2 天前
微信小程序(uni)+蓝牙连接+Xprint打印机实现打印功能
微信小程序·小程序·notepad++
愤怒的山羊2 天前
微信小程序消息推送解密
微信小程序·小程序
韩召华2 天前
微信小程序实现拉卡拉支付
微信小程序·小程序