<?php
require_once("99bill_service.php");
class cls_tool_api_pay
{
	function on_pay($arr_fields=array())
	{
		$arr_return=array("url"=>"","err"=>"");
		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;
		}
		$arr_fields["goods_price"]=$arr_fields["goods_price"]*100;
		$bill99 = new bill99_service;
		$str_url = $bill99->get_link($arr_fields);
		if($str_url!=""){
			$arr_return["url"]="<script>window.open('".$str_url."','_blank');</script>";
		}else{
			$arr_return["err"]="支付接口调用失败！";
		}
		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;
	}

}
?>