1. 程式人生 > >微信獲取手機號授權登入

微信獲取手機號授權登入

1.

 <button bindgetphonenumber="getPhoneNumber" open-type="getPhoneNumber" class='button-hover'>確認授權</button>

2.

 getPhoneNumber: function (e) {
    console.log(e.detail.errMsg)
    console.log(e.detail.iv)
    console.log(e.detail.encryptedData)
    
    if (e.detail.errMsg !== 'getPhoneNumber:ok') {
      wx.showModal({
        title: '提示',
        showCancel:false,
        content: '未授權',
        success:function(res) {

        }
      })
    }else {
      wx.showModal({
        title: '提示',
        showCancel: false,
        content: '同意授權',
        success: function (res) { }
      })
    }

  },

3.下面兩張圖是一樣的

3.1真機版

3.2 開發工具版本