情況壹,用戶第壹次訪問用戶地址授權,並且點擊確定授權。
情況二,用戶點擊取消授權後,再次獲取授權
流程: (代碼邏輯整理)
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)
}
})
}
}
}
})
},