欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

微信小程序如何獲取用戶收貨地址

 更新時間:2018年11月27日 17:20:10   作者:a_靖  
這篇文章主要為大家詳細介紹了微信小程序獲取用戶收貨地址的方法,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

獲取用戶收貨地址需要用戶點擊授權,所以有兩種情況,確認授權、取消授權。

情況一,用戶第一次訪問用戶地址授權,并且點擊確定授權。

情況二,用戶點擊取消授權后,再次獲取授權

流程: (代碼邏輯整理)

1.點擊事件觸發(fā)函數(shù),獲取用戶當前設置

2.根據(jù)用戶當前設置中的用戶授權結果,判斷是否包含收貨地址授權

3.如果包含收貨地址授權并且沒有取消過收貨地址授權,直接調用wx.chooseAddress(),獲取用戶收貨地址。

4.取消過收貨地址授權,調用wx.openSetting(),調起客戶端小程序設置界面讓用戶去打開授權

4.1:用戶當前設置包含收貨地址授權但是用戶點擊取消授權,調用wx.openSetting(),調起客戶端小程序設置界面讓用戶去打開授權

4.2:用戶當前設置不包含收貨地址授權(說明是第一次打開獲取用戶收貨地址信息的授權),調用wx.chooseAddress(),獲取用戶收貨地址。

完整代碼:

<button bindtap='aaaaaaa'>獲取地址</button>
 aaaaaaa() {
 wx.getSetting({
 success(res) {
 console.log("vres.authSetting['scope.address']:",res.authSetting['scope.address'])
 if (res.authSetting['scope.address']) {
  console.log("111")
  wx.chooseAddress({
  success(res) {
  console.log(res.userName)
  console.log(res.postalCode)
  console.log(res.provinceName)
  console.log(res.cityName)
  console.log(res.countyName)
  console.log(res.detailInfo)
  console.log(res.nationalCode)
  console.log(res.telNumber)
  }
  })
  // 用戶已經(jīng)同意小程序使用錄音功能,后續(xù)調用 wx.startRecord 接口不會彈窗詢問
  
 } else {
  if (res.authSetting['scope.address'] == false) {
  console.log("222")
  wx.openSetting({
  success(res) {
  console.log(res.authSetting)
  
  }
  })
  } else {
  console.log("eee")
  wx.chooseAddress({
  success(res) {
  console.log(res.userName)
  console.log(res.postalCode)
  console.log(res.provinceName)
  console.log(res.cityName)
  console.log(res.countyName)
  console.log(res.detailInfo)
  console.log(res.nationalCode)
  console.log(res.telNumber)
  }
  })
  }
 }
 }
 })
},

為大家推薦現(xiàn)在關注度比較高的微信小程序教程一篇:《微信小程序開發(fā)教程》小編為大家精心整理的,希望喜歡。

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

最新評論