收藏
回答

当用户未绑定手机号码获取点击事件?

取消和确定这两个点击事件如何获取

代码

wx.request({

  url: app.domainHost + 'index/api/program',

  data: {

'encryptedData': e.detail.encryptedData,

'iv': e.detail.iv,

'session_key': res.data.session_key,

'openid': session_info.openid,

'unionid': session_info.unionid,

  },

  method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT

  header: {

'content-type': 'application/json'

  }, // 设置请求的 header

  success: function (res) {

console.log('写入手机号',res);

wx.hideLoading();//隐藏加载

if (res.statusCode == 200 && res.data == -41002) {

  console.log('未绑定手机号');

  wx.showModal({

title: '提示',

showCancel: true,

content: '未绑定手机号',

cancelText:'跳过',

success: function (res) {

  if (res.confirm) {

   //确定操作

  } else if (res.cancel) {

//取消操作

self.setData({

  auth_type: 0,

  isLogin: true

});

  }

}

  });

  return false




} else if (res.statusCode == 200 && res.data.phoneNumber) {

  //用户手机号写入缓存

  var user_phone = {};

  user_phone['phone'] = res.data.phoneNumber;

  user_phone['openid'] = session_info.openid;

  user_phone['unionid'] = session_info.unionid;

  wx.setStorageSync('user_phone', user_phone);


  //console.log('用户获取手机号' + res.data.phoneNumber);

  self.setData({

auth_type: 0,

isLogin: true

  });

  if (self.data.isShop == false) {

//未查询出店铺信息弹出跳转首页

wx.showModal({

  title: '提示',

  showCancel: false,

  content: '-' + self.data.errorMsg,

  success: function (res) {

wx.switchTab({

  url: '../index/index'

})

  }

});

return false

  }

}

  },

  fail: function (err) {

//console.log('用户取消授权手机号');

wx.showModal({

  title: '提示',

  content: '需要通过授权才能使用,请重新点击并授权!',

  showCancel: false,

  success: function (res) {

console.log('弹框后点取消')

  }

})

  }

})


最后一次编辑于  2019-11-19
回答关注问题邀请回答
收藏

2 个回答

  • 睡前原谅一切
    睡前原谅一切
    2019-11-20

    你这样:

    你用手机扫下开发者工具的预览码。使用手机号登录 会给你发送短信。验证成功后 你再在开发者工具调试 就好了。

    至于获取点击以及取消的方法:

    <button open-type="getPhoneNumber" bindgetphonenumber="getPhoneNumber">
    getPhoneNumber(e) {
     
    if (e.detail.errMsg === 'getPhoneNumber:ok') {
           //这里是点击的

        } else {

           //这里是取消的,取消这里还有多种判断。具体可查看errMsg的返回值  

       }

    }


    2019-11-20
    有用
    回复
  • 子不语
    子不语
    2019-11-19

    你要不上代码瞅瞅?

    2019-11-19
    有用
    回复 3
    • 召
      2019-11-19
      wx.request({
         url: app.domainHost + 'index/api/program',
         data: {
        'encryptedData': e.detail.encryptedData,
        'iv': e.detail.iv,
        'session_key': res.data.session_key,
        'openid': session_info.openid,
        'unionid': session_info.unionid,
         },
         method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
         header: {
        'content-type': 'application/json'
         }, // 设置请求的 header
         success: function (res) {
        console.log('写入手机号',res);
        wx.hideLoading();//隐藏加载
        if (res.statusCode == 200 && res.data == -41002) {
          console.log('未绑定手机号');
          wx.showModal({
         title: '提示',
         showCancel: true,
         content: '未绑定手机号',
         cancelText:'跳过',
         success: function (res) {
           if (res.confirm) {
            //确定操作
           } else if (res.cancel) {
          //取消操作
          self.setData({
            auth_type: 0,
            isLogin: true
          });
           }
         }
          });
          return false
        } else if (res.statusCode == 200 && res.data.phoneNumber) {
          //用户手机号写入缓存
          var user_phone = {};
          user_phone['phone'] = res.data.phoneNumber;
          user_phone['openid'] = session_info.openid;
          user_phone['unionid'] = session_info.unionid;
          wx.setStorageSync('user_phone', user_phone);
          //console.log('用户获取手机号' + res.data.phoneNumber);
          self.setData({
         auth_type: 0,
         isLogin: true
          });
          if (self.data.isShop == false) {
         //未查询出店铺信息弹出跳转首页
         wx.showModal({
           title: '提示',
           showCancel: false,
           content: '-' + self.data.errorMsg,
           success: function (res) {
          wx.switchTab({
            url: '../index/index'
          })
           }
         });
         return false
          }
        }
         },
         fail: function (err) {
        //console.log('用户取消授权手机号');
        wx.showModal({
          title: '提示',
          content: '需要通过授权才能使用,请重新点击并授权!',
          showCancel: false,
          success: function (res) {
         console.log('弹框后点取消')
          }
        })
         }
       })
      2019-11-19
      回复
    • 召
      2019-11-19
      你给看看
      2019-11-19
      回复
    • 召
      2019-11-19
      微信用户未绑定手机号时候,获取手机号会返回-41002,我已经添加判断了判断但是还是提示这个弹出框,现在的问题是这个弹出框怎么能获取到它的触发事件
      2019-11-19
      回复
登录 后发表内容
问题标签