<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<%option explicit%>
<!--#include file="../Conn.asp"-->
<!--#include file="../Task/TaskConfig.asp"-->
<!--#include file="../HSK_Cls/HSK.MemberCls.asp"-->
<!--#include file="../HSK_Cls/HSK.Label.CommonCls.asp"-->
<%
'****************************************************
' 手机短信认证
'****************************************************
Dim KSCls
Set KSCls = New User_IDAuthentication
KSCls.HSK_Run()
Set KSCls = Nothing

Class User_IDAuthentication
        Private KS,KSUser
		Private RS
		Private TempStr,SqlStr
		
		Private Sub Class_Initialize()
		  Set KS=New PublicCls
		  Set KSUser = New UserCls
		  Session(KS.SiteSN&"UserInfo") = Empty
		End Sub
        Private Sub Class_Terminate()
		 Set KS=Nothing
		 Set KSUser=Nothing
		 Call CloseConn()
		End Sub
		%>
		<!--#include file="../HSK_Cls/UserFunction.asp"-->
		<%
       Public Sub loadMain()

		IF Cbool(KSUser.UserLoginChecked)=false Then
		  Response.Write "<script>top.location.href='Login';</script>"
		  Exit Sub
		End If
		Call KSUser.Head()
		Call KSUser.InnerLocation("手机短信身份认证")
		Select Case KS.LoseHtml(KS.S("Action"))
		 Case "Save"  Call DoSave()
		 Case "Send" Call DoSend()
		 Case Else  Call Main()
		End Select
	   End Sub

	   Sub Main()
	   IF KS.ChkClng(KSUser.GetUserInfo("KS_IDAuthentication"))<>1 Then
	    %>
<script type="text/javascript">
function ismobile(s)
{
   var p = /^(013|014|015|13|14|15|018|18)\d{9}$/;
   if(s.match(p) != null){
  return true;
  }
  return false;
}

function Confirm(){
var SendNum = document.myform.SendNum.value ;
if (SendNum=="" || ismobile(SendNum)==false)
{
alert('请输入有效的手机号码!');
document.myform.SendNum.focus();
return false;
}
if(confirm("确认手机号正确了吗？")){SendSMS();}
}

function SendSMS(){
	var ajaxchk;
	var ajaxstr;
	document.myform.Sendbt.disabled = true;
	$.ajax({type:"get",url:"/Plus/Ajax_SMS.asp",data:"Action=SendSMS&Mobile=" + document.myform.SendNum.value + "&Flag=IDAuthentication&N=2&MC=1&anticache=" + Math.floor(Math.random()*1000),cache:false,dataType:"html",success:function(d){
	var s=unescape(d);
	ajaxchk=s.split('|')[0];
	ajaxstr=s.split('|')[1];
	if (ajaxstr!=null){
		if (ajaxchk=='ok'){alert(ajaxstr);window.location.href="?Action=Send";}
		else{alert(ajaxstr);document.myform.Sendbt.disabled = false;}
	}
} });
}
</script>
<table class=border width="100%" border="0" align="center" cellpadding="2" cellspacing="1">
  <tr>
    <td height="50" align="left"><div id="tips" style="border:1px #A7DDFE solid; width:auto; height:auto; padding:8px; margin:10px 0; background:url(/style/images/msg_bg.png) #ECF8FF no-repeat 10px -490px; padding-left: 55px;"><strong>您还没有进行手机认证！</strong><br />
    只有通过手机认证的会员才可以发布和接手任务，同时通过手机认证可以保护资金和账户的安全，<span class="orange">而且这一切都是免费的。</span></div>
</td>
  </tr>
  <tr> 
    <td height="24" class="chargetitle" align="center"><b>现在进行手机认证——<font color="#FF0000">【送7天VIP会员】</font></b></td>
  </tr>
