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

相关推荐
2601_9498049210 小时前
开源多商户商城源码最新版_适配微信小程序+H5+APP+PC多端
微信小程序·小程序
码云数智-大飞10 小时前
2026主流自助建站平台对比评测
微信小程序
2501_9339072114 小时前
上海本凡科技的微信小程序公司主要提供哪些服务?
科技·微信小程序·小程序
2601_9498049215 小时前
【全开源】西陆家政系统源码小程序(FastAdmin+ThinkPHP+原生微信小程序)
微信小程序·小程序
计算机毕设指导62 天前
基于微信小程序的智能停车场管理系统【源码文末联系】
java·spring boot·微信小程序·小程序·tomcat·maven·intellij-idea
2501_933907212 天前
如何选择西安优质小程序开发服务与本凡码农合作?
科技·微信小程序·小程序
咖啡の猫3 天前
微信小程序案例 - 自定义 tabBar
微信小程序·小程序·notepad++
咖啡の猫3 天前
微信小程序全局数据共享
微信小程序·小程序
桐溪漂流3 天前
微信小程序cli脚本预览上传
微信小程序·小程序
咖啡の猫3 天前
微信小程序使用 npm 包
微信小程序·小程序·npm