zoukankan      html  css  js  c++  java
  • 微信小程序授权

       <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)
                }
              })
            }
          }
        })
      },
  • 相关阅读:
    POJ 1475 推箱
    POJ 2253 Frogger
    POJ 1970 The Game
    POJ 1979 Red and Black
    HDU 1546 Idiomatic Phrases Game 求助!help!!!
    Fibonacci 1
    BZOJ 1041
    椭圆曲线质因数分解
    奇怪的高精度
    数论v2
  • 原文地址:https://www.cnblogs.com/xhrr/p/12722045.html
Copyright © 2011-2022 走看看