</table>
<br />
<table class=border width="100%" border="0" align="center" cellpadding="2" cellspacing="1">
  <tr>
    <td height="30" align="center" style="background-color:#CCC; font-size:12px; font-weight:bold; color:#03F;">认证第一步：输入手机号码</td>
    <td height="30" align="center" style="background-color:#f1f1f1; font-size:12px; color:#999;">认证第二步：输入收到的验证码</td>
    <td height="30" align="center" style="background-color:#f1f1f1; font-size:12px; color:#999;">认证第三步：完成</td>
  </tr>
</table>
<br>
    <table class=border width="100%" border="0" align="center" cellpadding="2" cellspacing="1">
    <form name="myform" method="post" action="" onsubmit="Sendbt.click();return false">
      <tr class=tdbg>
          <td height="50" align="right">请输入您手机号码：</td>
          <td><input class="textbox" type="text" name="SendNum" id="SendNum" size="30" maxlength="12" onKeyUp="this.value=this.value.replace(/\D/g,'')"  onafterpaste="this.value=this.value.replace(/\D/g,'')" value="" />
          <input class="button" name="Sendbt" type="button" id="Sendbt" value=" 获取手机短信验证码 " onclick="Confirm()" /></td>
      </tr>
      <tr class=tdbg>
      	  <td align="right">&nbsp;</td>
          <td height="40" align="left" style="color:#999;">此服务<font color="#FF6600">免费</font>，填写手机号后我们将发送一条短信验证码到您的手机。</td>
      </tr>
	<% IF Hour(Now)>21 Or Hour(Now)<7 Then %>
      <tr class=tdbg>
      <td align="left" colspan="2" height="40" style="border:1px #FC6 solid; background:url(/style/images/msg_bg.png) #FFFFF4 no-repeat 10px -690px; color:red; padding-left:50px">
提示：如果您收不到短信，可能原因是：由于手机短信网关运营商有规定每晚22点至次日7点期间暂停短信发送，主要出于短信安全监控和履行国家规定非盈利网站运营的一些规定，但有时还是可以收到短信，所以… 请明早7点后再进行认证，谢谢！</td>
      </tr>
	<% End IF %>
    </form>
	</table>
<% Else %>
<table class=border width="100%" border="0" align="center" cellpadding="2" cellspacing="1">
  <tr>
    <td height="50" align="left"><div id="tips" style="border:1px #A7DDFE solid; width:auto; height:auto; padding:8px; margin:10px 0; background:url(/style/images/msg_bg.png) #ECF8FF no-repeat 10px -590px; padding-left: 55px;"><strong>您的账号已经通过认证！</strong><br />
    您的账号已经通过认证了，不需要重复认证，如果您需要重新绑定手机，请联系客服进行操作。
</div>
</td>
  </tr>
  <tr> 
    <td height="50" align="center"><b>绑定的认证手机号码：<span class="orange"><% KS.Echo Left(KSUser.GetUserInfo("Mobile"),3) & "*****" & Right(KSUser.GetUserInfo("Mobile"),3)%></span></b></td>
  </tr>
</table>
<br />
<%
End IF
End Sub
	   
Sub DoSend()
If KS.IsNul(Session("Mobile")) Then KS.AlertHistory "请不要非法提交，请您先输入手机号!","-1"
%>
<table class=border width="100%" border="0" align="center" cellpadding="2" cellspacing="1">
  <tr>
    <td height="50" align="left"><div id="tips" style="border:1px #A7DDFE solid; width:auto; height:auto; padding:8px; margin:10px 0; background:url(/style/images/msg_bg.png) #ECF8FF no-repeat 10px -490px; padding-left: 55px;"><strong>您还没有进行手机认证！</strong><br />
    只有通过手机认证的会员才可以发布和接手任务，同时通过手机认证可以保护资金和账户的安全，<span class="orange">而且这一切都是免费的。</span></div>
</td>
  </tr>
  <tr> 
    <td height="24" class="chargetitle" align="center"><b>现在进行手机认证</b></td>
  </tr>
