Supported on iOS >= 0.7.13 and Android >= 0.7.5.
By specifying the open-type attribute of the button component as phoneOneClickLogin, you can obtain a temporary login credential (code), which can then be exchanged for user identification information.
Prerequisites
-
Enable the Identity Management feature and check "One-click Login with Local Phone Number" in "WeChat Developer Platform - Multi-End Apps - Identity Management" via https://developers.weixin.qq.com/platform/.
-
Successfully invoke wx.getPhoneMask as described in the development documentation. (Note: One-click Login with Local Phone Number consumes the context information obtained from wx.getPhoneMask, rendering that context information invalid. If the developer needs to invoke One-click Login with Local Phone Number again, they must re-invoke wx.getPhoneMask.)
button component parameters
| Attribute | Type | Default Value | Required | Description |
|---|---|---|---|---|
| open-type | string | Yes | phoneOneClickLogin initiates the one-click login process | |
| bindphoneoneclicklogin | Function | No | One-click login callback, valid when open-type=phoneOneClickLogin |
bindphoneoneclicklogin callback parameters
Object res
| Attribute | Type | Description |
|---|---|---|
| code | string | User login credential (valid for 5 minutes). Developers can call code2Verifyinfo on the developer server to use the code to exchange for user identity information, etc. |
| errCode | number | Error code |
| errMsg | string | Error message |
res.errCode
| errCode | Description |
|---|---|
| -1 | system error |
| 10001021 | Obtaining the phone number once allows only one login |
Sample Code
<button bindphoneoneclicklogin="onHandleLogin" open-type="phoneOneClickLogin">One-click Login Button</button>
Page({
onHandleLogin(e) {
const detail = e.detail;
console.log('phoneOneClickLogin errCode', detail.errCode)
},
})