1.先在addloginpage.html中添加相关按钮
2.在loginDesignAuth.js中添加手机认证
/*添加手机认证*/
$('body').append('
3.还是在js页面添加相关方法
function checkRandom(){
var text = $("#num").val();
$.ajax({
type: "POST",
url: "../../checkRandom/",
data: {
randomKey: text
},
success: function(msg){
if (msg == '上网口令错误!') {
alert(msg);
}
else {
window.location.href = "../../"+msg;
}
}
});
}
/**
* 获取上网口令
*/
function sendMsm(){
var text = $("#phoneNum").val();
if (!(/(^1[3|4|5|8][0-9]\d{4,8}$)/.test(text))){
alert("请输入正确的手机号!");
return;
}
$.ajax({
type: "POST",
url: "../../sendMsg/",
data: {
phoneNum: text
},
success: function(msg){
setInterval("countDown()", 1000);
$('#getNum').attr({"disabled":"true"});
alert(msg);
}
});
}
var i = 60;
function countDown(){
$('#getNum').val('还剩' + i + '秒可重新获取上网');
if(i==0){
$('#getNum').val("免费获取");
$('#getNum').removeAttr("disabled");
return;
}
i--;
}
4.自己写SendMsg工具类SendMsg.java
package com.xerxes.util;
import com.shcm.send.DataApi;
import com.shcm.send.OpenApi;
public class SendMsg {
private static String sOpenUrl = "http://smsapi.c123.cn/OpenPlatform/OpenApi";
private static String sDataUrl = "http://smsapi.c123.cn/DataPlatform/DataApi";
// 接口帐号
private static final String account = "1001@500928820001";
// 接口密钥
private static final String authkey = "C6F72D705196E633CD14973337E07520";
// 通道组编号
private static final int cgid = 52;
// 默认使用的签名编号(未指定签名编号时传此值到服务器)
private static final int csid = 0;
/**
* 给指定的手机号发送短信
*
* @param phoneNum
* 手机号
* @param randomKey
* 随机生成的上网密码
* @return 返回true则是发送成功,false则是发送失败
*/
public static boolean send(String phoneNum, String randomKey) {
try {
// 发送参数
OpenApi.initialzeAccount(sOpenUrl, account, authkey, cgid, csid);
// 状态及回复参数
DataApi.initialzeAccount(sDataUrl, account, authkey);
// 取帐户余额
double dReamin = OpenApi.getBalance();
System.out.println("可用余额: " + dReamin);
// 发送短信
String sContent = "this is your network password:" + randomKey + "[OpenWifi]";
String sSend = new String(sContent.getBytes(), "UTF-8");
int nRet = OpenApi.sendOnce(phoneNum, sSend, 0, 0, null);
if (nRet > 0) {
return true;
} else {
return false;
}
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
}
5.在WifiDogAction.java中添加两个方法:
/**
* 发送短信接口
* 随机码可用时间为五分钟
*/
public void sendMsg(){
try {
//生成六位随机上网码
for (int i = 0; i < 6; i++) {
randomKey += (int)(10*Math.random());
}
if (SendMsg.send(phoneNum, randomKey)) {
//将手机号和随机码保存到数据
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
RandomKeyAuth randomKeyAuth = new RandomKeyAuth();
randomKeyAuth.setCreatedt(Timestamp.valueOf(sdf.format(new Date())));
randomKeyAuth.setCreattype(PHONE);
randomKeyAuth.setIsused(UNUSED);
randomKeyAuth.setKeymsg(randomKey);
Calendar nowTime = Calendar.getInstance();
nowTime.add(Calendar.MINUTE, 5);
randomKeyAuth.setUseddt(Timestamp.valueOf(sdf.format(nowTime.getTime())));
randomKeyAuthService.save(randomKeyAuth);
outPrint("请注意查收短信!");
}else {
outPrint("短发发送失败,请重试");
}
} catch (Exception e) {
e.printStackTrace();
outPrint("短发发送失败,请重试");
}
}
/**
* 验证随机上网码是否有效
*/
public void checkRandom(){
try {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
criterions = new ArrayList
criterions.add(Restrictions.eq("keymsg", randomKey));
criterions.add(Restrictions.eq("isused", UNUSED));
criterions.add(Restrictions.ge("useddt", Timestamp.valueOf(sdf.format(new Date()))));
RandomKeyAuth randomKeyAuth = randomKeyAuthService.executeQueryUnique(criterions, null);
if(randomKeyAuth != null){
randomKeyAuth.setIsused(USE);
randomKeyAuthService.saveOrUpdate(randomKeyAuth);
getSession().setAttribute("loginType", "5");
outPrint("oneKey/");
}else {
outPrint("上网口令错误!");
}
} catch (Exception e) {
e.printStackTrace();
}
}
6.在wifiAuth.xml添加