标签:user tar inf ati 调用 vat authorize json style
<button open-type="getUserInfo" bindgetuserinfo="getAuthorization"> 授权 </button> // 授权 getAuthorization(){ let that = this let code = wx.login() // 查看是否授权 wx.getSetting({ success: function (res) { console.log(res) if (res.authSetting[‘scope.userInfo‘]) { console.log(res.authSetting[‘scope.userInfo‘]) // 已经授权,可以直接调用 getUserInfo 获取头像昵称 wx.getUserInfo({ success: function (res) { let userInfo = JSON.parse(res.rawData) that.setData({ username: userInfo.nickName, userImg: userInfo.avatarUrl }) } }) }else { console.log("未授权=====") wx.authorize({ scope: ‘scope.userInfo‘, success(res) { // 已经授权,可以直接调用 getUserInfo 获取头像昵称 wx.getUserInfo({ success: function (res) { let userInfo = JSON.parse(res.rawData) that.setData({ username: userInfo.nickName, userImg: userInfo.avatarUrl }) } }) }, fail(res){ console.log(res) } }) } } }) },
标签:user tar inf ati 调用 vat authorize json style
原文地址:https://www.cnblogs.com/xhrr/p/12722045.html