Since Leancloud provides a set of SMS verification for mobile phones, authentication is sent via Leancloud
1. Register Leancloud account, create Leancloud project corresponding to Java project, get application Appid,appkey
(Take mercy, don't copy my ha)
2. Add the corresponding JS to the HTML page or JSP page
<script src= "Https://leancloud.cn/scripts/lib/av-0.5.1.min.js" ></script>
<script src= "Js/common/jquery.js" type= "Text/javascript" ></script> (parsing jquery)
The above is the preparation, the following is the key ...
3.html page (Don't ask me, doubt your IQ)
<input maxlength= "$" id= "mobile" name= "mobile" datatype= "mobile" autocomplete= "Off" >
<button onclick= "Sendcode ()" > Send activation Code </button>
<input maxlength= "$" id= "Tel_code" name= "Tel_code" autocomplete= "Off" >
<span id= "Msg_code" style= "color:red;" > (10 minutes after sending the verification can be sent again) </span>
4. The corresponding JS
(1) Appid,appkey initialization of Leancloud registered projects into the Web project
Av.initialize ("X8c1c6z8pe1nfp02qdfsjg992kpr2nvk2hwy3birx3ff4o27", " L67mh8v8tjsm16gu8pwlchpkqb2d1hmd80gt11zcwwa14lqv ");//Do not compare above, this is two items
(2) Send verification code
Av. Cloud.requestsmscode (tel). Then (function () {
Sent successfully
$ ("#msg_code"). HTML ("Verification code sent, please enter the verification Code");
}, function (err) {
alert (err.message);
Send failed
$ ("#msg_code"). HTML ("Send failed, please check phone number");
});
(3) Verification, here I use to remove the focus after verification
var telcode=$ ("#tel_code"). Val ();
var tel=$ ("#mobile"). Val ();
Av. Cloud.verifysmscode ("Get the Phone verification code", "corresponding to the input phone number"). Then (function () {
Validation successful
$ ("#msg_code"). HTML ("Phone verification code is correct!") ");
}, function (err) {
Validation failed
$ ("#tel_code"). Val ("");
$ ("#msg_code"). HTML ("Phone Verification code Error! ");
});
Note:
The above SMS authentication uses Leancloud to provide the authentication mechanism, the authentication time interval 10 minutes, the API provides can develop the text message template, the text message time.
Leancloud Address: https://leancloud.cn/customers.html
Mobile registration, that is, send verification code to verify