<?php
	session_start();

	ini_set('session.gc_maxlifetime', 99999999); //设置时间 永不过期
	
	require_once("db/db.php");	
	require_once("common/common.php");
	
	//设置统一语言格式
	header("Content-type: text/html; charset=gb2312"); 
		
	$strwxfwflag=trim($_REQUEST['wxfw']);
	
	$strReturn='0';
	$strSoftID=trim($_REQUEST['softid']);
	$strwxudid=trim($_REQUEST['wxudid']);
	
	$strComUrl='';
	$strCustomID=0;
	
	if(strlen($strSoftID)>0)
	{
		if(strlen($strSoftID)<15)
		{
			$sql = sprintf("SELECT CustomID,HotelURL FROM WX_Hotel_List WHERE CustomID=%s",$strSoftID);
			$result = querySql($sql);
					
			if($row = fetch_array($result))
			{
				$strComUrl=$row['HotelURL'];
				$strCustomID=$row['CustomID'];
			}
			freeResult($result);	//释放数据库
		}
	}
	
	if($strCustomID>0)
	{
		//添加微信记录
		if(strlen($strwxudid)>20)
		{
			$sql= sprintf("IF EXISTS (SELECT ListNo FROM WX_Hotel_User WHERE UserWXID='%s')
							UPDATE WX_Hotel_User SET CustomID=%s,LastTime=GetDate() WHERE UserWXID='%s'
						ELSE
							INSERT INTO WX_Hotel_User(TradeTime,CustomID,UserNo,UserWXID,LastTime) VALUES(GetDate(),%s,'','%s',GetDate())",$strwxudid,$strCustomID,$strwxudid,$strCustomID,$strwxudid);
			executeSql($sql);
		}
	}
	
	closeDb();				//关闭数据库

	if($strwxfwflag=='1')
	{
		$strComUrl=str_ireplace('https:','http:',$strComUrl);
	}
	
	if(strlen($strComUrl)>10)
	{
		$strReturn="1".$strComUrl;
	}
	echo $strReturn;
?>



