https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/getPhoneNumber.html
根据官方文档,调用getPhoneNumber后,没有返回code字段(使用的基础库为:2.21.3)
获取手机号,没有返回code字段Get the phone number without returning the code field
获取手机号,没有返回code字段https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/getPhoneNumber.html
根据官方文档,调用getPhoneNumber后,没有返回code字段(使用的基础库为:2.21.3)
https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/getPhoneNumber.html According to the official document, after calling getphonenumber, no code field is returned (the basic library used is 2.21.3)
回答:
wxml:<button open-type="getPhoneNumber" bindgetphonenumber="getPhoneNumber">获取手机号</button>js:getPhoneNumber: function (e) {//点击获取手机号码按钮 var that = this; let sessionk = wx.getStorageSync('sessionkey'); let uid = wx.getStorageSync('uid'); wx.checkSession({ success: function () { var ency = e.detail.encryptedData; var iv = e.detail.iv; if (e.detail.errMsg == 'getPhoneNumber:fail user deny') { wx.showToast({ title: '您拒绝了授权', icon:'none', }) } else {//同意授权 wx.request({ method: "GET", url: app.globalData.url + 'outine/login/getPhone', data: { encrypdata: ency, ivdata: iv, sessionkey: sessionk, uid:uid },success: (res) => { wx.navigateTo({ url: '/pages/webview/index' }) }, fail: function (res) { console.log("解密失败~",res); } }); }},fail: function () { console.log("session_key 已经失效,需要重新执行登录流程"); wx.showToast({ title: '您拒绝了~', icon:'none', }) } }); },
① 确认当前基础库版本是否为 2.21.2 及以上。
② 目前开发者工具稳定版未兼容此表现(近期应该会同步)。
③ 正常情况下,基础库 2.21.2
对应的是客户端版本号为 8.0.16
,如果你的版本低于 8.0.16
并且是通过开发者工具向客户端推送的 2.21.2
基础库,大几率不会返回 code
参数,请手动更新微信版本。
目前请先用 开发版 或者 真机 进行调试。
原文出处:获取手机号,没有返回code字段
真机调试一下