<?php
include_once('nusoap/lib/nusoap.php');

define('IN_MY', TRUE);
include_once('../data/config/msg.config.php');

$client = new nusoap_client('http://117.79.237.16/webservice.asmx?wsdl',true); 
//$client = new soapclient('http://sdk2.entinfo.cn/webservice.asmx?wsdl',true); 
$client->soap_defencoding = 'GB2312';
$client->decode_utf8 = false;

$sn=$MyMsg["account"]; 
$password=$MyMsg["password"];
$pwd=strtoupper(md5($sn.$password));
$mobile=$_REQUEST['mobile'];//$_REQUEST['mobile']手机号
$content='';//内容
$ext=''; //扩展码，可为空
$stime=$_REQUEST['stime'];//定时时间,可为空
$rrid= iconv( "UTF-8", "gb2312//IGNORE" , '预订易'); //唯一标志码，如果为空，将返回系统生成的标志码
$findCode=$_REQUEST['findCode'];

$path = explode('/' , $_SERVER['PHP_SELF']);
$path = $path[0] ? $path[0] : $path[1];
$path = '';
$s_name = 'http://'.$_SERVER['SERVER_NAME'];

if($_REQUEST['type'] == 'regsend')
{
	$mobile = $_POST['member_name'];
	$content = str_replace('{Content}' , '账号:' . $mobile . ' 密码:'.$_POST['num'], $MyMsg['registr']);
	$content =  iconv( "UTF-8", "gb2312//IGNORE" , $content);;
	
	$parameters=array("sn"=>$sn,"pwd"=>$pwd,"mobile"=>$mobile,"content"=>$content,"ext"=>$ext,"stime"=>$stime,"rrid"=>$rrid);
	$str=$client->call('mt',array('parameters' =>$parameters), '', '', false, true,'document','encoded'); 
	echo "<script>window.parent.location.href = '". $s_name . '/' .$path . "?m=ktv.ktvMmember'</script>";
	exit;
}


if($_REQUEST['type'] == 'regcode')
{
	session_start();

	if(!$_SESSION['msgcode'])
	{
		echo '1';
		exit;
	}
	
	if($_REQUEST['send_code'])
	{
		if($_SESSION['msgcode'] && $_SESSION['msgcode'] != $_REQUEST['send_code'])
		{
			echo '1';
		
			exit;
		}
		echo 2;
		exit;
	}
}

if($_REQUEST['type'] == 'sendMap')
{
	session_start();
	
	

	if(!$_SESSION[$_POST['mobile']])
	{
		$_SESSION[$_POST['mobile']] = 1;
	}else{
		$_SESSION[$_POST['mobile']]++;
	}
	
	
	
	if($_SESSION[$_POST['mobile']] > 3)
	{
	
		echo '<font style="font-size:14"; color="#9E9E9E">'.iconv( "UTF-8", "gb2312//IGNORE" , '对不起,规定时间内只能发3条,请过一段时间再发。') .'</font>'  ;
		exit;
	}
	


	
	if($_REQUEST['order_title'])
	{
		$content = $_REQUEST['order_title'];
		$mobile = $_POST['mobile'];

		$parameters=array("sn"=>$sn,"pwd"=>$pwd,"mobile"=>$mobile,"content"=>$content,"ext"=>$ext,"stime"=>$stime,"rrid"=>$rrid);
		
	
		$str=$client->call('mt',array('parameters' =>$parameters), '', '', false, true,'document','encoded'); 
		echo '<font style="font-size:14"; color="#9E9E9E">'.iconv( "UTF-8", "gb2312//IGNORE" , '短信已经发送成功,请注意查收') .'</font>'  ;

		exit;
	}
}


if($_REQUEST['type'] == 'code')
{
	
	$rand = '1234567890';
	for($i=0;$i<6;$i++)
	{
		$str .= $rand[rand(0,strlen($rand) - 1)];
	}
	
	
	$content = str_replace('{Content}' , $_COOKIE['msgcode'] ? $_COOKIE['msgcode'] : $str , $MyMsg["retrieve_code"]);
	session_start();
	unset($_SESSION['msgcode']);
	if(!$_SESSION['msgcode'])
	{
		$_SESSION['msgcode'] =  $str;
	}
	$content =  iconv( "UTF-8", "gb2312//IGNORE" , $content);
	$parameters=array("sn"=>$sn,"pwd"=>$pwd,"mobile"=>$mobile,"content"=>$content,"ext"=>$ext,"stime"=>$stime,"rrid"=>$rrid);
	
	
	
	$str=$client->call('mt',array('parameters' =>$parameters), '', '', false, true,'document','encoded'); 
	
	echo "<script>window.location.href = 'sendsms.php?type=msgCode&cName=code&mobile=".$mobile."'</script>";
	exit;

}



