当前位置:网站首页>微信小程序获取用户收货地址列表wx.chooseAddress
微信小程序获取用户收货地址列表wx.chooseAddress
2022-08-09 08:54:00 【Your-Nikee】

微信官方的说明,直接调用即可,但是由于该微信弹框如果拒绝,之后再不会弹出提示,而恰好wx.openSetting(),可以调起授权设置界面,显示用户已经调用过的微信授权,所以我们需要饶一下小弯路,但是也能做到用户拒绝授权后每次点击都能弹窗提示授权的功能。
两条路:
1、用户首次授权调用==》同意授权==》获取到用户地址列表信息
2、用户首次授权调用==》拒绝授权==》wx.showModal()的方式提示用户是否授权==》同意即调用wx.openSetting()(拒绝即隐藏弹窗)==》打开设置,打开/返回取消 ==》如同意即获取到用户地址列表
注:wx.openSetting必须以按钮或showModal的形式才能调用
用户成功授权后得到的参数说明:

具体代码:
**复制即可使用,需要一个按钮绑定chooseAddress事件
chooseAddress(){
wx.chooseAddress({
//首次调用
//同意授权
success:res=>{
console.log(res)//地址列表信息
},fail:err=>{
wx.getSetting({
success: res => {
if (res.authSetting['scope.address'] == false) {
wx.showModal({
//弹出框
title: '我爱我家申请获取你的通讯地址?',
content: '',
confirmColor:'#48A63E',
cancelText:'拒绝',
confirmText:'允许',
success:res=>{
if (res.cancel){
//再次拒绝
}else{
wx.openSetting({
success: res => {
wx.chooseAddress({
success: res => {
//opensetting后同意
console.log(res)
}, fail: err => {
console.log(err)
}
})
}, fail: err => {
wx.showToast({
title: '取消收货地址授权',
icon: 'none'
})
}
})
}
},fail:err=>{
}
})
}
}, fail: err => {
console.log(err)
}
})
}
})
},
如果对你有帮助,不要吝啬你的点赞!谢谢
边栏推荐
猜你喜欢
随机推荐
VLAN的原理及配置
Calendar类和Date类转换时区 && 部分时区城市列表
管理方向发展
The embedded serial port interrupt can only receive one byte
requests之模拟登录学习
gin中改进版curd接口例子
Makefile中patsubst、wildcard、notdir的使用
ctf misc 图片题知识点
Venture DAO 行业研报:宏观和经典案例分析、模式总结、未来建议
数制之间的转换
LAN Technology - 6MSTP
【场景化解决方案】ERP系统与钉钉实现数据互通
腾讯云服务器修改为root登录安装宝塔面板
Xpath之爬取全国城市名称学习
BUUCTF MISC brush notes (2)
hdu2191 多重背包(2016xynu暑期集训检测 -----B题)
SAE定时备份博客数据库
BUUCTF MISC刷题笔记(二)
Getting started with ctfshow-web Part of the file upload part solution
The working principle of switch









