<?php
require_once(SYS_ROOT."/tool/api_pay/tenpay/tenpay_service.php");
class cls_tool_api_pay
{
	function on_pay($arr_fields=array())
	{
		$arr_return=array("err"=>"","url"=>"");
		if(!isset($arr_fields["parterid"])){
			$arr_return["err"]="合作伙伴ID不能为空！";
			return $arr_return;
		}
		if(!isset($arr_fields["key"])){
			$arr_return["err"]="安全检验码不能为空！";
			return $arr_return;
		}
		if(!isset($arr_fields["subject"])){
			$arr_return["err"]="支付标题不能为空！";
			return $arr_return;
		}
		if(!isset($arr_fields["orders_number"])){
			$arr_return["err"]="订单号不能为空！";
			return $arr_return;
		}
		if(!isset($arr_fields["goods_price"])){
			$arr_return["err"]="支付价格不能为空！";
			return $arr_return;
		}
		if(!isset($arr_fields["detail"])) $arr_fields["detail"]=$arr_fields["subject"];
		$arr_fields["goods_price"]=$arr_fields["goods_price"]*100;
		$tenpay = new tenpay_online_payment;
		$link = $tenpay->tenpay_interface_pay ($arr_fields["subject"],$arr_fields["goods_price"],"","0",$arr_fields["detail"],$arr_fields["orders_number"],$arr_fields);
		if(stristr($link,"http")){
			$arr_return["url"]="<script>window.open('".$link."','_self');</script>";
		}else{
			$arr_return["err"]=$link;
		}
		return $arr_return;
	}

	//财付通字段
	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;
	}

}
?>