<?php
class cls_tool_api_pay
{
	function on_pay($arr_fields=array()){
		if(!isset($arr_fields["parterid"])) return "商户号不能为空！";
		if(!isset($arr_fields["key"])) return "MD5密钥不能为空！";
		if(!isset($arr_fields["orderid"])) return "定单号不能为空！";
		if(!isset($arr_fields["price"])) return "金额不能为空！";
		if(!isset($arr_fields["return_url"])) return "支付返回地址不能为空！";
		$arr_fields["moneytype"]="CNY";
		//以下几项项为网上支付完成后，随支付反馈信息一同传给信息接收页
		$arr_fields["remark1"]="";
		$arr_fields["remark2"]="";
		//md5加密拼凑串,注意顺序不能变
		$str_text = $arr_fields["price"].$arr_fields["moneytype"].$arr_fields["orderid"].$arr_fields["parterid"].$arr_fields["return_url"].$arr_fields["key"]; 
		$str_md5info = strtoupper(md5($str_text));                             //md5函数加密并转化成大写字母
		$str_content='<form method="post" name="frm_chinabank" action="https://pay3.chinabank.com.cn/PayGate">';
		$str_content.='<input type="hidden" name="v_mid" value="'.$arr_fields["parterid"].'">';
		$str_content.='<input type="hidden" name="v_oid" value="'.$arr_fields["orderid"].'">';
		$str_content.='<input type="hidden" name="v_amount" value="'.$arr_fields["price"].'">';
		$str_content.='<input type="hidden" name="v_moneytype" value="'.$arr_fields["moneytype"].'">';
		$str_content.='<input type="hidden" name="v_url" value="'.$arr_fields["return_url"].'">';
		$str_content.='<input type="hidden" name="v_md5info" value="'.$str_md5info.'">';
		$str_content.='<input type="hidden" name="remark1" value="'.$arr_fields["remark1"].'">';
		$str_content.='<input type="hidden" name="remark2" value="'.$arr_fields["remark2"].'">';
		$str_content.='</form>';
		global $obj_msg;
		$obj_msg->js("window.onload=function(){document.frm_chinabank.submit();}");
		return $str_content;
	}

	//易付宝字段
	function get_fields_html($arr_fields=array())
	{
		(!isset($arr_fields["parterid"]))?$parterid="":$parterid=$arr_fields["parterid"];
		(!isset($arr_fields["key"]))?$key="":$key=$arr_fields["key"];
		(!isset($arr_fields["rates"]))?$rates="":$rates=$arr_fields["rates"];
		$str_info="";
$str_info=<<<HTML
<tr><td class="pTabColName">货币类型：</td><td class="pTabColVal">人民币(￥)<input type="hidden" name="pay_fields_currency" value="人民币(￥)"></td></tr>
<tr><td class="pTabColName">客户号：</td><td class="pTabColVal"><input type="text" name="pay_fields_parterid" value="$parterid"></td></tr>
<tr><td class="pTabColName">私钥：</td><td class="pTabColVal"><input type="text" name="pay_fields_key" value="$key"></td></tr>
<tr><td class="pTabColName">支付费率：</td><td class="pTabColVal"><input type="text" name="pay_fields_rates" value="$rates"></td></tr>
HTML;
		return $str_info;
	}
	function set_fields_value()
	{
		$arr_fields["currency"]=$_POST["pay_fields_currency"];
		$arr_fields["parterid"]=$_POST["pay_fields_parterid"];
		$arr_fields["key"]=$_POST["pay_fields_key"];
		$arr_fields["rates"]=$_POST["pay_fields_rates"];
		$str_info="";
		$str_x="";
		foreach($arr_fields as $item=>$key)
		{
			$str_x=$item."=".$key;
			if($str_info==""){
				$str_info=$str_x;
			}else{
				$str_info.="|".$str_x;
			}
		}
		return $str_info;
	}

}
?>