Tomb-sweeping Day holiday group suddenly frying pan, said that all the nicknames used by all small programs have become wechat nicknames

At that time I will

What happened to the 13th?

Scared me to get up and look through the document (requires the code to scroll straight back)

wx.getUserProfile(Object object)

Base library 2.10.4 support, earlier versions need to be compatible processing.

Get user information. An authorization window pops up for each request, and userInfo is returned after the user agrees.

GetUserInfo obtains user information. It is expected that from April 13, 2021, getUserInfo will no longer pop up popup window and directly return anonymous user information, that is, the return parameter of wx.getUserInfo interface remains unchanged, but the userInfo obtained by developers is anonymous information.

In order to optimize user experience, the platform will make the following adjustments: From February 23, 2021, if the small program has been bound on the wechat open platform, the login credentials obtained through the Wx. login interface can be directly exchanged for the new version of the small program issued by unionID after April 13, 2021. Wx.getuserinfo cannot be used to retrieve user information (avatar, nickname, gender, and region). Anonymous data (including user information in userInfo and encryptedData) will be retrieved directly. The ability to retrieve encrypted openID and unionID data will not be adjusted. Previously released versions of applets are not affected, but adaptation is required if version updates are to be made. Added getUserProfile interface (supported by base library version 2.10.4), which can obtain user profile picture, nickname, gender and region information. Developers need user confirmation every time to obtain user personal information through this interface. Specific interface documents: GetUserProfile interface is supported from the base library version 2.10.4 (covering wechat version 7.0.9 and above). Considering that developers have the request to obtain user profile name in the earlier version, in the case that getUserProfile is not supported, Developers can continue to use the getUserInfo capability. Developers can refer to the sample code in the getUserProfile interface documentation for adaptation. Please use the wx.getUserInfo interface or developers adapt as soon as possible. Developer tool version 1.05.2103022 now supports the getUserProfile interface debugging. Developers can download this version for modification.

The reason is just like wechat said

Many developers invoke the getUserInfo popup by means of a component when opening the applet. If the user clicks reject, the applet cannot be used, which interrupts the normal process of using the applet and is not conducive to the applet acquiring new users.

Here I will give the adaptation code of UNI-App, and students can draw a reference from it (the official package released before April 13 will not be affected for the time being).

html

<button V-if ="canUseGetUserProfile" hover-class="none" @tap="getUserProfile" Hover -class="none" open-type="getUserInfo" @getUserinfo ="setUserInfo">Copy the code

data

canUseGetUserProfile: false
Copy the code

js

OnLoad () {if (uni.getUserProfile) {this.setData({canUseGetUserProfile: Wx.getuserprofile () {// Wx.getUserProfile is recommended to obtain user information. Uni. GetUserProfile ({desc: (res) => {// business logic}})},Copy the code

Notice here

Desc is mandatory, and the message may be displayed in a pop-up in the future, so use caution. The getUserProfileAPI is not hoisted by open-type but is called with @tap=”getUserProfile” or bindTap =”getUserProfile”

It must be called directly and cannot be called by other functions

Otherwise the getUserProfile: Fail Can only be invoked by User TAP gesture is invoked. error

If you’re asking me what I think

Just like the comments in the wechat development document, so many bugs are not fixed

Please give it a thumbs up if it helps 3Q

The source address