Mobile registration, that is, send verification code to verify

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.