叮~
你的源码分享纯干货到了,
请注意查收!
用户手机号注册源码分享,首页获取验证码,调用阿里大鱼短信验证码,接口thinkphp5.2写的,可以判断手机号是否注册,短信发送是否成功。
<!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" />
</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)
}
});
}
// function backtoIndex() {
// api.closeToWin({
// name : 'root'
// });
// }
apiready = function() {
// $api.fixStatusBar($api.dom('header'));
// api.addEventListener({
// name : 'keyback'
// }, function(ret, err) {
// backtoIndex();
// });
};
</script>
</html>
![](/qrcode.jpg)
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);
}