1. 程式人生 > >微信小程式:授權問題(scope.userInfo【廢棄】)

微信小程式:授權問題(scope.userInfo【廢棄】)

今天發現微信廢棄了授權API:’scope.userInfo’

wx.getSetting({
    success(res) {
        if (!res.authSetting['scope.userInfo']) {
            wx.authorize({
                scope: 'scope.userInfo',
                success() {
                    wx.getUserInfo()
                }
            })
        }
    }
})

如上程式碼已經不能實現授權提示,以及獲取使用者資訊,正式版本小程式,或是之前使用者已授權過暫不受影響,但是不保證以後不會被影響,所以還是聽微信的話,一個字:改 !

<button  open-type="getUserInfo" bindgetuserinfo="getUserInfo">授權</button>

為了獲取使用者資訊,我們需要些這樣一段程式碼,來調取授權提示,使用者允許授權你可以通過 getUserInfo 方法拿到使用者資訊,如果使用者拒絕你點選該按鈕還可以調取授權提示。

以上是本人自學小程式以來的一些總結,如存在問題請提出評論,或者可以檢視

我的簡書