<?php
class Chinabank extends Pay{
	private $info;
	private $path;
	function __construct(){
		$path = str_replace("/Chinabank.class.php","/",str_replace("\\","/",__FILE__));
		$this->path = $path;
	}
	
	function pay($paymentId,$amount,$outTradeNo){
		$domain = $_SERVER['HTTP_HOST'];
		$payConfig = $this->getConfig($paymentId);
		$payConfig['v_url'] = 'http://'.$domain.'/pay/payReturn/chinabank';
		$payConfig['v_moneytype'] = 'CNY';
		$payConfig['gateway'] = $payConfig['gateway']!=''?$payConfig['gateway']:'https://pay3.chinabank.com.cn/PayGate';
		$md5 = $amount.$payConfig['v_moneytype'].$outTradeNo.$payConfig['v_mid'].$payConfig['v_url'].$payConfig['v_key'];
		$payConfig['v_md5info'] = strtoupper(md5($md5));
		$html = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">';
        $html .= '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US" dir="ltr"><head></header><body><div>Redirecting...</div>';
        $html .= '<form id="payment" action="'.$payConfig['gateway'].'" method="post">';
		$html .= '<input type="hidden" name="v_mid"         value="'.$payConfig['v_mid'].'">';
		$html .= '<input type="hidden" name="v_oid"         value="'.$outTradeNo.'">';
		$html .= '<input type="hidden" name="v_amount"      value="'.$amount.'">';
		$html .= '<input type="hidden" name="v_moneytype"   value="'.$payConfig['v_moneytype'].'">';
		$html .= '<input type="hidden" name="v_url"         value="'.$payConfig['v_url'].'">';
		$html .= '<input type="hidden" name="v_md5info"     value="'.$payConfig['v_md5info'].'">';
		$html .= '<input type="hidden" name="remark1"       value="">';
		$html .= '<input type="hidden" name="remark2"       value="">';
		$html .= '<input type="hidden" name="v_rcvname"      value="">';
		$html .= '<input type="hidden" name="v_rcvtel"       value="">';
		$html .= '<input type="hidden" name="v_rcvpost"      value="">';
		$html .= '<input type="hidden" name="v_rcvaddr"      value="">';
		$html .= '<input type="hidden" name="v_rcvemail"     value="">';
		$html .= '<input type="hidden" name="v_rcvmobile"    value="">';
		$html .= '<input type="hidden" name="v_ordername"    value="">';
		$html .= '<input type="hidden" name="v_ordertel"     value="">';
		$html .= '<input type="hidden" name="v_orderpost"    value="">';
		$html .= '<input type="hidden" name="v_orderaddr"    value="">';
		$html .= '<input type="hidden" name="v_ordermobile"  value="">';
		$html .= '<input type="hidden" name="v_orderemail"   value="">';
		$html .= '<input type="submit" value="Pay Submit" />';
		$html .= '</form>';
		$html .= "<script language=\"javascript\">document.getElementById('payment').submit();</script>";
		$html .= '</html>';
		echo $html;exit;
	}

	function payReturn(){
		global $db;	
		$tx = getgpc("tx");
		$amt = getgpc("amt");
		$st = getgpc("st");
		$cc = getgpc("cc");
		$v_oid     =trim(getgpc('v_oid','P'));
		$v_pstatus     =trim(getgpc('v_pstatus','P'));//  支付状态 ：20（支付成功）；30（支付失败）
		$v_amount     =trim(getgpc('v_amount','P'));
		$outTradeNo = $v_oid;
		$paymentId = $db->getOne("select paymentId from qk_onlinepay where outTradeNo='$outTradeNo'");
		load_class("pay");
		$pm = new PayModel();
		$payInfo = $pm->getInfo(array("outTradeNo"=>$outTradeNo));
		if($outTradeNo && $v_amount && $v_pstatus){
			$payConfig = $this->getConfig($paymentId);
			$key=$payConfig['v_key'];
			$v_pmode     =trim(getgpc('v_pmode','P'));
			$v_pstring     =trim(getgpc('v_pstring','P'));
			$v_moneytype     =trim(getgpc('v_moneytype','P'));
			$remark1     =trim(getgpc('remark1','P'));
			$remark2     =trim(getgpc('remark2','P'));
			$v_md5str     =trim(getgpc('v_md5str','P'));
			$md5string = strtoupper(md5($v_oid.$v_pstatus.$v_amount.$v_moneytype.$key));
			if ($v_md5str==$md5string)
			{
				if($v_pstatus=="20")
				{
					$tmp = 'MD5校验码:'.$v_md5str;
					$tmp .= '订单号:'.$v_oid;
					$tmp .= '支付卡种:'.$v_pmode;
					$tmp .= '支付结果:'.$v_pstring;
					$tmp .= '支付金额:'.$v_amount;
					$tmp .= '支付币种:'.$v_moneytype;
					$this->payResult($outTradeNo,$v_amount,$tmp,'');
					return true;
				}else{
					return false;
					echo "支付失败";
				}
			}else{
				echo "<br>校验失败,数据可疑";
			}
		}
	}

	function payNotify(){

	}
}

		/*
			
			Array
		(
			[tx] => 0AP727744C5042443
			[st] => Pending
			[amt] => 42.00
			[cc] => USD
			[cm] => 
			[item_number] => 2012090113223513023
		)
			Array
		(
			[mc_gross] => 42.00
			[protection_eligibility] => Ineligible
			[address_status] => confirmed
			[payer_id] => AQRCNEX52HUJE
			[tax] => 0.00
			[address_street] => 1+Main+St
			[payment_date] => 22%3A23%3A24+Aug+31%2C+2012+PDT
			[payment_status] => Pending
			[terminal_id] => 
			[charset] => windows-1252
			[address_zip] => 95131
			[first_name] => Gao
			[receipt_reference_number] => 
			[mc_fee] => 1.52
			[address_country_code] => US
			[address_name] => Gao+he
			[custom] => 
			[payer_status] => verified
			[business] => admin_1345865115_biz%40qkweb.net
			[address_country] => United+States
			[address_city] => San+Jose
			[quantity] => 1
			[payer_email] => buyer_1346342309_per%40qkweb.net
			[txn_id] => 0AP727744C5042443
			[payment_type] => instant
			[last_name] => he
			[address_state] => CA
			[receiver_email] => admin_1345865115_biz%40qkweb.net
			[store_id] => 
			[payment_fee] => 1.52
			[receiver_id] => C5RFUNVFEYPY6
			[pending_reason] => paymentreview
			[pos_transaction_type] => 
			[txn_type] => web_accept
			[item_name] => Payment%3A2012090113223513023
			[num_offers] => 0
			[mc_currency] => USD
			[item_number] => 2012090113223513023
			[residence_country] => US
			[handling_amount] => 0.00
			[transaction_subject] => Payment%3A2012090113223513023
			[payment_gross] => 42.00
			[shipping] => 0.00
		)
		*/

?>