<?php
$lane=getenv('GP_LANE');$root=getenv('GP_ROOT');$path=parse_url($_SERVER['REQUEST_URI'],PHP_URL_PATH);
if(!in_array($lane,['B','C'],true)||(!in_array($path,['/p/accountSetting/giftFlowList','/p/walletFlow/list'],true)&&$path!=='/__poc_boundary')){http_response_code(403);exit;}
if($path!=='/__poc_boundary'&&$_SERVER['REQUEST_METHOD']!=='POST'){http_response_code(405);exit;}
$_SERVER['PATH_INFO']=$path;require $root.'/env.php';require $root.'/external_stubs.php';
if(!function_exists('json')){function json($data=[],$code=200,array $header=[],$options=[]){return \think\Response::create($data,'json',$code,$header,$options);}}
define('APP_PATH',__DIR__.'/source/application/');define('RUNTIME_PATH',__DIR__.'/runtime/');require $root.'/thinkphp/base.php';\think\App::initCommon();\think\Request::instance()->pathinfo();
\think\Log::init(['type'=>'File','path'=>__DIR__.'/runtime/safe-log/','level'=>['no_raw_application_log']]);\think\Config::set(['type'=>'File','path'=>__DIR__.'/cache/','prefix'=>'GW11_'],'cache');\think\Config::set('redis',[]);$database=require $root.'/application/database.php';\think\Config::set($database,'database');\think\Db::clear();
if($path==='/__poc_boundary'){header('Content-Type: application/json');echo json_encode(['lane'=>$lane,'redis_disabled'=>\think\Config::get('redis')===[],'real_queue'=>getenv('POC_REAL_QUEUE'),'store_id'=>getStoreId(),'account_source'=>hash_file('sha256',APP_PATH.'p/logic/AccountSetting.php'),'wallet_source'=>hash_file('sha256',APP_PATH.'p/logic/WalletFlow.php')]);exit;}
$safeLabel=$_SERVER['HTTP_X_GW_LABEL']??'';if(!preg_match('/^[a-z0-9-]{1,50}$/D',$safeLabel)){http_response_code(403);exit;}
$audit=[];\think\Db::listen(static function($sql,$time,$explain)use(&$audit){$items=[];foreach(['store'=>\think\Db::connect(),'ai'=>get_ai_db()]as $k=>$db){$ref=new ReflectionObject($db);if(!$ref->hasProperty('PDOStatement'))continue;$prop=$ref->getProperty('PDOStatement');$prop->setAccessible(true);$stmt=$prop->getValue($db);if($stmt instanceof PDOStatement)$items[$k]=['queryString'=>$stmt->queryString,'listener'=>$sql];}$audit[]=$items;});
register_shutdown_function(static function()use(&$audit,$safeLabel,$lane){$file=__DIR__.'/private-evidence/sql-http-'.$lane.'-'.$safeLabel.'.json';file_put_contents($file,json_encode($audit,JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE));chmod($file,0600);});
\think\App::run()->send();
