Wechat applet getuserprofile adaptation scheme

Time:2021-6-25

The day before the Qingming Festival holiday, the group suddenly fried the pot, saying that all the nicknames used by the small program have becomeWechat nickname

At that time, I was

1 (14).jpg

Don’t you agree to the 13th???

Scared me to get up and look through the document (need code to turn back directly)

wx.getUserProfile(Object object)

The basic library 2.10.4 starts to support, and the lower version needs to be compatible.

Get user information. The authorization window will pop up for each request, and the user agrees and returns to userinfo.

GetUserInfo gets user information. It is estimated that from April 13, 2021, getUserInfo will no longer pop up and directly return anonymous user personal information, that is, the return parameters of wx.getuserinfo interface remain unchanged, but the userinfo obtained by developers is anonymous information.

image.png

image.png

In order to optimize the user experience, the platform will make the following adjustments:
From February 23, 2021, if the applet has been bound on wechat open platform, the login certificate obtained through wx.login interface can be directly exchanged for unionid
The new version of the applet released after April 13, 2021 can’t communicate with the user through wx.getuserinfo

The reason is just like wechat said

Many developers call up getUserInfo pop-up window by component when they open the applet. If the user clicks reject, they can’t use the applet. This method interrupts the normal process of using the applet, and it’s not conducive for the applet to obtain new users.

Here I will give you the adaptation code of the uni app, and you can draw inferences from one instance (the official package released before 4.13 will not be affected temporarily)

html

Wechat login
Wechat login

data

canUseGetUserProfile: false

js

onLoad() {
    //Determine whether the getuserprofile method exists
    if (uni.getUserProfile) {
      this.setData({
        canUseGetUserProfile: true
      })
    }
},

//Applet authorization API replacement getUserInfo replacement
 getUserProfile() {
    //It is recommended to use wx.getuserprofile to obtain user information. Every time a developer obtains user's personal information through this interface, it needs to be confirmed by the user
    //Developers should keep the nicknames of avatars that users fill in quickly to avoid repeated pop ups
    uni.getUserProfile({
      Desc: 'used to improve the member information', // declare the purpose after obtaining the user's personal information, which will be displayed in the pop-up window later, please fill in carefully
      success: (res) => {
        //Business logic
      }
    })
  },

Pay attention here

descIt is a required item, and the information may be prompted in the pop-up window in the future, so it should be filled in carefully;
getUserProfileAPI is not throughopen-typeInstead of lifting, use@tap="getUserProfile"orbindtap="getUserProfile"Called

It must be called directly and cannot be called through other function callbacks

Otherwise, it will be reportedgetUserProfile:fail can only be invoked by user TAP gesture.error

If you want to ask my opinion

Just like the comments in wechat development documentsThere are so many bugs that people can’t fix without doing something

image.png

If it’s useful, please praise 3Q

Source address

Recommended Today

Implementation example of go operation etcd

etcdIt is an open-source, distributed key value pair data storage system, which provides shared configuration, service registration and discovery. This paper mainly introduces the installation and use of etcd. Etcdetcd introduction etcdIt is an open source and highly available distributed key value storage system developed with go language, which can be used to configure sharing […]