微信獲取用戶收貨地址,用戶點擊拒絕之後再次調起

前幾天做一個獲取微信用戶收貨地址,卡卡一頓懟,做官網上面找到了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
            //   })
            // }
          }
        })
      }
    })
  },
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章