公众号如何通过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的作用

相关推荐
xkxnq14 小时前
微信小程序地理定位功能
微信小程序·小程序
難釋懷14 小时前
微信小程序全局数据共享
微信小程序·小程序
郭邯14 小时前
小程序自定义组件学习笔记
微信小程序
xmdoor21 小时前
微信小程序:酒店预订管理系统
微信小程序·酒店预订·酒店系统·酒店管理
The_era_achievs_hero2 天前
微信小程序141~150
微信小程序·小程序·notepad++
熊猫片沃子2 天前
小程序间跳转与传值实现方案
前端·微信小程序
normi-D182 天前
微信小程序未登录状态下的导航拦截有哪些方法可以实现
微信小程序·小程序
wocwin2 天前
uniapp微信小程序vue3封装时间段范围选择组件
vue.js·微信小程序
晓风伴月2 天前
微信小程序:在ios中border边框显示不全
ios·微信小程序·小程序
新酱爱学习2 天前
前端海报生成的几种方式:从 Canvas 到 Skyline
前端·javascript·微信小程序