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

相关推荐
admin and root12 小时前
「移动安全」安卓APP 反编译&frida脱壳技巧分享
android·开发语言·python·web安全·微信小程序·移动安全·攻防演练
m0_462803882 天前
【无标题】
微信小程序
码农学院3 天前
微信小程序云开发实战:扫码点餐系统的高并发订单处理与外卖接单架构
微信小程序·架构·notepad++
这是个栗子4 天前
uni-app 微信小程序开发:常用函数总结(一)
微信小程序·小程序·uni-app·getcurrentpages
爱勇宝4 天前
上线 20 多天后,我才发现小程序的图片上传一直不可用
微信小程序·智能小程序
万亿少女的梦1686 天前
基于微信小程序、Spring Boot与Vue3的智慧养老管理系统设计与实现
spring boot·redis·微信小程序·mybatis·vue3
alxraves7 天前
零代码AI助手:用大模型自动生成微信小程序界面与逻辑
人工智能·微信小程序·notepad++
秃头披风侠_郑7 天前
【uniapp】一文让你学会微信小程序+APP+H5全平台实战指南
前端·微信小程序·uni-app
爱勇宝7 天前
一个家庭成长小程序的 MVP 复盘:看到用户在用我很欣慰
微信小程序·产品·设计
这是个栗子8 天前
uni-app微信小程序开发:高频核心 API(三)
微信小程序·小程序·uni-app