What should I do if the WeChat applet cannot obtain the unionId?

php是最好的语言
Release: 2018-08-09 11:55:02
Original
5032 people have browsed it

UnionID mechanism description

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

WeChat official flow chart:

What should I do if the WeChat applet cannot obtain the unionId?

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

Look at the return result given by WeChat official after the code request is successful:

What should I do if the WeChat applet cannot obtain the 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?

What should I do if the WeChat applet cannot obtain the unionId?

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!

Here comes the point. The problem is explained in the picture on WeChat’s official website below:

What should I do if the WeChat applet cannot obtain the unionId?

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template