收藏
回答

wx.authorize拒绝授权后->依然可以成功调用getUserInfo ?

如题,想兼容用户拒绝授权的情况,测试部分需要授权接口时,遇到的问题。


JS 代码 :

//app.js
App({
    onLaunch: function () {
        wx.authorize({
            scope: 'scope.userInfo',
            success(res) {
                console.log('success => ', res.errMsg)
            },
            fail(res) {
                console.log('fail => ', res.errMsg)
                wx.getUserInfo({
                    withCredentials: true,
                    success(res) {
                        console.log('userinfo => ', res)
                    },
                    fail(res) {
                        console.log(res.errMsg)
                    }
                })
            }
        })
    }
})


开发者工具中,清除授权后,重新编译代码;

模拟器弹出,微信授权,申请获取用户公开信息对话框,如下图:


点击拒绝后,控制台输出结果:

实际结果和文档中wx.authorize的描述好像不太一样,很是疑惑。


回答关注问题邀请回答
收藏
登录 后发表内容