<?php
/**
 * 支付同步回调
 */
require_once dirname(__DIR__, 2) . '/config.php';
require_once dirname(__DIR__, 2) . '/vendor/epay/config.php';

$pay_config = json_decode(getSiteConfig('payment_config') ?? '{}', true);
$key = $pay_config['key'] ?? '2LZ3NAkLVBixGcfz4oMz';

$money = $_GET["money"] ?? '';
$name = $_GET["name"] ?? '';
$pid = $_GET["pid"] ?? '';
$out_trade_no = $_GET["out_trade_no"] ?? '';
$trade_no = $_GET["trade_no"] ?? '';
$trade_status = $_GET["trade_status"] ?? '';
$type = $_GET["type"] ?? '';
$param = $_GET["param"] ?? '';
$sign_type = $_GET["sign_type"] ?? '';
$sign = $_GET["sign"] ?? '';

$arr = array(
    "pid" => $pid,
    "type" => $type,
    "out_trade_no" => $out_trade_no,
    "trade_no" => $trade_no,
    "name" => $name,
    "money" => $money,
    "param" => $param,
    "trade_status" => $trade_status,
    "sign_type" => $sign_type
);

if ($sign == get_sign($arr, $key)) {
    header("Location: " . SITE_URL . "modules/payment/success.php?order_no=" . $out_trade_no . "&amount=" . $money . "&type=" . $type);
} else {
    header("Location: " . SITE_URL . "modules/payment/success.php?status=failed");
}
exit;
?>