Wechat officially issued a notice on February 24, 2021 on the adjustment of interface related to small program login and user information, stipulating that the ability of wx.getUserInfo interface to obtain user information will be stopped at 24pm on April 28, 2021.
What did the notice adjust?
There are three main adjustments in this notice:
1. Disable wx.login’s ability to obtain unionID:
As long as the developer binds the applets to the open platform, the developer can call this interface to get the user’s UnionID. This avoids the problem of the developer having to call the wx.getUserInfo interface for user authorization to get the user’s UnionID. That clears the way for the next adjustment.
2. Disable the wx.getUserInfo interface’s ability to get user information:
Maybe wechat officials are also aware of the problem with wx.getUserInfo. The design of this interface is not reasonable. Why? Because this interface does two things: the first is to get the user information (avatar nickname, etc.), and the second, this interface also assumes the function of getting the user’s unionID. This causes developers to call the wx.getUserInfo interface in order to access data from multiple applets, public accounts, mobile applications, etc. What the developer really wants is to get the user’s unionid (which is supposed to be given by the login interface), not the user’s profile picture, which means that the interface is actually being abused.
3. Use the wx.getUserProfile interface to obtain user information:
As mentioned above, wechat abolished the wx.getUserInfo interface after realizing that it was not properly designed and replaced it with wx.getUserProfile. The function of the new interface is clear: to obtain user information.
What do you think of this adjustment?
In my opinion, this adjustment actually draws a clear line between small program login and authorization. Please refer to the two articles on applet login and authorization: Applet Login and Authorization. First of all, the unionID is completely obtained by the WX. login interface, no longer mixed with the user profile picture and other information, the login function belongs to the login; The authorized profile picture is obtained by the getUserProfile interface, and the authorization function belongs to the authorized interface. In this way, the principle of one interface only doing one thing is implemented. So, from a design point of view, this adjustment makes perfect sense. Of course, this adjustment process has been quite rapid, and many developers have complained about it. Maybe the authorities can do something more appropriate.
What should a newly developed applets do?
The last part of the notice has this best practice:
After the change, developers need only call the wx.login interface to obtain user identity identifiers. If you want to display a user’s profile picture nickname on the screen, you can use a component to render the profile picture. This component can be displayed on the screen without user confirmation. In some scenarios (such as social mini-programs), the developer can call the wx.getUserProfile interface to obtain the user’s profile picture nickname information. Every time the developer passes this interface, the user needs to confirm the interface. Please properly handle the time of calling the interface to avoid excessive popups that disturb the user.
For small programs that do not need to use other user information, there is no need to call the interface to obtain user information, and directly use open data to display their avatar gender, refer to this official document. If you do need user information for another user, such as for a comment function, you might need to display all the reviewers’ information, which must be obtained through the wx.getUserProfile interface before the user can comment.
How to change old code?
How do I change the code that’s already live? The first step is to check all the places where the applet client uses the wx.getUserInfo interface and replace this interface with wx.getUserProfile. Also check the applet server code to see if wx.getUserInfo decrypted unionID field is used, if so, need to be compatible (because wx.getUserProfile does not return unionID). If you want to be more detailed, you also need to deal with the compatibility issue of wechat version, please refer to the official documentation for details.
Refer to the project
Specific implementation can refer to my mall small program project.
Project Experience Address: Experience
Code: code