# Mobile phone number rapid verification component
This capability is designed to help developers initiate a mobile phone number application from users, and must be approved by users before developers can obtain a mobile number verified by the platform to provide services to users.
The following is a guide to using older components. Note that when using older components, you need to call the wx.login interface.Developers are advised to use the new version of the component to enhance Weixin Mini Program security.Details New Component Usage Guide .
Because the user is actively triggered to initiate the mobile phone number rapid verification, this function is not called by the API and is triggered by the click of the button component.
Be careful
- 1. At present, the interface is for non-individual developers, and has completed the certification of Weixin Mini Program open (excluding overseas entities). Use with caution, if the user reports more or is found to be used in unnecessary scenarios, WeChat has the right to permanently recover the interface permissions of the Mini Program.
- 2. When this capability is used, users can choose to bind a number or add a number on their own. The platform will verify the number, but it does not guarantee real-time verification;
- 3. Developers are asked to determine whether to use it based on business scenarios, and consider adding additional security verification when necessary.
# How to use it
Need to set the value of the button componentopen-typetogetPhoneNumber,When the user clicks and agrees, the encrypted data returned by thebindgetphonenumberevent callback can be obtained from the WeChat server.Then combinesession_keyandapp_idon the third-party service to decrypt the phone number.
# Note
Calling wx.login login in a callback may refresh the login state.At this point, the server uses code for a session key that is not the session key used in encryption, resulting in a decryption failure.login;Or usecheckSession]]to check the login state first in the callback to avoidlogin]]to refresh the login state.
# Code examples
<button open-type="getPhoneNumber" bindgetphonenumber="getPhoneNumber"></button>
Page({
getPhoneNumber (e) {
console.log(e.detail.errMsg)
console.log(e.detail.iv)
console.log(e.detail.encryptedData)
}
})
# Return parameter explaination
| parameter | type | Introductions | Minimum version |
|---|---|---|---|
| encryptedData | String | Including sensitive data, including complete user information encrypted data, see encrypted data decryption algorithm | |
| iv | String | The initial vector of the encryption algorithm, see encryption data decryption algorithm | |
| cloudID | string | The cloud ID corresponding to the sensitive data is returned only if Weixin Mini Program is enabled for cloud development. Open data can be directly obtained through cloud calls, see for more details | Base library {% version (2.8.0)%} |
The resulting open data is the following JSON structure:
{
"phoneNumber": "13580006666",
"purePhoneNumber": "13580006666",
"countryCode": "86",
"watermark":
{
"appid":"APPID",
"timestamp": TIMESTAMP
}
}
| parameter | type | Introductions |
|---|---|---|
| phoneNumber | String | The user's bound mobile phone number (there are regional codes for mobile phone numbers abroad) |
| purePhoneNumber | String | Mobile phone numbers that do not have a region code |
| countryCode | String | area code |