</table>
<br />
<table class=border width="100%" border="0" align="center" cellpadding="2" cellspacing="1">
  <tr>
    <td height="30" align="center" style="background-color:#f1f1f1; font-size:12px; color:#999;">认证第一步：输入手机号码</td>
    <td height="30" align="center" style="background-color:#CCC; font-size:12px; font-weight:bold; color:#03F;">认证第二步：输入收到的验证码</td>
    <td height="30" align="center" style="background-color:#f1f1f1; font-size:12px; color:#999;">认证第三步：完成</td>
  </tr>
</table>
<br>
<form name="myform" method="post" action="?Action=Save" onsubmit="return Confirm()">
    <table class=border width="100%" border="0" align="center" cellpadding="2" cellspacing="1">
      <tr class=tdbg>
          <td width="23%" height="40" align="right"><img src="Images/accept.png" width="16" height="16" /></td>
          <td width="77%"><font color="red"><strong>短信已发送到您的手机，请注意查收！</strong></font></td>
      </tr>
      <tr class=tdbg>
          <td height="30" align="right">您的手机号码：</td>
          <td><font color="red"><%=Session("Mobile")%></font></td>
      </tr>
      <tr class=tdbg>
          <td height="30" align="right">验证码：</td>
          <td><input class="textbox" type="text" name="VerifyCode" id="VerifyCode" size="30" maxlength="6" onKeyUp="this.value=this.value.replace(/\D/g,'')"  onafterpaste="this.value=this.value.replace(/\D/g,'')" value="" /></td>
      </tr>
      <tr class=tdbg>
          <td height="80" align="right">&nbsp;</td>
          <td><table width="80%" border="0" cellspacing="0" cellpadding="0" style="border:1px #FC6 solid; background-color:#FFFFF4">
            <tr>
              <td height="60">&nbsp; 如果3分钟内没有收到验证短信，你可以重新获取验证码，此服务免费<br />
&nbsp; <input class="button" name="Sendbt" id="Sendbt" type="button" onclick="SendSMS()" value="" disabled="disabled" /></td>
            </tr>
          </table></td>
      </tr>
      <tr>
        <td colspan=2 height="60" align="center">
        	<input type="hidden" name="Mobile" value="<%=Session("Mobile")%>" />
			<button class="pn" id="submit1" type="submit"><strong>OK, 确 认</strong></button>
		</td>
	  </tr>
	<% IF Hour(Now)>21 Or Hour(Now)<7 Then %>
      <tr class=tdbg>
      <td align="left" colspan="2" height="40" style="border:1px #FC6 solid; background:url(/style/images/msg_bg.png) #FFFFF4 no-repeat 10px -690px; color:red; padding-left:50px">
提示：如果您收不到短信，可能原因是：由于手机短信网关运营商有规定每晚22点至次日7点期间暂停短信发送，主要出于短信安全监控和履行国家规定非盈利网站运营的一些规定，但有时还是可以收到短信，所以… 请明早7点后再进行认证，谢谢！</td>
      </tr>
	<% End IF %>
	</table>
 </form>
<script language="javascript"> 
function SendSMS(){
	var ajaxchk;
	var ajaxstr;
	document.myform.Sendbt.disabled = true;
	$.ajax({type:"get",url:"/Plus/Ajax_SMS.asp",data:"Action=SendSMS&Mobile=<%=Session("Mobile")%>&Flag=IDAuthentication&N=2&MC=1&anticache=" + Math.floor(Math.random()*1000),cache:false,dataType:"html",success:function(d){
	var s=unescape(d);
	ajaxchk=s.split('|')[0];
	ajaxstr=s.split('|')[1];
	if (ajaxstr!=null){
		if (ajaxchk=='ok'){alert(ajaxstr);CheckTime();}
		else{alert(ajaxstr);document.myform.Sendbt.disabled = false;}
	}
} });
}

