微信小程序獲取用戶收貨地址的方法

這篇文章給大家分享的是有關(guān)微信小程序獲取用戶收貨地址的方法的內(nèi)容。小編覺得挺實(shí)用的,因此分享給大家做個(gè)參考,一起跟隨小編過來看看吧。

網(wǎng)站建設(shè)哪家好,找創(chuàng)新互聯(lián)!專注于網(wǎng)頁設(shè)計(jì)、網(wǎng)站建設(shè)、微信開發(fā)、重慶小程序開發(fā)、集團(tuán)企業(yè)網(wǎng)站建設(shè)等服務(wù)項(xiàng)目。為回饋新老客戶創(chuàng)新互聯(lián)還提供了榆陽免費(fèi)建站歡迎大家使用!

獲取用戶收貨地址需要用戶點(diǎn)擊授權(quán),所以有兩種情況,確認(rèn)授權(quán)、取消授權(quán)。

情況一,用戶第一次訪問用戶地址授權(quán),并且點(diǎn)擊確定授權(quán)。

微信小程序獲取用戶收貨地址的方法微信小程序獲取用戶收貨地址的方法

情況二,用戶點(diǎn)擊取消授權(quán)后,再次獲取授權(quán)

微信小程序獲取用戶收貨地址的方法微信小程序獲取用戶收貨地址的方法微信小程序獲取用戶收貨地址的方法

流程:(代碼邏輯整理)

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

2.根據(jù)用戶當(dāng)前設(shè)置中的用戶授權(quán)結(jié)果,判斷是否包含收貨地址授權(quán)

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

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

4.1:用戶當(dāng)前設(shè)置包含收貨地址授權(quán)但是用戶點(diǎn)擊取消授權(quán),調(diào)用wx.openSetting(),調(diào)起客戶端小程序設(shè)置界面讓用戶去打開授權(quán)

4.2:用戶當(dāng)前設(shè)置不包含收貨地址授權(quán)(說明是第一次打開獲取用戶收貨地址信息的授權(quán)),調(diào)用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ù)調(diào)用 wx.startRecord 接口不會(huì)彈窗詢問
  
 } 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)
  }
  })
  }
 }
 }
 })
},

感謝各位的閱讀!關(guān)于“微信小程序獲取用戶收貨地址的方法”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,讓大家可以學(xué)到更多知識(shí),如果覺得文章不錯(cuò),可以把它分享出去讓更多的人看到吧!

文章名稱:微信小程序獲取用戶收貨地址的方法
當(dāng)前網(wǎng)址:http://www.muchs.cn/article30/ijsiso.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供靜態(tài)網(wǎng)站、App開發(fā)關(guān)鍵詞優(yōu)化、響應(yīng)式網(wǎng)站網(wǎng)站建設(shè)、網(wǎng)站排名

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

成都定制網(wǎng)站建設(shè)