


How to obtain mobile phone number information through the mini program
1. Before obtaining the mobile phone number, you must log in first.
Use wx.login to log in. If the login is successful, a code will be returned. The code will be passed to the background to obtain the login key session_key and other information. Store this information in data.
Recommended learning: Small program development
2. Use the button of type="getPhoneNumber" to obtain encryptedData, and iv pass these two information and session_key to In the background, the correct mobile phone number is returned through decryption.
<button open-type="getPhoneNumber" bindgetphonenumber="getPhoneNumber"> 手机号领取 </button>
The information obtained after clicking is
Before requesting the background interface, you must first use wx.checkSession to determine whether the login status has expired. If it expires, you need to obtain a new session_key.
getPhoneNumber(e) { var msg = e.detail.errMsg, that = this; var that = this; var sessionID=that.data.userinfo.Session_key, encryptedDataStr=e.detail.encryptedData, iv= e.detail.iv; if (msg == 'getPhoneNumber:ok') { wx.checkSession({ success:function(){ that.deciyption(sessionID,encryptedDataStr,iv); }, fail:function(){ wx.login({ success: res => { console.log(res,'sessionkey过期') wx.request('url',{code:res.code},function(res){ var userinfo=res.data.data; wx.setStorageSync('userinfo',userinfo); that.setData({ userinfo:userinfo }); that.deciyption(userinfo.Session_key,encryptedDataStr,iv); }) } }) } }) } }, deciyption(sessionID,encryptedDataStr,iv){ wx.request('url', { sessionID: sessionID, encryptedDataStr:encryptedDataStr, iv: iv }, function (res) { //这个res即可返回用户的手机号码 }) },
The above is the detailed content of How to obtain mobile phone number information in the mini program. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

WebStorm Mac version
Useful JavaScript development tools

Dreamweaver Mac version
Visual web development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function
