登录短信验证实现
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 + "秒内输入验证码");
}
}
页面部分
<%@ 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 + "秒内输入验证码");
}
}
相关文章推荐
- 利用Bmob公司的云服务实现获取短信验证码登录操作
- Spring Security Oauth2.0 实现短信验证码登录示例
- 短信验证登录实现流程
- 简述短信验证码登录功能实现
- SpringBoot + SpringSecurity 短信验证码登录功能实现
- 利用Bmob公司的云服务实现获取短信验证码登录操作
- 用唯一ID实现免费的短信验证码登录
- Spring Security Oauth2.0 实现短信验证码登录
- 安卓使用Mob实现短信验证登录代码 很简单
- Android实现登录系统(二)--SMS短信验证登录
- 基于mob平台,手机短信验证码实现登录功能
- 怎样实现简单Forms验证(登录,注销)
- Ajax-HelloWorld(运用AJAX技术实现会员注册登录验证功能)
- jQuery入门学习二:使用jQuery方式实现异步登录验证
- JAVA实现:使用sAMAccountName作为登录名通过LDAP目录库验证
- 在Forms验证模式下,实现多个站点(SubDomain相同)共享同一用户登录状态
- 使用Servlet过滤器实现用户登录验证
- 最简单的登录验证(js实现)
- Struts中用Filter实现每个页面的登录验证
- jquery ajax 登录验证实现代码