您的位置:首页 > 其它

登录短信验证实现

2017-05-08 22:28 627 查看
默认发送的手机号码为管理员,发送的实现在后台实现

页面部分

<%@ page language="java" pageEncoding="utf-8"%>
<%@ page import="java.util.*"%>
<%@include file="/WEB-INF/pages/common/taglibs.jsp"%>
<!doctype html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>

<div style="margin-top:1%;margin-left:10px">
<label class="cusorHvr" id="oriPassword" style="color:#06C;margin-bottom:2%">短信验证码:</label>
<input class="textbox" type="text" id="codeIn" placeholder="请输入短信验证码" size="10" data-options="width:'100',panelWidth:'100',panelHeight:'100'" style="width:120px"/>
<input type
4000
="button" id="btnSendCode" name="btnSendCode" value="免费获取验证码" onclick="sendCode()" />
</div>

<div style="margin-top:1%;margin-left:10px">
<span id="tipv" style="color:#ff0000;"></span>
</div>

<div>
<button id="valiMessBtn" class="btn btn-warning" style="margin-top:7%;margin-right:5%;float:right"type="button">确定</button>
</div>

</body>
</html>
js部分

var InterValObj; //timer变量,控制时间
var count = 300; //间隔函数,1秒执行 ,(有效时间:5分钟)
var curCount;//当前剩余秒数
var code = ""; //产生验证码
var codeLength = 6;//验证码长度

//发送手机短信验证码
function sendCode(){
curCount = count;
// 产生验证码
for ( var i = 0; i < codeLength; i++) {
code += parseInt(Math.random() * 9).toString();
}
// 设置button效果,开始计时
$("#btnSendCode").attr("disabled", "true");
$("#btnSendCode").val("请在" + curCount + "秒内输入验证码");
InterValObj = window.setInterval(SetRemainTime, 1000); // 启动计时器,1秒执行一次
//发送验证码到手机
TeJax({
url: $.contextPath + "/vmConnONGL_sendMessCode",
async: false,
method:'post',
data:{
"code":code
},
success: function (rel) {
if(rel.result=="true"){
$.messager.alert('提示', '短信验证码已发到您的手机,请注意查收!', 'info');
}else{
$.messager.alert('提示', '短信验证码发送失败,请稍后再试!', 'info');
}
},
error: function (rel) {
$.messager.alert('错误','与服务器通讯失败,请检查通讯状态!','error');
}
});

}

//timer处理函数
function SetRemainTime() {
if (curCount == 0) {
//验证码失效,重新发送
window.clearInterval(InterValObj);// 停止计时器
$("#btnSendCode").removeAttr("disabled");// 启用按钮
$("#valiMessBtn").removeAttr("disabled");//确定按钮
$("#btnSendCode").val("重新发送验证码");
code = ""; // 清除验证码。如果不清除,过时间后,输入收到的验证码依然有效
}else {
curCount--;
$("#btnSendCode").val("请在" + curCount + "秒内输入验证码");
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: