php夢網科技簡訊平台手機簡訊驗證功能實現

來源:互聯網
上載者:User

標籤:驗證碼   簡訊平台   手機   

1.表單傳輸頁面

<?phpsession_start();error_reporting(E_ALL & ~E_NOTICE);?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title>手機驗證碼</title><?$action=$_GET["action"];    if ($action==‘add‘) {        if ((strtotime($_SESSION[‘time‘]) + 60) < time()) {//將擷取的緩衝時間轉換成時間戳記加上60秒後與目前時間比較,小於目前時間即為到期            session_destroy();            unset($_SESSION);            //header(‘content-type:text/html; charset=utf-8;‘);            echo ‘<script>alert("驗證碼已到期,請重新擷取!");</script>‘;        } else {            $Code = trim($_POST["TextBox2"]);            if (strlen($Code) > 1 and $Code == $_SESSION[‘rand‘])                print("<script>alert(‘驗證成功‘)</script>");            else                print("<script>alert(‘驗證失敗‘)</script>");            unset($_SESSION[‘rand‘]);        }    }    ?><script src="js/jquery.js" language="javascript" type="text/javascript"></script><script type="text/javascript">function get(obj) {    var partten = /^\d{10,13}$/;    if (!partten.test(document.getElementById("TextBox1").value)) {        alert(‘請輸入正確的手機號碼‘);        return;    }  obj.disabled = true;  $.ajax({      url: "getcode.php",      type: "Post",      data: "Tel=" + $("#TextBox1").val(),      success: function(msg) {          obj.disabled = false;          if (msg == "ok") {              alert("111")              return;          }          if (msg == "error") {              alert("22")              return;          }          alert(msg);      }  })  }</script></head><body><label><form id="form1" name="form1" method="post" action="index.php?action=add">您手機號碼:<input name="TextBox1" type="text" id="TextBox1" />       <input id="Button1" type="button" value="擷取簡訊驗證碼" onClick="get(this)" /><br /><br />驗證碼:<input name="TextBox2" type="text" id="TextBox2" /> </label><br /><br /><label><input type="submit" name="Submit" value=" 確 定 " /></label></form><p>&nbsp;</p></body></html>

2.資料處理頁面,(傳送簡訊驗證)

<?phpsession_start();include "TopSdk.php";date_default_timezone_set(‘Asia/Shanghai‘);//產生隨機驗證碼$srand = rand(1000,9999);$_SESSION[‘rand‘]=$srand;//產生緩衝時間if (isset($_SESSION[‘time‘]))//判斷緩衝時間{    $_SESSION[‘time‘];} else {    $_SESSION[‘time‘] = date("Y-m-d H:i:s");}    $rand = $_SESSION[‘rand‘];    $c = new TopClient;    $appkey = ‘XXX‘;//你的appkey    $secret = ‘XXXX‘;//你的secret    //$phone = ‘XXXXXX‘;    $phone=$_POST["Tel"];//得到的手機號    $c->appkey = $appkey;    $c->secretKey = $secret;    $req = new AlibabaAliqinFcSmsNumSendRequest;    $req->setExtend("");    $req->setSmsType("normal");    $req->setSmsFreeSignName("XX");//你的簡訊驗證簽名    $req->setSmsParam("{number:‘$rand‘}");    $req->setRecNum($phone);    $req->setSmsTemplateCode("XX");//你的簡訊模板ID    $resp = $c->execute($req);?>


php夢網科技簡訊平台手機簡訊驗證功能實現

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.