POST http://localhost:8080/QiangkaBindServlet 404 (Not Found)
send @ jquery.min.js:2
ajax @ jquery.min.js:2
code_btn_et1 @ main.js:80
dispatch @ jquery.min.js:2
u @ jquery.min.js:2
$(function(){
//ajax判斷是否已經注冊
//獲取驗證碼按鈕
var isAppoint=false;
console.log(openId);
var submitData = {
"openId" : openId,
// "phone" : tel2,
"type" : 1
};
/*$.ajax({
type : "post",
async : false,
url : "/QiangkaBindServlet",
dataType : "json",
data : submitData,
success : function(data) {
if(Number(data.code)== 0 ){
isAppoint=data.isAppoint;
if(isAppoint==true){
$("#index1").hide();
$("#index2").show();
window.location.href="zz001.html";
//alert("您已經綁定過了");
}
}else{
}
},
error : function(r) {
//alert("判斷用戶是否綁定接口失敗,當前網絡繁忙!");
}
});*///end ajax
$("#get_code").bind("click", code_btn_et1 = function() {
// alert("isAppoint="+isAppoint);
if(isAppoint==true){
alert("您已經綁定過了");
return;
}
tel2 = $("#tel2").val();
if (tel2 == '') {
alert("請輸入您要綁定的手機號");
return;
}
var mobileNo=/^175[0-9]{8}$/ ;
var mobileNo1=/^1(3[0-9]|5[0-35-9]|8[025-9]|47|7[5])[0-9]{8}$/ ;
var mobileNo2=/^1760000[0-9]{4}$/;
var cm=/^1(78[0-9]|47[0-9]|34[0-8]|(3[5-9]|5[017-9]|8[278])[0-9])[0-9]{7}$/ ;
var cu=/^1(3[0-2]|5[256]|8[56]|76)[0-9]{8}$/;
var ct=/^1((33|53|8[09]|77)[0-9]|349)[0-9]{7}$/
var mn = new RegExp(mobileNo);
var mn1 = new RegExp(mobileNo1);
var mn2 = new RegExp(mobileNo2);
var m = new RegExp(cm);
var u = new RegExp(cu);
var t = new RegExp(ct);
if (!mn.test(tel2)&&!mn2.test(tel2)&&!mn1.test(tel2)) {
alert("請輸入正確手機號碼!");
return;
}
/* else if (m.test(tel2)) { //移動號碼
alert("請輸入中國聯通手機號碼!");
return;
} else if (t.test(tel2)) { //電信號碼
alert("請輸入中國聯通手機號碼!");
return;
} else if (!u.test(tel2)) { //非聯通號碼
alert("您輸入的手機號碼無效,請重新輸入!");
return;
}*/
$("#get_code").unbind("click", code_btn_et1);
seconds = 60;
var submitData = {
"openId" : openId,
"phone" : tel2,
"type" : 4
};
$.ajax({
type : "post",
async : false,
url : "/QiangkaBindServlet",
dataType : "json",
data : submitData,
success : function(data) {
if(Number(data.code)== 0 ){
/*if(data.isAppoint==true){
//alert("該用戶已經預約,無需再次預約");
$("#box4").show();
$("#goto1").one("click",function(){
window.location.href="index.jsp?type=3&openId="+openId;
});
}else
if(data.isSichuan==false){
//alert("該用戶不是四川用戶,不能參加本活動");
$("#box6").show();
$("#get_code").bind("click", code_btn_et1);
}else if(data.isUsim==false){
//alert("該用戶是Usim卡,不用換卡");
$("#box6").show();
$("#get_code").bind("click", code_btn_et1);
}else*/if(data.isAppoint){//需要換卡但是已經預約過了
//alert("您已經預約過了,不用再預約了");
//$("#box4").show();
//window.location.href="index.jsp?type=3&openId="+openId;
//window.location.href="index.jsp?type=3&openId="+openId;
alert("您已經綁定過了");
}else if(data.success==true){
//alert("該用戶不是Usim卡,短信發送成功");
timeCountDown();
}
}else{
alert("你輸入的手機號碼不合法");
}
},
error : function(r) {
alert("抱歉,當前系統繁忙,請您稍後再試!");
seconds = 0;
}
});//end ajax
});//end click
//--注冊--提交
$("#phone7").bind("click", bind_btn_et2 = function() {
if(isAppoint==true){
alert("您已經綁定過了");
return;
}
tel2 = $("#tel2").val();
if (tel2 == '') {
alert("請輸入您要綁定的手機號");
return;
}
var mobileNo=/^175[0-9]{8}$/ ;
var mobileNo1=/^1(3[0-9]|5[0-35-9]|8[025-9]|47|7[5])[0-9]{8}$/ ;
var mobileNo2=/^1760000[0-9]{4}$/;
var cm=/^1(78[0-9]|47[0-9]|34[0-8]|(3[5-9]|5[017-9]|8[278])[0-9])[0-9]{7}$/ ;
var cu=/^1(3[0-2]|5[256]|8[56]|76)[0-9]{8}$/ ;
var ct=/^1((33|53|8[09]|77)[0-9]|349)[0-9]{7}$/
var mn = new RegExp(mobileNo);
var mn1 = new RegExp(mobileNo1);
var mn2 = new RegExp(mobileNo2);
var m = new RegExp(cm);
var u = new RegExp(cu);
var t = new RegExp(ct);
if (!mn.test(tel2)&&!mn2.test(tel2)&&!mn1.test(tel2)) {
alert("請輸入正確手機號碼!");
return;
}
/* else if (m.test(tel2)) { //移動號碼
alert("請輸入中國聯通手機號碼!");
return;
} else if (t.test(tel2)) { //電信號碼
alert("請輸入中國聯通手機號碼!");
return;
} else if (!u.test(tel2)) { //非聯通號碼
alert("您輸入的手機號碼無效,請重新輸入!");
return;
}*/
var yzm = $("#yzm").val();
if (yzm == '') {
alert("驗證碼不能為空!");
return;
}else if(yzm.length!=6){
alert("驗證碼錯誤!");
return;
}
/* if(!confirm("您確定要開通“1元省內網內隨意打”業務嗎?")){
return;
} /
$("#phone7").unbind("click", bind_btn_et2);
var submitData = {
"openId" : openId,
"phone" : tel2,
"yzm" : yzm,
"type" : 5
};
$.ajax({
type : "post",
async : true,
url : "/QiangkaBindServlet",
dataType : "json",
data : submitData,
success : function(data) {
if(Number(data.code)== 0 ){
if(data.isAppoint==true){
alert("您已經綁定過了");
// $("#box4").show();
// $("#goto1").one("click",function(){
// window.location.href="index.jsp?type=3&openId="+openId;
// });
}else if(data.rightYzm==false){
alert("驗證碼錯誤");
}
/ else if(data.isSichuan==false){
$("#box6").show();
//alert("該用戶不是四川用戶,不能參加本活動");
}else if(data.isUsim==false){
//alert("該用戶是Usim卡,不用換卡");
$("#box6").show();
}else if(data.success==false){
//alert("該用戶不是Usim卡,但驗證碼錯誤");
$("#box7").show();
}*/
else if(data.success==true){
//alert("該用戶不是Usim卡,預約成功");
//alert("綁定成功");
/*$("#index1").hide();
$("#index2").show();
$("#yzm").attr("readonly","true");
$("#tel2").attr("readonly","true");
$("#get_code").hide();*/
window.location.href="zz001.html";
// isAppoint=true;
// window.location.href="http://www.baidu.com";
}
}else{
alert("你輸入的手機號碼不合法");
}
$("#phone7").bind("click", bind_btn_et2);
},
error : function(r) {
alert("抱歉,系統繁忙,請您稍後重試!");
$("#phone7").bind("click", bind_btn_et2);
}
});//end ajax
});//end click
});
function timeCountDown() { //加時函數
if (seconds > 0) { //如果不到5分鐘
$("#get_code").html(seconds + "秒重新獲取");
seconds--; //時間變量自減1
setTimeout("timeCountDown()", 1000); //設置1000毫秒以後執行一次本函數
} else {
$("#get_code").bind("click", code_btn_et1);
$("#get_code").html("獲取驗證碼");
}
};
package servlet;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Enumeration;
import java.util.Random;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang.StringUtils;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
import org.xml.sax.SAXException;
import com.sinovatech.ntf.send.NtfplatService;
import domain.BindPhoneBean;
import service.QiangkaBindService;
import util.Utils;
@WebServlet("/QiangkaBindServlet")
public class QiangkaBindServlet extends HttpServlet {
private static final long serialVersionUID = 7599540073445710243L;
//private static Logger log = LoggerFactory.getLogger(QiangkaBindServlet.class);
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.doPost(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
try {
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
response.setContentType("text/html; charset=utf-8");
String openId = request.getParameter("openId");
String typeStr = request.getParameter("type");
//log.info("----WangkaBindServlet-----openId:" + openId + "------typeStr:" + typeStr);
String respJson = "{ \"code\":\"1\" , \"desc\":\"服務器訪問失敗,請稍後重試!\" }";
if (openId != null && !"".equals(openId) && typeStr != null && !"".equals(typeStr)) {
int type = Integer.parseInt(typeStr);
if (type == 1) {// 判斷是否綁定
respJson = "{\"code\":\"1\" ,\"isAppoint\":false}";
// String phone = request.getParameter("phone");
// if (phone != null && !phone.equals("")) {
// boolean isSichuan =
// QiangkaBindService.getInstance().checkSichuan(phone);
// log.info("\n=====是否四川用戶:" + isSichuan);
// boolean isSichuan=true;//mock
boolean isAppoint = false;
// if(isSichuan==true){
isAppoint = QiangkaBindService.getInstance().checkAppoint(openId);
// }
//log.info("\n=====是否已經綁定用戶:" + isAppoint);
respJson = "{\"code\":\"0\" ,\"isAppoint\":" + isAppoint + "}";
// respJson = "{\"code\":\"0\"
// ,\"isUsim\":"+false+",\"isSichuan\":"+true+"}";//mock
//log.info("---respJson:" + respJson);
// }
} else if (type == 4) { // 發送驗證碼
String phone = request.getParameter("phone");
NtfplatService sendsingle = new NtfplatService();
// 業務類別編碼
String bizCode = "11001";
// 業務類別名稱
String bizName = "京東強卡驗證碼下發";
// 任務名稱
String taskName = "京東強卡驗證碼下發";
// // 隨機生成驗證碼
// Random random = new Random();
// int yzm = random.nextInt(899999);
// yzm += 100000;
// 短信內容
// String content = "您的驗證碼是:" + yzm + "[京東強卡]";
// 手機號
// String target="";
if (phone != null && !"".equals(phone)) {
// boolean isSichuan =
// QiangkaBindService.getInstance().checkSichuan(phone);
// boolean isSichuan = true;//mock
// log.info("\n=====親友是否四川用戶:" + isSichuan);
// boolean isUsim=false;
boolean success = false;// 發短信是否成功
boolean isAppoint = false;// 這個人是否綁定
// BindPhoneBean bpBean0 =
// QiangkaBindService.getInstance().queryBindPhoneInfoByOpenId(openId,phone);
/*
* if(bpBean0 !=
* null&&bpBean0.getCode()!=0&&bpBean0.getIsBind()==1||
* bpBean0 != null&&bpBean0.getCode()==0){//這個朋友已經綁定了
* isAppoint=true; }else {
*/
// if(isSichuan==true){
// isUsim=QiangkaBindService.getInstance().checkUsim(phone);
// log.info(" isUsim="+isUsim);
// isUsim=false;
// if(isUsim){//發短信驗證碼 //檢查是否在庫中,在庫中的不是USIM卡
// BindPhoneBean bpBean0 =
// QiangkaBindService.getInstance().queryBindPhoneInfoByOpenId(openId);
// if(bpBean0 !=
// null&&bpBean0.getCode()!=0&&bpBean0.getIsBind()==1){//這個人已經綁定了
// isAppoint=true;//是否綁定該手機號
// }else{
// isAppoint=false;//是否綁定該手機號
// }
// log.info("\n=====是否綁定用戶:" + isAppoint);
isAppoint = QiangkaBindService.getInstance().checkAppoint(openId);
if (!isAppoint) {//// 沒綁定,綁定一下
int code = Utils.buildRandom(6);// 生成驗證碼
//log.info("^^^^^^^^^^^^^^^^^^^^^強卡服務綁定^^^^^^^^^^^^^^^^^^^^^驗證碼是:" + code);
// String smsMsg =
// "您的驗證碼是:"+code+"(10分鐘內有效),如非本人操作,請忽略本短信。";
String smsMsg = "您的強卡服務微信公眾號驗證碼是:" + code + "(10分鐘內有效),如非本人操作,請忽略本短信";
// boolean
// sendRs=SendSmsNetEngine.getInstance().sendSms(phone,smsMsg);
try {
int sendRs = sendsingle.sendSingle(bizCode, bizName, taskName, smsMsg, phone);
System.out.println(sendRs + ":京東強卡驗證碼下發成功");
} catch (SAXException e) {
e.printStackTrace();
}
BindPhoneBean bpBean = new BindPhoneBean();
bpBean.setOpenId(openId);
//log.info("openId=" + openId);
bpBean.setPhone(phone);
bpBean.setCode(code);
bpBean.setIsBind(0);
bpBean.setStatusBind(1);
QiangkaBindService.getInstance().saveOrUpdateBindPhone(bpBean); // 存入數據庫
success = true;
}
// }
// }
/* } */
/*
* respJson = "{\"code\":\"0\" ,\"isUsim\":"
* +isUsim+",\"isSichuan\":"+isSichuan+",\"isAppoint\":"
* +isAppoint+",\"success\":"+success+"}";
*/
respJson = "{\"code\":\"0\" ,\"isAppoint\":" + isAppoint + ",\"success\":" + success + "}";
} else {
respJson = "{\"code\":\"1\",\"msg\":\"請輸入正確的手機號碼!\"}";
}
} else if (type == 5) { // 校驗驗證碼,若正確則綁定
String phone = request.getParameter("phone");
if (phone != null && !"".equals(phone)) {
// boolean isSichuan = false;
// log.info("\n=====親友是否四川用戶:" + isSichuan);
// boolean isUsim=false;
// boolean isAppoint=false;//這個朋友是否綁定
boolean success = false;// 綁定是否成功
boolean rightYzm = true;// 驗證碼是否正確
// boolean isFirst=false;//是否首次綁定
// isFirst=QiangkaBindService.getInstance().checkFirst(openId);//是否首次綁定
BindPhoneBean bpBean = QiangkaBindService.getInstance().queryBindPhoneInfoByOpenId(openId);
boolean isAppoint = false;// 這個人是否綁定
isAppoint = QiangkaBindService.getInstance().checkAppoint(openId);
if (!isAppoint) {// 這個朋友已經綁定了
// isSichuan =
// QiangkaBindService.getInstance().checkSichuan(phone);
// isSichuan=true;
// if(isSichuan==true){
// isUsim=QiangkaBindService.getInstance().checkUsim(phone);//檢查是否在庫中,在庫中的不是USIM卡
// isUsim=false;
// if(isUsim){//不是Usim卡,檢查短信驗證碼是否正確
String codeStr = request.getParameter("yzm");
//log.info("codeStr=" + codeStr);
if (codeStr != null && !"".equals(codeStr)) {
int code = Integer.parseInt(codeStr);
//log.info("code == bpBean.getCode()" + (code == bpBean.getCode()));
if (code == bpBean.getCode()) {
bpBean.setOpenId(openId);
bpBean.setPhone(phone);
bpBean.setIsBind(1);
bpBean.setStatusBind(0);
bpBean.setPhoneType(1);// 號碼類型 0 未知 1四川聯通 2
// 非四川聯通 3 移動號碼 4
// 電信號碼
success = QiangkaBindService.getInstance().saveOrUpdateBindPhone(bpBean); // 存入數據庫
if (success) {
/*
* String[]
* awards=QiangkaBindService.getInstance
* ().getAward(openId);
* if(awards[0]==null&&awards[1]==null){
* QiangkaBindService.getInstance().
* saveAward(openId); }
* if(isFirst){//首次綁定給獎品
* QiangkaBindService.getInstance().
* saveAward(openId); }
*/
}
} else {
rightYzm = false;
}
}
// }
// }
} else {
rightYzm = false;
}
/*
* respJson = "{\"code\":\"0\" ,\"isUsim\":"
* +isUsim+",\"isSichuan\":"+isSichuan
* +",\"isAppoint\":"+isAppoint+",\"success\":"+success+
* ",\"rightYzm\":"+rightYzm+"}";
*/
respJson = "{\"code\":\"0\" ,\"isAppoint\":" + isAppoint + ",\"success\":" + success
+ ",\"rightYzm\":" + rightYzm + "}";
} else {
respJson = "{\"code\":\"1\",\"msg\":\"請輸入正確的手機號碼!\"}";
}
} else if (type == 6) {// 解除綁定
BindPhoneBean bpBean = QiangkaBindService.getInstance().queryBindPhoneInfoByOpenId(openId);
boolean isAppoint = false;// 這個人是否綁定
// isAppoint=QiangkaBindService.getInstance().checkAppoint(openId);
// if(isAppoint){//這個朋友已經綁定了
bpBean.setIsBind(0);
bpBean.setStatusBind(1);
bpBean.setPhoneType(0);// 號碼類型 0 未知 1四川聯通 2 非四川聯通 3 移動號碼 4
// 電信號碼
boolean success = QiangkaBindService.getInstance().saveOrUpdateBindPhone(bpBean); // 存入數據庫
respJson = "{\"code\":\"0\" ,\"isAppoint\":" + isAppoint + ",\"success\":" + success + "}";
// }else{//這個朋友未綁定
// respJson = "{\"code\":\"0\"
// ,\"isAppoint\":"+isAppoint+",\"success\":"+false+"}";
// }
} else if (type == 7) { // 無驗證碼綁定-亞聯
String phone = request.getParameter("phone");
if (phone != null && !"".equals(phone)) {
boolean success = false;// 綁定是否成功
// boolean rightYzm=true;//驗證碼是否正確
// BindPhoneBean bpBean =
// QiangkaBindService.getInstance().queryBindPhoneInfoByOpenId(openId);
BindPhoneBean bpBean = new BindPhoneBean();
// boolean isAppoint=false;//這個人是否綁定
// isAppoint=QiangkaBindService.getInstance().checkAppoint(openId);
// if(!isAppoint){//這個朋友已經綁定了
// String codeStr = request.getParameter("yzm");
// log.info("codeStr="+codeStr);
// if(codeStr != null && !"".equals(codeStr)){
// int code = Integer.parseInt(codeStr);
// log.info("code == bpBean.getCode()"+(code ==
// bpBean.getCode()));
// if(code == bpBean.getCode()){
bpBean.setOpenId(openId);
bpBean.setPhone(phone);
bpBean.setIsBind(1);
bpBean.setStatusBind(0);
bpBean.setPhoneType(1);// 號碼類型 0 未知 1四川聯通 2 非四川聯通 3 移動號碼
// 4 電信號碼
success = QiangkaBindService.getInstance().saveSpecBindPhone(bpBean); // 存入數據庫
// }else{
// rightYzm=false;
// }
// }
// }else{
// rightYzm=false;
// }
respJson = "{\"code\":\"0\",\"success\":" + success + "}";
} else {
respJson = "{\"code\":\"1\",\"success\":false}";
}
}
}
//log.info("-----respJson:" + respJson);
PrintWriter out = response.getWriter();
out.println(respJson);
out.flush();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}
@SuppressWarnings("rawtypes")
public static boolean validateRequest(HttpServletRequest request) {
String referer = "";
boolean referer_sign = true;// true 站內提交,驗證通過 //false 站外提交,驗證失敗
Enumeration headerValues = request.getHeaders("referer");
while (headerValues.hasMoreElements()) {
referer = (String) headerValues.nextElement();
}
// 判斷是否存在請求頁面
if (StringUtils.isBlank(referer))
referer_sign = false;
else {
// 判斷請求頁面和getRequestURI是否相同
String servername_str = request.getServerName();
if (StringUtils.isNotBlank(servername_str)) {
int index = 0;
if (StringUtils.indexOf(referer, "https://") == 0) {
index = 8;
} else if (StringUtils.indexOf(referer, "http://") == 0) {
index = 7;
}
if (referer.length() - index < servername_str.length()) {// 長度不夠
referer_sign = false;
} else { // 比較字符串(主機名稱)是否相同
String referer_str = referer.substring(index, index + servername_str.length());
if (!servername_str.equalsIgnoreCase(referer_str))
referer_sign = false;
}
} else
referer_sign = false;
}
return referer_sign;
}
}