<?php
$lane=getenv('MR3_LANE');$root=getenv('MR3_ROOT');$expected=$lane==='B'?'/tmp/zhct-http-store-mysql.dQTTBP':'/tmp/zhct-dm-poc-20260928.fcpiiN/store';
if(!in_array($lane,['B','C'],true)||$root!==$expected||is_link($root)){http_response_code(503);exit;}
$path=parse_url($_SERVER['REQUEST_URI'],PHP_URL_PATH);$allowed=['/p/rechargeOrder/add','/api/consume/orderPay','/p/mealOrder/refund','/p/mealOrder/refundAgree'];
if($path!=='/__poc_boundary'&&(!in_array($path,$allowed,true)||$_SERVER['REQUEST_METHOD']!=='POST')){http_response_code(403);exit;}
$_SERVER['PATH_INFO']=$path;require $root.'/env.php';if(!function_exists('json')){function json($data=[],$code=200,array $header=[],$options=[]){return \think\Response::create($data,'json',$code,$header,$options);}}
if(getenv('POC_EXTERNAL_STUBS')!=='1'||getenv('POC_REAL_QUEUE')!=='0'){http_response_code(503);exit;}require $root.'/external_stubs.php';
$sourceRoot=__DIR__.'/source';if(!is_dir($sourceRoot.'/application')||is_link($sourceRoot.'/application')){http_response_code(503);exit;}
define('APP_PATH',$sourceRoot.'/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'=>'CENT10_','cache_subdir'=>false],'cache');
// Project-supported File fallback only in this private worker. Never touch shared Redis keys.
\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(['private_file_cache'=>true,'redis_disabled'=>\think\Config::get('redis')===[],'external_stubs_configured'=>class_exists(\app\common\Serve::class,false)&&class_exists(\app\api\service\xpyun\Xpyun::class,false)&&class_exists(\app\common\service\wanyisheng\Dispatcher::class,false),'real_queue'=>false,'allowlist'=>'cent-cash-local-wallet-only','business'=>(string)\think\Config::get('business'),'original_debug'=>$database['debug']??null,'real_settlement_source'=>strpos((new ReflectionClass(\app\common\service\account\AccountSettlementService::class))->getFileName(),$sourceRoot.'/application/')===0]);exit;}
if(in_array($path,['/p/rechargeOrder/add','/api/consume/orderPay','/p/mealOrder/refund'],true)){
 $file=__DIR__.'/private-request-order-no.json';$lock=json_decode((string)@file_get_contents($file),true);$nonce=$_SERVER['HTTP_X_RFJ_FIXTURE_NONCE']??'';
 if(!is_array($lock)||!is_string($nonce)||!hash_equals($lock['nonce']??'',$nonce)||($lock['path']??'')!==$path||!preg_match('/^CDXCENT[BC][A-F0-9]{8}[CRF]$/D',$lock['order_no']??'')){http_response_code(403);exit;}
 unlink($file);\app\common\service\Order::forceNextOrderNo($lock['order_no']);
}
\think\App::run()->send();
