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

相关推荐
拉不动的猪40 分钟前
移动端调试工具VConsole初始化时的加载阻塞问题
前端·javascript·微信小程序
WangHappy2 天前
不写 Canvas 也能搞定!小程序图片导出的 WebView 通信方案
前端·微信小程序
小时前端2 天前
微信小程序选不了本地文件?用 web-view + H5 一招搞定
前端·微信小程序·uni-app
icebreaker3 天前
Weapp-vite:原生模式之外,多一种 Vue SFC 选择
前端·vue.js·微信小程序
icebreaker3 天前
重走 Vue 长征路 Weapp-vite:编译链路与 Wevu 运行时原理拆解
前端·vue.js·微信小程序
大米饭消灭者6 天前
Taro是怎么实现一码多端的【底层原理】
微信小程序·taro
FliPPeDround7 天前
Vitest Environment UniApp:让 uni-app E2E 测试变得前所未有的简单
微信小程序·e2e·前端工程化
FliPPeDround7 天前
微信小程序自动化的 AI 新时代:wechat-devtools-mcp 智能方案
微信小程序·ai编程·mcp
码云数智-大飞7 天前
如何创建自己的小程序,码云数智与有赞平台对比
微信小程序
luffy54597 天前
微信小程序页面使用类似filter函数的wxs语法
微信小程序·小程序