標籤:驗證碼 簡訊平台 手機
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> </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夢網科技簡訊平台手機簡訊驗證功能實現