<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
	<HEAD>
		<TITLE> 工商银行电子商务测试页面 </TITLE>
		<meta http-equiv="Content-Type" content="text/html; charset=GBK">
	</HEAD>
<?php
	//加载PHP签名模块，详细
	if (!extension_loaded('infosec'))
	{
		if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN')
		{
			dl('php_infosec.dll');
		}
		else
		{
			dl('infosec.so');
		}
	}
	
	//获取输入
	if(isset($_GET["submit"]))
	{
		//返回商户变量
		$merVAR=$_GET["merVAR"];
		if(strlen($merVAR) <= 0)
		{
			echo "WARNING : no merVAR input<br/>";
			exit();
		}
		
		//获取通知明文
		$notifyData=$_GET["notifyData"];
		if(strlen($notifyData) <= 0)
		{
			echo "WARNING : no notifyData input<br/>";
			exit();
		}

		//获取密文
		$signMsg=$_GET["signMsg"];
		if(strlen($signMsg) <= 0)
		{
			echo "WARNING : no signMsg input<br/>";
			exit();
		}
		
		//获取工行证书
		$bankCertFile="1.cer";
		$fp = fopen($bankCertFile,"rb");
		if($fp == NULL)
		{
			echo "open bankCert file error<br/>";
			exit();
		}
		fseek($fp,0,SEEK_END);
		$filelen=ftell($fp);
		fseek($fp,0,SEEK_SET);
		$bankCert = fread($fp,$filelen);
		fclose($fp);

		//解码签名数据
		$sign = base64dec($signMsg);
		//解码原文
		$plaint = base64dec($notifyData);
		//验签名
		$rv = verifySign(current($plaint),$bankCert,current($sign));
		if($rv)
		{
			$ret = "verify error!";
		}	
		else
		{
			$ret = "verify success!";
		}
	}
?>
	<BODY>
		<font face='Arial' size='4' color='white'>商户接收银行通知信息验签页面</font>
		<table width="98%"  border="1">
			<tr>
				<td width="9%">验签名结果</td>
				<td width="91%"><textarea ID="ret" name="ret" cols="120" rows="5"><?php echo $ret;?></textarea></td>
			</tr>
			<tr>
				<td width="9%">返回商户变量</td>
				<td width="91%"><INPUT ID="merVAR" NAME="merVAR" TYPE="text" value="<?php echo $merVAR;?>" size="120" ></td>
			</tr>
			<tr>
				<td width="9%">通知结果数据</td>
				<td width="91%"><textarea ID="notifyData" name="notifyData" cols="120" rows="5"><?php echo current($plaint);?></textarea></td>
			</tr>
		</table>
	</BODY>
</HTML>