首页 > 代码库 > sendsms短信验证功能实现代码
sendsms短信验证功能实现代码
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="maximum-scale=1.0,minimum-scale=0,width=device-width,initial-scale=1.0" />
<title>APP</title>
<link rel="stylesheet" type="text/css" href="http://www.mamicode.com/css/api.css" />
<link rel="stylesheet" type="text/css" href="http://www.mamicode.com/css/common.css" />
<style>
#con{
margin:10px;
font-size:28px;
}
ul{
margin-bottom:10px;
}
.txt{
margin:5px 10px;
padding:5px;
color:#000;
word-wrap:break-word;
}
input[type="text"]{
border-radius:6px;
background-color:#ffffff;
height:36px;
border:1px solid #D2CCCE;
color:#D2CCCE;
line-height:36px;
text-indent:7px;
width:120px;
background-clip:padding-box;
}
input[type="button"],#con{
border-radius:6px;
background-color:#81A9C3;
height:36px;
border:1px solid #2CCCE
color:#ffffff;
line-height:36px;
padding-left:30px;
padding-right:30px;
background-clip:padding-box;
}
</style>
</head>
<body>
<br>
<input type="button" onclick="reg_sms()" value="http://www.mamicode.com/注册短信模块" /><br><br>
手机号:<input type="text" id="tel" name="tel" value="" placeholder="输入手机号" />
<input type="button" class="yzm-btn" onclick="send_sms()" value="http://www.mamicode.com/发送验证码" /><br><br>
验证码<input type="text" id="code" name="code" value="" />
<input type="button" onclick="code_sms()" value="http://www.mamicode.com/短信验证" /><br><br><br><br><br>
<!-- 市场评分模块 -->
--------------------市场评分模块---------------------------------<br><br>
<label id="con" onclick="tosmarket()">5星好评支持我们</label>
<div id=‘sys-info‘>这里我用的是微信,可以随意改</div>
</body>
<script type="text/javascript" src="http://www.mamicode.com/script/api.js"></script>
<script type="text/javascript" src="http://www.mamicode.com/script/zepto.min.js"></script>
<script type="text/javascript">
apiready = function(){
sendsms = api.require(‘sendSms‘);
};
function reg_sms(){
//貌似是120秒内只能注册一次,不然会失败,注意下
var param = {appkey:"6680ba14a50e",appsecret:"95b67202d004b9f4ab2a38f3eda2e82c"};
sendsms.regSms(param);
alert("注册成功");
}
function send_sms(){
var tel = document.getElementById("tel").value;
var param = {phone:tel};
sendsms.sendMessage(param,function(ret,err){
if(ret.result == "ok"){
maxtime = 90;
timer1 = setInterval("send_code_jishi();", 1000);
alert("短信发送成功");
}else{
alert(ret.result);
}
});
}
function code_sms(){
var mycode = document.getElementById("code").value;
var param={code:mycode};
sendsms.enterCode(param,function(ret,err){
if(ret.result == "ok"){
alert("验证成功");
}else{
alert("验证失败");
}
});
}
function tosmarket(){
if (api.systemType =="android"){
smarket = api.require(‘marketScore‘);
var param = {appname:"com.tencent.mm"};
smarket.myScore(param);
}else{
api.openApp({
iosUrl: ‘https://itunes.apple.com/cn/app/wei-xin/id414478124?mt=8‘
},function(ret,err){
});
}
}
var timer1 = "";
var maxtime = 90;
function send_code_jishi(){
if(maxtime == 0){
clearInterval(timer1);
$(".yzm-btn").val("重发验证码");
}else{
maxtime--;
$(".yzm-btn").val(maxtime+"秒可重发");
}
}
</script>
</html>
sendsms短信验证功能实现代码