According to the latest notice

In order to optimize user experience, the platform will make the following adjustments: 1. 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 unionID 2, the new version of the small program issued 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. 3. Add 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. GetUserProfile interface document ———————————————— Copyright: Xun-Ming, CSDN, CC 4.0 BY-SA. The original link: blog.csdn.net/diyangxia/a…

Old getUserInfo now has a default name of “wechat user” and a dummy image.

Before is

<button open-type="getUserInfo" @getUserinfo ="wxGetUserInfo" withCredentials="true"> </button>Copy the code

To get the avatar name and iv, encryptedData information needed to log in,

Now it’s just plain old:

<button @click="getInfo">Copy the code

Methods the internal

getInfo(){ let self = this; Uni. getUserProfile({desc:" Get your name, avatar, locale and name ", success: If (res.errmsg === 'getUserProfile:ok') {self.iv = res.iv; self.encryptedData = res.encryptedData; self.wxLogin(); }}, fail (err) =>{console.log(" you cancel authorization, login failed ")})}, wxLogin() {// wechat login uni. Login({provider: 'weixin', success: function(loginRes) { let weixinCode = loginRes.code; Self. LoginWeChat (weixinCode)// Necessary to pass the parameter to the back end}}); },Copy the code

If you want to get a phone:

<button open-type="getPhoneNumber" @getphonenumber="getPhoneNumber"> </button> getPhoneNumber(res) {self.iv = res.detail.iv; self.encryptedData = res.detail.encryptedData; wx.checkSession({ complete() { uni.login({ provider: 'weixin', success: function(loginRes) { let weixinCode = loginRes.code; self.getPhoneNumberAfter(weixinCode) } }); }})},Copy the code