If a developer has multiple mobile applications, website applications, and public accounts (including mini programs), they can be distinguished by unionid The uniqueness of the user, because as long as it is a mobile application, website application and public account (including mini program) under the same WeChat open platform account, the user's unionid is unique. In other words, for the same user, the unionid is the same for different applications under the same WeChat open platform.
Our system has provided WeChat login for mobile applications, website applications, and public accounts. Our backend has a WeChat account binding function. Therefore, it is necessary to determine whether the user has bound WeChat ID based on the user's unique unionID given by WeChat.
Official link for WeChat Mini Program API details: https://developers.weixin.qq.com/miniprogram/dev/api/api-login.html#wxloginobject
The front-end calls wx.login to obtain the code, and then returns the code to the background with the code and appid, and secret accesses the WeChat interface to obtain session_key, openid and unionId
I The result returned at that time was the one that did not satisfy the UnionID situation. Here I am a black man with three consecutive question marks? ? ?
Let’s take a look at the official explanation given by WeChat. How can we satisfy the UnionID situation?
So I Let the front-end staff do the logic. The front-end needs to get the code after calling the wx.login function, and then call the wx.authorize function to allow the user to authorize and agree, and then just call wx. The code obtained by login requests the back-end interface (the functions called here on the front-end seem to be in order wx.login ----> wx.authorize)
Then... ........................
Still only session_key and openid are returned, but there is still no UnionID! ! ! ! ! Ma Dan!
You need to go to the account center in WeChat’s open platform to apply. Developer Qualification Certification
Related Recommendations:
Detailed explanation of how to log in and obtain unionid in WeChat Mini Program
WeChat Mini Program Java implements AES decryption and obtains unionId
The above is the detailed content of What should I do if the WeChat applet cannot obtain the unionId?. For more information, please follow other related articles on the PHP Chinese website!