手機註冊,即發送驗證碼進行驗證

來源:互聯網
上載者:User

標籤:

由於leancloud提供了一套手機簡訊驗證,因此通過leancloud發送驗證

1.註冊leancloud帳號,建立對應java項目的leancloud項目,獲得應用的appID,appKey
(手下留情,別複製我的哈)
2.於html頁面或者jsp頁面加入對應的js

<script src="https://leancloud.cn/scripts/lib/av-0.5.1.min.js"></script>
<script src="js/common/jquery.js" type="text/javascript"></script>(解析jquery)

以上皆為準備,以下為重點。。。

3.html頁面(別問我,懷疑你的智商)
<input maxlength="200" id="mobile" name="mobile" dataType="mobile" autocomplete="off">
<button onclick="sendCode()">發送啟用碼</button>

<input maxlength="200" id="tel_code" name="tel_code" autocomplete="off">
<span id="msg_code" style="color:red;">(發送驗證後十分鐘可再次發送)</span>

4.對應的js

(1)將leancloud註冊的項目獲得的appId,appKey初始化進入web項目
AV.initialize("x8c1c6z8pe1nfp02qdfsjg992kpr2nvk2hwy3birx3ff4o27", "l67mh8v8tjsm16gu8pwlchpkqb2d1hmd80gt11zcwwa14lqv");//別比較之上的,這是兩個項目

(2)發送驗證碼
AV.Cloud.requestSmsCode(tel).then(function(){
          //發送成功
          $("#msg_code").html("驗證碼已發送,請輸入驗證碼");
        }, function(err){
            alert(err.message);
          //發送失敗
            $("#msg_code").html("發送失敗,請檢查手機號");
        });

(3)驗證,在這兒我用的是移除焦點後驗證

var telcode=$("#tel_code").val();
var tel=$("#mobile").val();

AV.Cloud.verifySmsCode("獲得的手機驗證碼", "對應輸入的手機號").then(function(){
          //驗證成功
          $("#msg_code").html("手機驗證碼正確!");
        }, function(err){
          //驗證失敗
          $("#tel_code").val("");
          $("#msg_code").html("手機驗證碼錯誤!");
        });        

備忘:
  以上簡訊驗證使用leancloud原生提供的驗證機制,驗證時間間隔10分鐘,api提供了可制定簡訊模板,簡訊時間。   
  leancloud地址:https://leancloud.cn/customers.html                   

手機註冊,即發送驗證碼進行驗證

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.