<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/9/11
 * Time: 16:49
 * Modified: 2025-11-13 - 升级到 ThinkPHP 6.0
 */

use think\App;
use think\facade\Request;

define('IA_ROOT', '');
error_reporting(E_ERROR);
date_default_timezone_set("Asia/Shanghai");
defined('BASE_ROOT') or define('BASE_ROOT', str_replace('/extend/Wxpay', '', str_replace('\\', '/', realpath(dirname(__FILE__) . '/')) . "/"));
defined('SITE_PATH') or define('SITE_PATH', BASE_ROOT);
defined('PUBLIC_PATH') or define('PUBLIC_PATH', SITE_PATH . 'public/');
define('EXTEND_PATH', BASE_ROOT . 'extend/');
// 定义应用目录
define('APP_PATH', SITE_PATH . 'app/');

// 加载 Composer 自动加载
require_once SITE_PATH . 'vendor/autoload.php';

// 加载自定义配置
if (file_exists(PUBLIC_PATH . 'php/yb.version.php')) {
    require_once PUBLIC_PATH . 'php/yb.version.php';
}

// 引入回调处理类
require_once __DIR__ . '/PayNotifyCallBack.php';

use think\facade\Db;
use think\facade\Log;

// 初始化应用
$http = (new App(SITE_PATH))->http;
$response = $http->run();
$request = Request::instance();

try {
    // 记录回调日志
    Log::write('微信支付回调开始', 'info');

    // 处理回调数据 - Handle() 方法会自动从 php://input 读取数据
    $notify = new \PayNotifyCallBack();
    Log::write('创建 PayNotifyCallBack 实例完成', 'info');
    $notify->Handle();
    Log::write('Handle 方法执行完成', 'info');

} catch (\Exception $e) {
    Log::error('微信回调异常: ' . $e->getMessage());
    Log::error('异常堆栈: ' . $e->getTraceAsString());
    echo 'fail';
}