公众号和小程序如何获取UnionID?

灏忕▼搴� 文章 2021-11-30 16:20 24 0 全屏看文

公众号和小程序如何获取UnionID?How to obtain UnionID for official accounts and mini programs?

公众号和小程序如何获取UnionID?

想使用小程序判断是否关注公众号,公众号和小程序已经关联。当用户关注公众号时,后台会获取用户的event、openid等信息。

使用

https://sh.api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid="+ appid + "&secret=" + secret;

获取accessToken,然后使用

https://api.weixin.qq.com/cgi-bin/user/info?access_token="+token+"&openid="+fromusername+"&lang=zh_CN"

获取用户信息,但是用户信息里没有unionId这个返回值。

想问一下各位,想获取unionId,必须让小程序和公众号绑定在同一个微信开放平台账号里吗?小程序和公众号关联不行吗?或者是我的access_token获取的不对

The official account is related to the official account number. When users are concerned about the official account, the background will get users' event, openid and other information. use https://sh.api.weixin.qq.com/cgi-bin/token?grant_ type=client_ Credential & appid = "+ appid +" & Secret = "+ secret; get accesstoken and use https://api.weixin.qq.com/cgi-bin/user/info?access_token= "+ token +" & openid = "+ fromusername +" & lang = zh_cn "get the user information, but there is no return value of unionid in the user information. Would you like to ask everyone, if you want to get unionId, you must bind the applet and public number to the same official account of WeChat open platform? Can small programs and official account be linked? Or my access_ Incorrect token acquisition

鍥炵瓟锛�

圣殿骑士:

unionid 是要去微信开放平台兑换的, 而且同一个用户 unionId 是不变的

另外小程序还可以通过云函数直接获取

https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/union-id.html

三年两语:

要绑定到微信开放平台,才能获取到unionId

青寒:

想获取unionId,必须让小程序和公众号绑定在同一个微信开放平台账号里吗?

必须。

unionid是根据微信开放平台生成的东西,你不绑开放平台是没有的。

-EOF-