当前位置:网站首页>微信小程序获取用户收货地址列表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)
}
})
}
})
},
如果对你有帮助,不要吝啬你的点赞!谢谢
边栏推荐
- Literature retrieval operation code
- jdbctemplate connects to sql server, the data found in the code is inconsistent with the database, how to solve it?
- 【CNN】2022 ECCV 对比视觉Transformer的在线持续学习
- Shell编程之循环语句与函数
- 基于 JSch 实现服务的自定义监控解决方案
- 基于蓝牙定位功能开发的医院智能导航系统
- 零搜索量的关键词,你需要布局吗?
- [V&N2020 Open] Memory Forensics
- 【场景化解决方案】OA审批与用友U9数据集成
- 深度学习时代的视频理解综述
猜你喜欢

UE4 RTS 框选功能实现

js实现看板全屏功能

leetcode 37. 解数独 (困难)

Some of the topics in VNCTF2021 are reproduced

【redis】使用redis实现简单的分布式锁,秒杀并发场景可用

XCTF College War "Epidemic" Network Security Sharing Competition Misc wp

加密技术和电子竞技如何促进彼此的发展

Tencent cloud server is modified to root login to install pagoda panel

6000 字+,帮你搞懂互联网架构演变历程!

静态路由原理与配置
随机推荐
Three handshakes, four waves
Shell编程之循环语句与函数
GBJ610-ASEMI超薄整流扁桥GBJ610
Venture DAO 行业研报:宏观和经典案例分析、模式总结、未来建议
这下你知道为什么程序员要和产品干架了吧?
Tencent cloud server is modified to root login to install pagoda panel
VNCTF2021 部分题目复现
hdu2191 多重背包(2016xynu暑期集训检测 -----B题)
uva11624 Fire! (双bfs)
The principle and configuration of VLAN
DeFi 项目中的治理Token
数制之间的转换
【场景化解决方案】构建医疗通讯录,“慧医钉”助力医院实现数字化管理
Where does detection go forward?
Max Flow P
Programming a washing machine: garbled characters after string output
STM32 如何知道FLASH的使用情况
大端小端存储区别一看即懂
elder blind date
Routing configuration forwarding and experiment