微信小程序设置用户收货地址

1. 获取用户收货地址需要用户点击授权,所以有两种情况,确认授权、取消授权。

情况一,用户第一次访问用户地址授权,并且点击确定授权
在这里插入图片描述
情况二,用户点击取消授权后,再次获取授权
在这里插入图片描述

流程: (代码逻辑整理)

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)
  }
  })
  }
 }
 }
 })
},
  • 2
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

star@星空

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值