當前位置:編程學習大全網 - 源碼下載 - 微信小程序如何獲取用戶收貨地址

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

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

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

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

流程: (代碼邏輯整理)

1.點擊事件觸發函數,獲取用戶當前設置

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

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)

}

})

// 用戶已經同意小程序使用錄音功能,後續調用 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)

}

})

}

}

}

})

},

  • 上一篇:C++、C、或者java,這些語言寫代碼時應該要怎麽規範格式,
  • 下一篇:電腦wifi的ip地址怎麽設置
  • copyright 2024編程學習大全網