鍍金池/ 問(wèn)答/HTML/ 小程序 獲取手機(jī)號(hào)碼 ,出現(xiàn)這個(gè)提示, 是要接短信接口嗎

小程序 獲取手機(jī)號(hào)碼 ,出現(xiàn)這個(gè)提示, 是要接短信接口嗎

clipboard.png

回答
編輯回答
我以為

你檢查下你調(diào)用時(shí)用戶登錄狀態(tài),如果刷新了沒(méi)有使用加密時(shí)的sessionKey會(huì)導(dǎo)致調(diào)用失敗,你是否判定了第三方的調(diào)用會(huì)回調(diào)參數(shù),默認(rèn)的獲取手機(jī)號(hào)是不用驗(yàn)證碼的
參考:
獲取手機(jī)號(hào)

wxml

<button wx:if="{{canIUse}}" open-type="getUserInfo" bindgetuserinfo="bindGetUserInfo">授權(quán)登錄</button>
<button open-type="getPhoneNumber" bindgetphonenumber="getPhoneNumber">獲取手機(jī) </button>

js

Page({

  /**
   * 頁(yè)面的初始數(shù)據(jù)
   */
  data: {
    canIUse: wx.canIUse('button.open-type.getUserInfo')
  },

  /**
   * 生命周期函數(shù)--監(jiān)聽(tīng)頁(yè)面加載
   */
  onLoad: function (options) {
    var that = this;
    // 查看是否授權(quán)
    wx.getSetting({
      success: function (res) {
        if (res.authSetting['scope.userInfo']) {
          // 已經(jīng)授權(quán),可以直接調(diào)用 getUserInfo 獲取頭像昵稱(chēng)
          wx.getUserInfo({
            success: function (res) {
              //獲取用戶敏感數(shù)據(jù)密文和偏移向量
              if (res.userInfo) {
                //數(shù)據(jù)庫(kù)存儲(chǔ)用戶首次基本信息
                wx.request({
                  url: 'https:/xxxx',
                  data: {
                    userid: wx.getStorageSync('userid'),
                    avatarUrl: res.userInfo.avatarUrl,
                    city: res.userInfo.city,
                    country: res.userInfo.country,
                    gender: res.userInfo.gender,
                    nickName: res.userInfo.nickName,
                    province: res.userInfo.province
                  },
                  header: {
                    'content-type': 'application/x-www-form-urlencoded'
                  },
                  method: 'POST',
                  success: function (res) {
                    //console.log(res);
                    wx.showToast({
                      title: '登錄成功',
                    })
                  }
                })
              }
            }
          })
        }
      }
    })
  },

  /**
   * 生命周期函數(shù)--監(jiān)聽(tīng)頁(yè)面初次渲染完成
   */
  onReady: function () {
  
  },

  getPhoneNumber: function (e) {
    console.log(e.detail.errMsg)
    console.log(e.detail.iv)
    console.log(e.detail.encryptedData)
  },
}

效果圖

圖片描述
圖片描述

我順序點(diǎn)擊登錄與收獲手機(jī)

2017年9月6日 11:46
編輯回答
怣人

如果你的手機(jī)號(hào)在任何小程序沒(méi)有授權(quán)過(guò)(任何小程序)它第一次會(huì)來(lái)短信,只要授權(quán)過(guò)就不會(huì)來(lái)短信了

2017年10月12日 20:19