/* 获取用户信息 */ wx.getSetting({ success: (res) => { // 如果用户已经授权 scope.userInfo 这个 scope if (res.authSetting['scope.userInfo']) { // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框 console.log("用户已授权") wx.getUserInfo({ success: (res) => { console.log("用户信息", res) } } }) } else { // 向用户发起授权请求 console.log('向用户发起授权请求 scope.userInfo') wx.authorize({ scope: 'scope.userInfo', success(suc) { console.log("用户已授权", suc }, fail(err) { console.log("无法授权", err) }, complete(c) { console.log("授权函数执行", c) } }) } } })
提示如下错误信息
errMsg: "authorize:fail 系统错误,错误码:-12007,scope unauthorized"
截图
此时,只能通过用户主动去点击授权按键才会调出授权页面,但是就做不到首次打开小程序主动调出授权页面的要求了
谢邀,必须用户主动触发授权,不能强制,即使你设置了强制,审核也不会通过