叮~javascript
你的源碼分享純乾貨到了,php
請注意查收!css
用戶手機號註冊源碼分享,首頁獲取驗證碼,調用阿里大魚短信驗證碼,接口thinkphp5.2寫的,能夠判斷手機號是否註冊,短信發送是否成功。html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
<meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
<title>title</title>
<link rel="stylesheet" type="text/css" href="../css/api.css"/>
<link rel="stylesheet" type="text/css" href="../css/style.css" />
<link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />java
</head>
<body>ajax
<div class="aui-content aui-margin-b-15">
<ul class="aui-list aui-form-list">
<li class="aui-list-item">
<div class="aui-list-item-inner">
<div class="aui-list-item-label-icon">
<i class="aui-iconfont aui-icon-mobile"></i>
</div>
<div class="aui-list-item-input">
<input type="text" placeholder="手機號" id="mobile">
</div>
</div>
</li>
<li class="aui-list-item">
<div class="aui-list-item-inner">
<div class="aui-list-item-label-icon">
<i class="aui-iconfont aui-icon-lock"></i>
</div>
<div class="aui-list-item-input">
<input type="text" placeholder="驗證碼" id="code">
</div>
<div class="aui-list-item-label-icon">
<i class="aui-iconfont aui-icon-display"></i>
</div>
</div>
</li>
</ul>
</div>
<div align="center">
<button type="button" onclick="get_code();">
獲取驗證碼
</button>
<button type="button" onclick="next_reg();">
下一步
</button>
</div>thinkphp
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript">
var mobile = document.getElementById("mobile");
var code = document.getElementById("code");
var code_str = "";
for (var i = 0; i < 6; i++) {
code_str += Math.round(Math.random() * 10);
}
var getcode = document.getElementById("getcode");
// alert(code_str);
function get_code() {
// alert(mobile.value);
// alert();
if (mobile.value.length == 0) {
alert("手機號不能爲空");
return;
}
api.ajax({
url : 'http://huodong.demo.com/index.php/api/Member/getCode',
method : 'post',
data : {
values : {
mobile : mobile.value,
code_str : code_str,
signature : '*******'
}
}
}, function(data) {
// alert(data.code);
if (data) {
if (data.code == 1) {
// alert('驗證碼發送成功');
api.toast({
msg : '驗證碼發送成功'
});
} else if (data.code == 2) {
alert('驗證碼發送失敗');
} else if (data.code == 3) {
alert('手機號已註冊');
}
} else {
alert('111');
}
});
}json
//用戶註冊
function next_reg() {
if (code.value != code_str) {
alert("驗證碼錯誤");
return;
}
// api.openWin({
// name : 'personer_regsetpass',
// url : 'personer_regsetpass.html',
// pageParam : {
// mobile : mobile.value
// }
// });
api.openWin({
name : 'personer_regsetpass',
url : './a_headbackindex.html',
pageParam : {
title : '註冊',
url : 'personer_regsetpass',
mobile : $api.setStorage('mobile', mobile.value)
}
});
}api
// function backtoIndex() {
// api.closeToWin({
// name : 'root'
// });
// }app
apiready = function() {
// $api.fixStatusBar($api.dom('header'));
// api.addEventListener({
// name : 'keyback'
// }, function(ret, err) {
// backtoIndex();
// });
};
</script>
</html>
php接口代碼:
//註冊獲取手機驗證碼接口 public function getCode() { $code = Request::instance()->post('code_str'); $mobile = Request::instance()->post('mobile'); $signature = Request::instance()->post('signature'); $str = Db::table('member')->where('phone', $mobile)->find(); if ($str) { // echo 3; $res['code'] = 3; } else { if ($signature == '************') { Loader::import('AlibabaAliqinFcSmsNumSendRequest', EXTEND_PATH); Loader::import('TopClient', EXTEND_PATH); Loader::import('ResultSet', EXTEND_PATH); Loader::import('RequestCheckUtil', EXTEND_PATH); Loader::import('TopLogger', EXTEND_PATH); $c = new \TopClient; $c->appkey = '';//換成本身的 $c->secretKey = '';//換成本身的 $req = new \AlibabaAliqinFcSmsNumSendRequest; $req->setExtend("123456"); $req->setSmsType("normal"); $req->setSmsFreeSignName("");//換成本身的 $req->setSmsParam("{\"code\":\"$code\",\"product\":\"註冊\"}"); $req->setRecNum("$mobile"); $req->setSmsTemplateCode("SMS_2575466"); $resp = $c->execute($req); if ($resp) { // echo 1; $res['code'] = 1; } else { // echo 2; $res['code'] = 2; } } else { // echo 3; $res['code'] = 3; } } echo json_encode($res); }