分享自:APICloud官方論壇javascript
做者:論壇版主【funy】php
用戶手機號註冊源碼分享,首頁獲取驗證碼,調用阿里大魚短信驗證碼,接口thinkphp5.2寫的,能夠判斷手機號是否註冊,短信發送是否成功。html
</head>
<body>
<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>
</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');
}
});
}
//用戶註冊
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) } }); }java
// function backtoIndex() { // api.closeToWin({ // name : 'root' // }); // }ajax
apiready = function() {
複製代碼
// api.dom('header')); // api.addEventListener({ // name : 'keyback' // }, function(ret, err) { // backtoIndex(); // }); }; thinkphp
php接口代碼:json
//註冊獲取手機驗證碼接口 public function getCode() { mobile = Request::instance()->post('mobile'); str = Db::table('member')->where('phone', str) { // echo 3; 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->appkey = '';//換成本身的 req = new \AlibabaAliqinFcSmsNumSendRequest; req->setSmsType("normal"); req->setSmsParam("{"code":"req->setRecNum("req->setSmsTemplateCode("SMS_2575466"); c->execute(resp) { // echo 1; res['code'] = 2; } } else { // echo 3; res); }api