【微信小程序】如何获取用户绑定手机号
用户调用wx.login()方法,获取登录用户凭证code
wx.login({
success: function(res) {
console.log('loginCode', res.code)
}
});
code传给后台,凭证code获取session_key和openid
https://api.weixin.qq.com/sns/jscode2session?appid=APPID&secret=SECRET&js_code=JSCODE&grant_type=authorization_code
后台会获的用户的openid和session_key
[外链图片转存失败(img-rQSCUZCI-1563290280720)(https://upload-images.jianshu.io/upload_images/2481127-09ea7e9e1f7fecbb.png?imageMogr2/auto-orient/strip|imageView2/2/w/346/format/webp)]
getPhoneNumber组件
拿到encryptedData和iv
<button open-type="getPhoneNumber" bindgetphonenumber="getPhoneNumber"></button>
Page({
getPhoneNumber: function(e) {
console.log(e.detail.errMsg)
console.log(e.detail.iv)
console.log(e.detail.encryptedData)
}
})
将encryptedData和iv传给后台
[外链图片转存失败(img-XB74dpNR-1563290280723)(https://upload-images.jianshu.io/upload_images/2481127-b2d4800dcac8925b.png?imageMogr2/auto-orient/strip|imageView2/2/w/703/format/webp)]
请点赞!因为你们的赞同/鼓励是我写作的最大动力!
欢迎关注达叔小生的简书!
这是一个有质量,有态度的博客
[外链图片转存失败(img-ACAtKBpw-1563290280725)(https://upload-images.jianshu.io/upload_images/11158618-9ab0d3fef85d80ce?imageMogr2/auto-orient/strip|imageView2/2/w/1240)]
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 3.0 许可协议。转载请注明出处!