欧美三级国产三级日韩三级_亚洲熟妇丰满大屁股熟妇_欧美亚洲成人一区二区三区_国产精品久久久久久模特

微信小程序—微信信息授權(quán)登錄以及手機(jī)號(hào)授權(quán)登錄 - 新聞資訊 - 云南小程序開發(fā)|云南軟件開發(fā)|云南網(wǎng)站建設(shè)-昆明葵宇信息科技有限公司

159-8711-8523

云南網(wǎng)建設(shè)/小程序開發(fā)/軟件開發(fā)

知識(shí)

不管是網(wǎng)站,軟件還是小程序,都要直接或間接能為您產(chǎn)生價(jià)值,我們?cè)谧非笃湟曈X表現(xiàn)的同時(shí),更側(cè)重于功能的便捷,營銷的便利,運(yùn)營的高效,讓網(wǎng)站成為營銷工具,讓軟件能切實(shí)提升企業(yè)內(nèi)部管理水平和效率。優(yōu)秀的程序?yàn)楹笃谏?jí)提供便捷的支持!

您當(dāng)前位置>首頁 » 新聞資訊 » 小程序相關(guān) >

微信小程序—微信信息授權(quán)登錄以及手機(jī)號(hào)授權(quán)登錄

發(fā)表時(shí)間:2021-1-5

發(fā)布人:葵宇科技

瀏覽次數(shù):61

圖片演示

wxml(login.wxml)代碼

 <view class="">
    <button class="logoBtn" wx:if='{{hiddenBtn == 0}}' open-type="getUserInfo"  bindgetuserinfo="bindGetUserInfo">微信賬號(hào)快捷登錄</button>
    <!-- <button class="logoBtn" wx:if='{{hiddenBtn == 1}}' open-type="getUserInfo"  bindgetuserinfo="bindGetUserInfo">微信賬號(hào)快捷登錄</button> -->
    <button class="logoBtn" wx:if='{{hiddenBtn == 2}}' open-type="getPhoneNumber"
      bindgetphonenumber="getPhoneNumber">綁定微信手機(jī)號(hào)</button>
  </view>

js(login.js)代碼


  data: {
    openid: '',
    session_key: '',
    showModal: false,//彈出框顯示
    hiddenBtn: 0,//微信授權(quán)登錄顯示
  },
   /**
   * 獲取微信用戶的相關(guān)信息
   */
  onLogin() {
    var that = this
    var openid = that.data.openid
    var avatar = that.data.avatarUrl
    var nickname = that.data.nickName
    var address = that.data.address
    var sex = that.data.sex
    // console.log('ccccccccccccc',avatarUrl,nickName,that.data.fid)
    // 給后臺(tái)傳信息
    wx.request({
      url: app.globalData.urlSrc + '...',
      method: 'POST',
      data: {
        open_id: openid,
        avatar: avatar,
        address:address,
        nickname: nickname,
        sex:sex,
      },
      header: {
        'content-type': app.globalData.head
      },
      success: function (v) {
        console.log('微信授權(quán)后給后臺(tái)傳相關(guān)信息', v)
        var code = v.data.code
        if (code == 1) {
          that.setData({
            showModal: false,
            hiddenBtn: 2
          })
          wx.showToast({
            title: '請(qǐng)繼續(xù)點(diǎn)擊綁定手機(jī)號(hào)!',
            icon: 'none'
          })
         
          // wx.setStorage({
          //   key: "shibie",
          //   data: app.globalData.shibie
          // })              
        }
      },
    })
  },
  
  /**
   * 點(diǎn)擊綁定微信手機(jī)號(hào)
   */
  getPhoneNumber: function (event) {
    var that = this;
    wx.checkSession({
      success: (res) => {
        console.log('nnnnnnnn', res)
        wx.login({
          success: function (res) {
            console.log('is_code:', res.code)
            if (res.code) {
              //獲取openid
              wx.request({
                url: app.globalData.urlSrc + '....',
                method: 'GET',
                data: {
                  code: res.code
                },
                header: {
                  'content-type': app.globalData.head
                },
                success: function (e) {
                  console.log('獲取session_key:', e.data)
                  var session_key = e.data.data.session_key
                  var ivObj = event.detail.iv
                  var telObj = event.detail.encryptedData
                  wx.request({
                    url: app.globalData.urlSrc + '...',
                    method: 'POST',
                    data: {
                      session_key: session_key,
                      encryptedData: telObj,
                      iv: ivObj,
                    },
                    header: {
                      'content-type': app.globalData.head
                    },
                    success: function (res) {
                      // phoneObj = res.data.phoneNumber;
                      console.log("手機(jī)號(hào)=", res.data)
                      var code = res.data.code
                      if (code == 1) {
                        var phone = res.data.mobile
                        var openid = that.data.openid
                        // 傳手機(jī)號(hào)給后臺(tái)
                        wx.request({
                          url: app.globalData.urlSrc + '....',
                          method:'POST',
                          data: {
                            open_id:openid,
                            phone:phone
                          },
                          header: {
                            'content-type': app.globalData.head
                          },
                          success: function (v) {
                            // phoneObj = res.data.phoneNumber;
                            console.log("傳手機(jī)號(hào)給后臺(tái)", v.data)
                            var code = v.data.code
                            if (code == 1) {
                              app.globalData.userId = v.data.data.user_id
                              wx.setStorage({
                                key: "userId",
                                data: app.globalData.userId
                              })
                              wx.reLaunch({
                                url: '../community/community',
                              })
                            }
                            // else{
                            //   wx.showToast({
                            //     title: '手機(jī)號(hào)獲取失敗,請(qǐng)重新獲??!',
                            //     icon:'none'
                            //   })
                            // }
                          }
                        })
                      } else {
                        wx.showToast({
                          title: '手機(jī)號(hào)獲取失敗,請(qǐng)重新獲?。?,
                          icon: 'none'
                        })
                      }
                    }
                  })
                }
              })
            }
          }
        })
      },
      fail(err) {
        console.log('gggggggggg', err)
        that.getSession()
      }
    })
  },
   /**
   * 點(diǎn)擊微信賬號(hào)快捷登錄按鈕后
   * 
   */
  bindGetUserInfo: function (e) {
    var that = this
    console.log('dddd', that.data.openid)
    // console.log('vvvvvvvv', that.data.tag)

    // if (that.data.openid != '') {}
    if (e.detail.userInfo) {
      //用戶按了允許授權(quán)按鈕
      var that = this;  
      console.log("用戶的信息如下:", e.detail.userInfo);
      this.setData({
        avatarUrl: e.detail.userInfo.avatarUrl,
        nickName: e.detail.userInfo.nickName,
        sex: e.detail.userInfo.gender,
        address: e.detail.userInfo.country +',' +e.detail.userInfo.province+ ',' +e.detail.userInfo.city,
        showModal: false,
      })
      that.onLogin()
    } else {
      //用戶按了拒絕按鈕
      console.log('用戶點(diǎn)擊了“返回授權(quán)”');
      wx.showModal({
        title: '警告',
        content: '您點(diǎn)擊了拒絕授權(quán),將無法進(jìn)入小程序,請(qǐng)授權(quán)之后再進(jìn)入!!!',
        showCancel: false,
        confirmText: '返回授權(quán)',
        success: function (res) {
          if (res.confirm) {
            console.log('用戶點(diǎn)擊了“返回授權(quán)”');
            wx.showToast({
              title: '您已經(jīng)取消了授權(quán)!',
              icon: 'none'
            })
          }
        }
      });
    }
  },

相關(guān)案例查看更多