# Send SMS verification code
iOS >= 0.7.13 Support, Android >= 0.7.5 Support.
adopt button
Component Specification open-type
for sendPhoneSms
, can trigger sending a mobile phone verification code to a specified mobile phone number.
Note: Before using the SMS verification code function, you need to complete the SMS signature requirement real name system for registration, otherwise you will not be able to send SMS.Click here to submit the reporting materials
# button Component parameter
attribute | type | Default value | Required | Introductions |
---|---|---|---|---|
phoneNumber | string | yes | Phone number | |
open-type | string | yes | sendPhoneSms To send mobile phone verification code | |
sms-type | number | 0 | no | Type of Sending Mobile Phone Verification Code |
bindsendphonesms | Function | no | Get the user phone number callback, open-type = sendPhoneSms valid |
# sms-type
value | Introductions |
---|---|
0 | Act as wx.phoneSmsLogin The Front Flow of |
1 | Act as wx.miniapp.bindPhone The Front Flow of |
# bindsendphonesms Callback parameter
# Object res
attribute | type | Introductions |
---|---|---|
errCode | number | Error code |
errMsg | string | Error message |
# sample code
<input bindinput="onPhoneNumberChange" value="{{phoneNumber}}"/>
<button type="primary" open-type="sendPhoneSms" sms-type="{{0}}" bindsendphonesms="onHandleLogin" phoneNumber="{{phoneNumber}}">Send verification code</button>
<input bindinput="onVerifyCodeChange" value="{{verifyCode}}"/>
<button bindtap="login" >log in</button>
Page({
data: {
phoneNumber: '',
verifyCode: ''
},
onVerifyCodeChange(e) {
this.setData({ verifyCode: e.detail.value })
},
onPhoneNumberChange (e) {
this.setData({ phoneNumber: e.detail.value })
},
onHandleLogin (e) {
const detail = e.detail
console.log('sendphonesms errCode', detail.errCode)
},
Login() {
wx.phoneSmsLogin({
phoneNumber: this.data.phoneNumber,
verifyCode: this.data.verifyCode,
success (res) {
if (res.code) {
//Initiate a network request
wx.request({
url: 'https://example.com/onLogin',
data: {
code: res.code
}
})
} else {
console.log('Login failed! ' + res.errMsg )
}
}
})
}
})