if($_REQUEST['type'] == 'findcode')	
{


	if($_COOKIE['findcode'] && $_COOKIE['findcode'] != $_POST['findcode'])
	{
		
		$m_content =  iconv( "UTF-8", "gb2312//IGNORE" , '验证码错误');
		echo "<script>alert('".$m_content."');</script>";
		echo "<script>window.location.href = 'sendsms.php?type=findcode&mobile=".$_REQUEST['mobile']."'</script>";
	}else
	{

		unset($_COOKIE['findcode']);

		echo "<script>window.location.href = 'sendsms.php?type=editpwd&mobile=".$_REQUEST['mobile']."'</script>";
	}
	exit;
}

if($_REQUEST['type'] == 'search_code')
{
	unset($_COOKIE['findcode']);
	
	$rand = '1234567890';
	for($i=0;$i<6;$i++)
	{
		$str .= $rand[rand(0,strlen($rand) - 1)];
	}

	
	$content = str_replace('{Content}' , $_COOKIE['findcode'] ? $_COOKIE['findcode'] : $str , $MyMsg["retrieve"]);
	
	if(!$_COOKIE['findcode'])
	{
		setcookie('findcode' , $str , time() + 6000);
	}
	
	
	$content =  iconv( "UTF-8", "gb2312//IGNORE" , $content);

	$parameters=array("sn"=>$sn,"pwd"=>$pwd,"mobile"=>$mobile,"content"=>$content,"ext"=>$ext,"stime"=>$stime,"rrid"=>$rrid);
	$str=$client->call('mt',array('parameters' =>$parameters), '', '', false, true,'document','encoded'); 

	echo "<script>window.location.href = 'sendsms.php?type=findcode&cName=findCode&mobile=".$mobile."'</script>";
}
	

if($_REQUEST['type'] == 'find')
{

	$order_title =  $_REQUEST['order_title'];// str
	$content = str_replace('{Name}' ,$_REQUEST['member_name'] , $MyMsg["downOrder"]);
	$content = str_replace('{orderNum}' ,$_REQUEST['num'] , $content);
	$content = str_replace('{time}' ,$_REQUEST['times'] . ' ' . $_REQUEST['begin_time'] . '点前' , $content);
	$content = str_replace('{Content}' ,iconv( "gb2312", "UTF-8" , $order_title)  , $content);
	$content =  iconv( "UTF-8", "gb2312//IGNORE" , $content);
	
	
	
	$parameters=array("sn"=>$sn,"pwd"=>$pwd,"mobile"=>$mobile,"content"=>$content,"ext"=>$ext,"stime"=>$stime,"rrid"=>$rrid);
	$str=$client->call('mt',array('parameters' =>$parameters), '', '', false, true,'document','encoded'); 
	echo "<script>window.parent.location.href = '". $s_name . '/' .$path . "order/ktvInfo-".$_REQUEST['num2'].".html'</script>";


	exit;
	
	
	
}



if($_REQUEST['type'] == 'cancelOrder')
{
	session_start();
	$m_info = unserialize($_SESSION['my_memberLoginInfo']);
	
	
	if($MyMsg["is_msg"] && $MyMsg["is_cancel"])
	{


		$content = $MyMsg["cancel"];//内容
		$c_arr = array('{Name}'  , '{Content}' , '{orderNum}', '{Time}' );
		$s_arr = array($m_info['name']  , $_REQUEST['ordertitle'] , $_REQUEST['num'],  date('Y-m-d h:i:s',time()));
		$content = str_replace($c_arr , $s_arr , $content);
		$content =  iconv( "UTF-8" , "gb2312//IGNORE" , $content);


		$mobile = $_REQUEST['member_name'];
		
		$parameters=array("sn"=>$sn,"pwd"=>$pwd,"mobile"=>$mobile,"content"=>$content,"ext"=>$ext,"stime"=>$stime,"rrid"=>$rrid);
		
	
		
		$str=$client->call('mt',array('parameters' =>$parameters), '', '', false, true,'document','encoded'); 
		

		echo "<script>window.parent.location.href = '". $s_name . '/' .$path . "?m=ktv.ktvMmember&type=order'</script>";

	}

}








?>
