<?php
	session_start();
	
	require_once("db/db.php");	
	require_once("common/common.php");

	$strroomkey=trim($_REQUEST['rmid']);
	$intstate=0;
	$checksum=0;
	$sumval=0;
		
	$strwxid=trim($_SESSION["main_wxudid"]);
	if(strlen($strwxid)>16)
	{	
		if(strlen($strroomkey)==13)
		{
			//开始创建
			//1.判断输入的验证码是否合法
			//C2N1H2X3M1X2H1M2X4S2X1S1C1
			$bidlen=substr($strroomkey,1,1);	//系统住房流水号的长度1至4
			
			$checksum=substr($strroomkey,12,1).substr($strroomkey,0,1);
			//2.得到单据时间HH:MM:SS
			$billtime=substr($strroomkey,6,1).substr($strroomkey,2,1).':'.substr($strroomkey,4,1).substr($strroomkey,7,1).':'.substr($strroomkey,11,1).substr($strroomkey,9,1);
			//3.根据输入的KEY得到流水号后4位
			$strbid=substr($strroomkey,10,1).substr($strroomkey,5,1).substr($strroomkey,3,1).substr($strroomkey,8,1);
			//4.判断校验和是否正确
			$sumval=substr($strroomkey,1,1) + substr($strroomkey,2,1) + substr($strroomkey,3,1) + substr($strroomkey,4,1) + substr($strroomkey,5,1) + substr($strroomkey,6,1) + substr($strroomkey,7,1) + substr($strroomkey,8,1) + substr($strroomkey,9,1) + substr($strroomkey,10,1) + substr($strroomkey,11,1);
			if($checksum==$sumval)
			{
				if($bidlen==3)
				{
					$strbid=substr($strbid,1,3);
				}
				if($bidlen==2)
				{
					$strbid=substr($strbid,2,2);
				}
				if($bidlen==1)
				{
					$strbid=substr($strbid,3,1);
				}
				
				$sql = sprintf("EXECUTE TRS_WebWeiXinAndRoom '%s','%s','%s','%s'",$strwxid,$strroomkey,$strbid,$billtime);
				$result = querySql($sql);
				$row = fetch_array($result);
				$retval= $row['retval'];
				//1.2验证码不正确，3
				freeResult($result);
				closeDb();
				if($retval==0)
				{
					$intstate=1;
				}
				else
				{
					$intstate=2;
				}
			}
			else
			{
				$intstate=2;
			}
		}
		else
		{	//验证码不合法
			$intstate=2;
		}
	}
	else
	{
		$intstate=3;
	}
	//echo "<script>window.location.href='roomlist.php';</script>";
?>

<html>
<head>
	<meta charset="gb2312">	
	<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0"/>
	<meta name="apple-mobile-web-app-capable" content="1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="format-detection" content="telephone=0">
	<meta name="apple-touch-fullscreen" content="1">
	<title>提交关联住房</title>
	<script src="jsp4/jquery.js"></script>
	<link rel="stylesheet" href="css/mycss.css"> 
	
	<script>
		setTimeout("window.location='roomlist.php'",1000);
	</script>

	<script language="JavaScript"> 
		//不允许进行后退
		javascript:window.history.forward(0); 
	</script>
</head>

<body leftmargin="0" rightmargin="0" topmargin="0" bottommargin="0">
&nbsp;<br>
<center><span style='color:green;font-size:22px'><b>
	<?php if($intstate==1) { ?>
	提交成功！
	<?php } 
		elseif($intstate==2) 
		{
	?>
	验证码错误！
	<?php }
		elseif($intstate==3) 
		{
	?>
	关联微信失败！
	<?php }
		else
		{
	?>
	提交失败！
	<?php } ?>
</b></span></center>
<p>
</body>

</html>


