你检查下你调用时用户登录状态,如果刷新了没有使用加密时的sessionKey会导致调用失败,你是否判定了第三方的调用会回调参数,默认的获取手机号是不用验证码的参考:获取手机号 wxml <button wx:if="{{canIUse}}" open-type="getUserInfo" bindgetuserinfo="bindGetUserInfo">授权登录</button> <button open-type="getPhoneNumber" bindgetphonenumber="getPhoneNumber">获取手机 </button> js Page({ /** * 页面的初始数据 */ data: { canIUse: wx.canIUse('button.open-type.getUserInfo') }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { var that = this; // 查看是否授权 wx.getSetting({ success: function (res) { if (res.authSetting['scope.userInfo']) { // 已经授权,可以直接调用 getUserInfo 获取头像昵称 wx.getUserInfo({ success: function (res) { //获取用户敏感数据密文和偏移向量 if (res.userInfo) { //数据库存储用户首次基本信息 wx.request({ url: 'https:/xxxx', data: { userid: wx.getStorageSync('userid'), avatarUrl: res.userInfo.avatarUrl, city: res.userInfo.city, country: res.userInfo.country, gender: res.userInfo.gender, nickName: res.userInfo.nickName, province: res.userInfo.province }, header: { 'content-type': 'application/x-www-form-urlencoded' }, method: 'POST', success: function (res) { //console.log(res); wx.showToast({ title: '登录成功', }) } }) } } }) } } }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, getPhoneNumber: function (e) { console.log(e.detail.errMsg) console.log(e.detail.iv) console.log(e.detail.encryptedData) }, } 效果图 我顺序点击登录与收获手机
你检查下你调用时用户登录状态,如果刷新了没有使用加密时的sessionKey会导致调用失败,你是否判定了第三方的调用会回调参数,默认的获取手机号是不用验证码的
参考:
获取手机号
wxml
js
效果图
我顺序点击登录与收获手机