<?php
error_reporting(0);
include "../../config/ht.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);
}
$paycode=base64_encode($ddh.'|ubo|'.$money.'|ubo|'.$hzpaylist[id].'|ubo|'.$paylx.'|ubo|'.$blx);
$callback="http://".$_SERVER["HTTP_HOST"]."/hzpay/ysf/wx.php?code=".$paycode;
$payurl='https://1shanghu.com/v2/wechat/login?app_key='.$paykey.'&sub_mch_id='.$payid.'&callback='.$callback; 
header ("location:$payurl");
?>