<?php

include "inc.php";
require_once SYS_ROOT.'/cls_tab/tab.pay.type.php';
$obj_tab_type=new cls_tab_pay_type;
$base_dir=$obj_tab_type->api_dir;

$arr_config=$obj_tab_type->get_type_fields("99bill");

$merchant_key=$arr_config["key"];

$merchant_id =trim($_REQUEST['merchant_id']);    ///获取商户编号
$orderid = trim($_REQUEST['orderid']);   ///获取订单编号
$amount = trim($_REQUEST['amount']); ///获取订单金额
$dealdate = trim($_REQUEST['date']);   ///获取交易日期
$succeed = trim($_REQUEST['succeed']); ///获取交易结果,Y成功,N失败
$mac = trim($_REQUEST['mac']);   ///获取安全加密串
$merchant_param = trim($_REQUEST['merchant_param']);   ///获取商户私有参数

$couponid = trim($_REQUEST['couponid']);   ///获取优惠券编码
$couponvalue = trim($_REQUEST['couponvalue']);   ///获取优惠券面额

///生成加密串,注意顺序
   $ScrtStr = "merchant_id=".$merchant_id."&orderid=".$orderid."&amount=".$amount."&date=".$dealdate."&succeed=".$succeed."&merchant_key=".$merchant_key; 
   $mymac = md5($ScrtStr); 

if(strtoupper($mac)==strtoupper($mymac)){
    if($succeed=="Y"){   ///支付成功
     /*
     #商户网站逻辑处理#
     */
		$arr_pay_return=array(
			"number"=>$orderid,
			"pay_money"=>$amount
		);
		$obj_tab_type->on_pay_ok($arr_pay_return);
		$show = $obj_tab_type->pay_ok_url;
		go_url($show);
    }else{   ///支付失败 
		echo "<br/>" . "支付失败" . "<br/>";
		set_log("99bill","支付失败",array(),true);
    }

} else {
    //验证失败
	echo "<br/>" . "认证签名失败" . "<br/>";
	set_log("99bill","fail",array(),true);
}
?>