function Confirm(){
if (document.myform.VerifyCode.value=="" || document.myform.VerifyCode.value.length<6)
{
alert('请输入有效的验证码!');
document.myform.VerifyCode.focus();
return false;
}
return true;
}

var t;
function CheckTime() {
t = 180;	//3分钟
if (t <0 ) t = 0;
document.myform.Sendbt.value= "（" + t + "秒后）重新获取手机短信"
    var uptime = function() {
        t = t - 1;
        if (t <= 0) {
            window.clearInterval(tt_0);
            t = 0;
			document.myform.Sendbt.value= " 重新获取手机短信 ";
			document.myform.Sendbt.disabled=false;
        }else{
        document.myform.Sendbt.value= "（" + t + "秒后）重新获取手机短信"
		}
    }
    var tt_0 = window.setInterval(uptime, 1000);
}
CheckTime();
</script>
<%
End Sub
	   
Sub DoSave()
Dim VerifyCode,Mobile
VerifyCode = KS.R(KS.F("VerifyCode"))
Mobile	=	 KS.R(KS.F("Mobile"))
If KS.ChkClng(KSUser.GroupID) = 1 Then KS.AlertHistory "抱歉！管理员组不能认证，如需要请到后台修改即可!","-1"
IF Not KS.IsNul(VerifyCode) Then
	IF Conn.Execute("Select Top 1 UserID From KS_User Where Mobile='" & Mobile & "' And KS_IDAuthentication=1").Eof Then
		IF Not Conn.Execute("Select Top 1 UserID From KS_User Where CheckNum='" & VerifyCode & "' And UserName='" & KSUser.UserName & "'").Eof Then
			Conn.Execute("UPDate KS_User Set KS_IDAuthentication=1, Mobile='" & Mobile & "' Where UserName='" & KSUser.UserName & "'")		'设为已经手机认证通过
			Conn.Execute("Update KS_User Set CheckNum = '" & KS.MakeRandom(6) & "' Where UserName = '" & KSUser.UserName & "'")				'随时生成字符替换原验证码防止被利用
			IF SMS_IDAuthentication_GiveVIP = 1 Then	'启用认证赠送VIP会员
				Dim UserCardID: UserCardID = GiveVIP_KS_UserCard_ID	'获得赠送VIP会员的线上充值卡的ID号
				Dim RSCard:Set RSCard=conn.execute("select top 1 * From KS_UserCard Where ID="& UserCardID)
				If Not RSCard.Eof Then
					Conn.Execute("Update KS_User Set UserCardID=" & UserCardID & " where username='" & KSUser.UserName & "'")
					Dim ValidNum:ValidNum=RSCard("ValidNum")
					Dim CardTitle:CardTitle=RSCard("GroupName")
					If RSCard("groupid")<>0 Then
					  Conn.Execute("Update KS_User Set GroupID=" & KS.ChkClng(RSCard("GroupID")) & ",ChargeType=" & KS.ChkClng(KS.U_G(RSCard("groupid"),"chargetype")) &" where username='" & KSUser.UserName & "'") 
					End If
					If RSCard("ValidUnit") = 2 Then
						Conn.Execute("Update KS_User Set Edays=" & ValidNum & ",BeginDate=" & SQLNowString& " where username='" & KSUser.UserName & "'") 
						Call KS.EdaysInOrOut(KSUser.UserName,1,ValidNum,"系统","手机认证通过赠送VIP会员")
					End If
				End IF
				RSCard.Close:Set RSCard=Nothing
			End IF
			KS.Alert "恭喜！认证成功！","?"
		Else
			KS.AlertHistory "抱歉！验证码不对，请返回核实或重新获取验证码!","-1"
		End IF
	Else
		KS.AlertHistory "抱歉！该手机号已被认证过了，请更换另一个手机号再试!","-1"
	End IF
End If
End Sub

End Class
%> 