微信获取用户收货地址,用户点击拒绝之后再次调起

前几天做一个获取微信用户收货地址,卡卡一顿怼,做官网上面找到了api直接获取就可以了。然后测试也没有测出什么问题了。一审核,过了发布上线,但是这时候就出现问题了。一直报授权失败

因为用户第一次进来的时候就点击了拒绝。所以第二次就不会再弹窗。所以这时候需要做一个button再次调起

// An highlighted block
 <block wx:if='{{isopenAddress==false}}'>
      <span class="address" bindtap='bindRegionChange'>{{addressInfo?addressInfo:"常住地"}}</span>
    </block> 
    <block wx:if='{{isopenAddress==true}}'>
      <button class="address1" plain='true' bind:tap="bindRegionChange" bindopensetting="bindRegionChange"> {{addressInfo?addressInfo:"常住地"}}</button> 
    </block> 
bindRegionChange(e) {
    var that = this;
    console.log(e);

    //获取到用户的收货地址
    wx.openSetting({
      success(res) {
        console.log(res.authSetting)
        // res.authSetting = {
        //   "scope.userInfo": true,
        //   "scope.userLocation": true
        // }
        //获取到用户的收货地址
        wx.chooseAddress({
          success: function (res) {
            console.log(res);
            var addressInfo = res.provinceName + res.cityName + res.countyName;
            console.log(addressInfo);
            that.setData({
              "addressInfo": addressInfo,
              "provinceName": res.provinceName,
              "cityName": res.cityName,
              "countyName": res.countyName
            })
            wx.request({
              url: app.globalData.linkStr + '/HappyHui/filter/queryAreaById.do',
              // url: 'http://192.168.1.111:8080/HappyHui/filter/queryAreaById.do',
              method: 'POST',
              header: {
                'content-type': 'application/json;charset=utf-8'
              },
              data: {
                provinceName: res.provinceName,
                cityName: res.cityName,
                countyName: res.countyName
              },
              success: function (res) {
                console.log(res.data.data);
                that.data.orderData["province_id"] = res.data.data.province_id;
                that.data.orderData["city_id"] = res.data.data.city_id;
                that.data.orderData["region_id"] = res.data.data.region_id;
              }
            })
          },
          fail: function (err) {
            console.log(JSON.stringify(err));
            console.info("收货地址授权失败");
            that.setData({
              isopenAddress: true
            })
            // if (that.data.addressInfo == '') {
            //   wx.showToast({
            //     title: '授权失败',
            //     icon: 'success',
            //     duration: 2000
            //   })
            // }
          }
        })
      }
    })
  },
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章