<?php

//---------------------------------------------------------
//�Ƹ�ͨ��ʱ����֧��Ӧ�𣨴���ص�ʾ���̻����մ��ĵ����п�������
//---------------------------------------------------------

require_once ("./classes/PayResponseHandler.class.php");
$arr=include("../Conf/config.php");
 define("_UL_", $_SERVER['SERVER_NAME']);
/* ��Կ */
$key = $arr["KUAIQIAN_BUKEY"];

/* ����֧��Ӧ����� */
$resHandler = new PayResponseHandler();
$resHandler->setKey($key);

//�ж�ǩ��
if($resHandler->isTenpaySign()) {
	
	//���׵���
	$transaction_id = $resHandler->getParameter("transaction_id");
	
	//���,�Է�Ϊ��λ
	$total_fee = $resHandler->getParameter("total_fee");
	
	//֧�����
	$pay_result = $resHandler->getParameter("pay_result");
	
	//�̻����׺�
	$sp_billno=$resHandler->getParameter("sp_billno");
	
	if( "0" == $pay_result ) {
	
		//------------------------------
		//����ҵ��ʼ
		//------------------------------
	
			@mysql_connect($arr["DB_HOST"].":".$arr["DB_PORT"],$arr["DB_USER"],$arr["DB_PWD"]);
			@mysql_select_db($arr["DB_NAME"]);
			$sql="update ".$arr["DB_PREFIX"]."_m_order set orderstate=1,paytime='".date('Y-m-d H:i:s')."'  where orderid='".$sp_billno."'";
			mysql_query($sql);
		
		//------------------------------
		//����ҵ�����
		//------------------------------	
		
		//����doShow, ��ӡmetaֵ��js����,���߲Ƹ�ͨ����ɹ�,�����û��������ʾ$showҳ��.
		$show = "http://"._UL_."/index.php/home/paystate/suno";
		$resHandler->doShow($show);
	
	} else {
		//����ɹ�����
		echo "<script language='javascript'>location.href='http://"._UL_."/index.php/home/paystate/err'</script>";
	}
	
} else {
	echo "<script language='javascript'>location.href='http://"._UL_."/index.php/home/paystate/err'</script>";
}

//echo $resHandler->getDebugInfo();

?>