<?php
error_reporting(0);
include "../../config/ht.php";
require_once("lib/alipay_submit.class.php");
$code=ubo(base64_decode($_GET[code]));
$paylx=$_GET[lx];
if (strpos($code, "|ubo|") !== false) {
$p= explode("|ubo|",$code); 
$ddh=$p[0];//提交的订单号
$money=$p[1];//提交的支付金额
$userid=$p[2];//提交的用户ID
$shipinid=$p[3];//提交的资源ID
$lx=$p[4];//
$ip=$p[5];//
$ddhto=$p[6];
$payid=$p[7];
}
//调用接口
$type="where biaoshi='$paylx'";
$hzpay=queryall(hzpay,$type);
if($hzpay[zt]==1){
$type="WHERE biaoshi='$paylx'";
$hzpayto=queryall(hzpayto,$type);
if($hzpayto){
if($hzpayto[sz]==1){
$type="where biaoshi='$paylx'  and userid='$userid'";
$hzpaylist=queryall(hzpaylist,$type);
if($hzpaylist){
if($hzpaylist[sz]==1){
$payid=$hzpaylist[payid];//商户ID
$paykey=$hzpaylist[paykey];//商户秘钥
$payurl=$hzpaylist[payurl];//支付网关
$blx='hzpaylist';
}else{
echo '代理通道已被停止使用';
exit;
}
}else{
echo '代理通道未添加';
exit;
}
}else{
echo '通道未启用';
exit;
}
}else{
echo '通道不存在';
exit;
}
}else{
$type="WHERE biaoshi='$paylx' and  zt='1' and sz='1'";
$hzpayto=queryall(hzpayto,$type);
if($hzpayto){
$payid=$hzpayto[payid];//商户ID
$paykey=$hzpayto[paykey];//商户秘钥
$payurl=$hzpayto[payurl];//支付网关
$blx='hzpayto';
}else{
echo '通道未设置默认接口';
exit;
}
}
//这里插入支付///------------------------------------------------------------统一配置
$back="http://".$_SERVER["HTTP_HOST"]."/check-".$ddh.".html";//这是同步跳转地址
$tzurl="http://".$_SERVER["HTTP_HOST"]."/hzpay/".$paylx."/tzurl.php";//这是异步通知地址
$ddmulu="../../".date("Y-m-d")."ddh";
mkdir ($ddmulu);
$ddmulu2="../../".date("Y-m-d",strtotime("-1 day"))."ddh";
del_dir($ddmulu2);
$ddhcj = $ddmulu."/".$ddh.".txt";
if (file_exists($ddhcj)) {
}else{
$ddhwb =$ddh."|ubo|".$money."|ubo|".$userid."|ubo|".$shipinid."|ubo|".$lx."|ubo|".$ip."|ubo|".$ddhto."|ubo|".$hzpaylist[id]."|ubo|".$_SERVER["HTTP_HOST"]."|ubo|".$paylx."|ubo|".$blx;
writefile($ddhcj,$ddhwb);
}
$alipay_config["partner"]=$payid;
$alipay_config["seller_id"]= $alipay_config["partner"];
$alipay_config["key"]=$paykey;
$alipay_config["sign_type"]= strtoupper("MD5");
$alipay_config["input_charset"]= strtolower("utf-8");
$alipay_config["cacert"]= getcwd()."\cacert.pem";
$alipay_config["transport"]= "http";
$alipay_config["payment_type"] = "1";
$alipay_config["service"] = "alipay.wap.create.direct.pay.by.user";
$show_url ="";
$parameter = array(
"service"=>$alipay_config['service'],
"partner"=>$alipay_config['partner'],
"seller_id"=>$alipay_config['seller_id'],
"payment_type"=>$alipay_config['payment_type'],
"notify_url"=>$tzurl,
"return_url"=>$back,
"_input_charset"=>trim(strtolower($alipay_config['input_charset'])),
"out_trade_no"=>$ddh,
"subject"=>$ddh,
"total_fee"=>$money,
"show_url"=>$show_url,
"app_pay"=> "Y",//启用此参数能唤起钱包APP支付宝
"body"=>$ddh,
);
$alipaySubmit = new AlipaySubmit($alipay_config);
$payurl= $alipaySubmit->buildRequestForm($parameter,"get", "确认");
header ("location:$payurl");
?>