make(Illuminate\Contracts\Console\Kernel::class)->bootstrap(); use Illuminate\Support\Facades\{DB,Cache,Http,Mail,Queue}; use App\Models\{User,Plan,Order,Payment}; if(DB::connection()->getDatabaseName()!=='fuc_xb_test')throw new RuntimeException('Wrong database'); config(['cache.stores.redis'=>['driver'=>'array'],'cache.default'=>'redis']);Cache::purge('redis');$app->forgetInstance(App\Support\Setting::class); Mail::fake();Queue::fake()->except([App\Jobs\OrderHandleJob::class]);Http::preventStrayRequests(); $checks=[];$cashiers=[];$auth=''; function checkPay(bool $ok,string $name):void{global $checks;if(!$ok)throw new RuntimeException($name);$checks[]=$name;} function apiPay(string $path,string $method='GET',array $data=[]):array{ global $auth;$r=Illuminate\Http\Request::create('https://fuc-xb-test.gemcook.net/api/v1/'.$path,$method,$data,[],[],['HTTP_ACCEPT'=>'application/json','HTTP_AUTHORIZATION'=>$auth,'REMOTE_ADDR'=>'127.0.0.1']); app()->instance('request',$r);app('auth')->forgetGuards();$res=app(Illuminate\Contracts\Http\Kernel::class)->handle($r); return [$res->getStatusCode(),json_decode($res->getContent(),true),$res->getContent()]; } function signPay(array $p):array{ global $credentials;unset($p['sign'],$p['sign_type']);$v=array_filter($p,fn($x)=>$x!==''&&$x!==null);ksort($v,SORT_STRING);$parts=[];foreach($v as$k=>$x)$parts[]=$k.'='.$x;$p['sign']=md5(implode('&',$parts).$credentials['api_key']);$p['sign_type']='MD5';return $p; } function checkoutPay(User $u,Plan $p,Payment $channel):array { global $auth;$auth=(new App\Services\AuthService($u->fresh()))->generateAuthData()['auth_data']; [$c,$v]=apiPay('user/order/save','POST',['plan_id'=>$p->id,'period'=>'month_price']);checkPay($c===200,'native order create'); $trade=$v['data'];[$c,$v]=apiPay('user/order/checkout','POST',['trade_no'=>$trade,'method'=>$channel->id]);checkPay($c===200&&($v['type']??null)===1,'native checkout builds EPay redirect'); return [Order::where('trade_no',$trade)->firstOrFail(),$v['data']]; } $before=['users'=>User::count(),'orders'=>Order::count(),'payments'=>Payment::count(),'wallet'=>(int)User::sum('balance'),'vip'=>DB::table('fuc_vip_entries')->count(),'plugins'=>DB::table('v2_plugins')->count()]; $db=DB::connection();$db->beginTransaction(); try{ $pm=app(App\Services\Plugin\PluginManager::class);$pm->initializeEnabledPlugins(); if(!App\Models\Plugin::where('code','epay')->exists())$pm->install('epay');$pm->enable('epay'); checkPay(isset((new App\Services\PaymentService('temp'))->getAvailablePaymentMethods()['EPay']),'native EPay plugin enabled only in transaction'); $u=User::create(['email'=>'qa-payment-20261104@fuc-xb.invalid','password'=>password_hash(bin2hex(random_bytes(20)),PASSWORD_BCRYPT),'uuid'=>(string)Illuminate\Support\Str::uuid(),'token'=>bin2hex(random_bytes(16)),'balance'=>0,'expired_at'=>0,'banned'=>0]); $p=Plan::create(['name'=>'QA-payment-only-20261104','prices'=>['monthly'=>1],'transfer_enable'=>1,'capacity_limit'=>null,'show'=>1,'sell'=>1,'renew'=>1,'reset_traffic_method'=>2]); app(Plugin\VipLoyalty\Service::class)->opening($u->id,$u->uuid,9900,hash('sha256','qa-payment-opening-20261104')); $channels=[]; foreach(['alipay','wxpay']as$type){ $channel=Payment::create(['uuid'=>App\Utils\Helper::randomChar(8),'name'=>'QA-'.$type,'payment'=>'EPay','enable'=>true,'sort'=>9000,'handling_fee_fixed'=>0,'handling_fee_percent'=>0,'notify_domain'=>'https://fuc-xb-test.gemcook.net','config'=>['url'=>'https://pay.airspay.top','pid'=>$credentials['merchant_id'],'key'=>$credentials['api_key'],'type'=>$type]]); $channels[$type]=$channel; [$o,$url]=checkoutPay($u,$p,$channel);$parts=parse_url($url);parse_str($parts['query']??'',$args); checkPay(($parts['scheme']??'')==='https'&&($parts['host']??'')==='pay.airspay.top'&&($args['type']??'')===$type&&($args['money']??'')==='1','registered merchant redirect and exact unpaid amount '.$type); checkPay(str_starts_with($args['notify_url'],'https://fuc-xb-test.gemcook.net/')&&!str_contains($args['notify_url'],'fuuuu.cloud'),'callback stays on isolated site '.$type); checkPay($args['sign']===signPay($args)['sign'],'independent MD5 redirect signature '.$type); // Read the real cashier once, with no user wallet, cookies, scan, payment approval or automatic redirect. $curl=curl_init($url);curl_setopt_array($curl,[CURLOPT_RETURNTRANSFER=>true,CURLOPT_FOLLOWLOCATION=>false,CURLOPT_TIMEOUT=>20,CURLOPT_CONNECTTIMEOUT=>8,CURLOPT_SSL_VERIFYPEER=>true,CURLOPT_SSL_VERIFYHOST=>2,CURLOPT_USERAGENT=>'FUC-XB-Isolated-Acceptance/1.0']); $html=curl_exec($curl);$status=curl_getinfo($curl,CURLINFO_HTTP_CODE);$tls=curl_getinfo($curl,CURLINFO_SSL_VERIFYRESULT);$err=curl_errno($curl);curl_close($curl); $cashiers[]=['type'=>$type,'http_status'=>$status,'tls_verify_result'=>$tls,'transport_error'=>$err,'body_bytes'=>is_string($html)?strlen($html):0,'provider_rejected'=>is_string($html)&&(str_contains($html,'签名验证失败')||str_contains($html,'商户不存在')||str_contains($html,'商户已被封禁')||str_contains($html,'商户未开启'))]; if(is_string($html))file_put_contents($private.'/cashier-'.$type.'.html',$html); [$c,$state]=apiPay('user/order/check','GET',['trade_no'=>$o->trade_no]);checkPay($c===200&&$state['data']===0&&$o->fresh()->status===0,'cashier visit alone never opens order '.$type); [$c]=apiPay('user/order/cancel','POST',['trade_no'=>$o->trade_no]);checkPay($c===200&&$o->fresh()->status===2,'unpaid order cancelled '.$type); } // Controlled signed notifications are synthetic, not actual gateway delivery or settlement. $channel=$channels['alipay'];$channel->update(['handling_fee_fixed'=>5,'handling_fee_percent'=>2]); $u->update(['balance'=>20]);[$o]=$pair=checkoutPay($u,$p,$channel); checkPay((int)$o->total_amount===80&&(int)$o->balance_amount===20&&(int)$o->handling_amount===7,'native mixed wallet principal and fee separation'); $params=['pid'=>$credentials['merchant_id'],'type'=>'alipay','out_trade_no'=>$o->trade_no,'trade_no'=>'QA-CONTROLLED-20261104-'.$o->id,'trade_status'=>'TRADE_SUCCESS','money'=>'0.87']; $path='guest/payment/notify/EPay/'.$channel->uuid; $mutations=['wrong merchant'=>['pid'=>'invalid-merchant'],'wrong channel type'=>['type'=>'wxpay'],'pending trade'=>['trade_status'=>'WAIT_BUYER_PAY'],'negative amount'=>['money'=>'-0.87'],'incorrect amount'=>['money'=>'0.86'],'fee omitted'=>['money'=>'0.80'],'sub-cent amount'=>['money'=>'0.870'],'unknown order'=>['out_trade_no'=>'QA-NOT-EXIST']]; foreach($mutations as$name=>$diff){[$c]=apiPay($path,'POST',signPay(array_replace($params,$diff)));checkPay($c!==200&&$o->fresh()->status===0,'reject signed '.$name);} $bad=signPay($params);$bad['sign']=str_repeat('0',32);[$c]=apiPay($path,'POST',$bad);checkPay($c!==200&&$o->fresh()->status===0,'reject invalid signature'); $bad=signPay($params);$bad['sign_type']='RSA';[$c]=apiPay($path,'POST',$bad);checkPay($c!==200,'reject unsupported signature type'); $bad=signPay($params);$bad['money']=['0.87'];[$c]=apiPay($path,'POST',$bad);checkPay($c!==200,'reject array payload'); [$c,$v,$raw]=apiPay($path,'POST',signPay($params));checkPay($c===200&&$raw==='success'&&$o->fresh()->status===3,'controlled signed callback opens synchronously'); $expiry=$u->fresh()->expired_at;$entry=DB::table('fuc_vip_entries')->where('order_id',$o->id)->get(); checkPay($entry->count()===1&&(int)$entry[0]->amount_cents===100&&$u->fresh()->discount===8,'VIP counts package wallet plus online principal and excludes fees'); [$c,$v,$raw]=apiPay($path,'POST',signPay($params));checkPay($c===200&&$raw==='success'&&$u->fresh()->expired_at===$expiry&&DB::table('fuc_vip_entries')->where('order_id',$o->id)->count()===1,'duplicate callback never reopens or double accrues'); [$c]=apiPay($path,'POST',signPay(array_replace($params,['trade_no'=>'QA-WRONG-PROVIDER-ID'])));checkPay($c!==200,'reject conflicting callback transaction'); $auth=(new App\Services\AuthService($u->fresh()))->generateAuthData()['auth_data'];[$c,$v]=apiPay('user/order/save','POST',['plan_id'=>$p->id,'period'=>'month_price']);$next=Order::where('trade_no',$v['data'])->firstOrFail();checkPay((int)$next->total_amount===92,'new discount applies to next order'); [$c]=apiPay('user/order/cancel','POST',['trade_no'=>$next->trade_no]);checkPay($c===200,'cancel next order'); $late=signPay(array_replace($params,['out_trade_no'=>$next->trade_no,'money'=>'0.92','trade_no'=>'QA-LATE']));[$c]=apiPay($path,'POST',$late);checkPay($c!==200&&$next->fresh()->status===2,'late callback cannot revive cancelled order'); $db->rollBack(); $after=['users'=>User::count(),'orders'=>Order::count(),'payments'=>Payment::count(),'wallet'=>(int)User::sum('balance'),'vip'=>DB::table('fuc_vip_entries')->count(),'plugins'=>DB::table('v2_plugins')->count()]; checkPay($before===$after,'all test business and plugin rows rolled back'); $cashierOk=count($cashiers)===2&&!array_filter($cashiers,fn($x)=>!in_array($x['http_status'],[200,301,302,303],true)||$x['tls_verify_result']!==0||$x['transport_error']!==0||$x['provider_rejected']); $result=['native_business_checks_passed'=>true,'gateway_entry_reachable'=>$cashierOk,'final_cashier_tested'=>false,'checks'=>count($checks),'cases'=>$checks,'real_cashiers'=>$cashiers,'native_http_kernel'=>true,'real_money_paid'=>0,'callbacks_are_controlled_synthetic'=>true,'actual_gateway_success_callback_tested'=>false,'external_unpaid_cashier_orders_may_expire'=>true,'rollback'=>true,'production_changed'=>false]; file_put_contents($private.'/payment-result.json',json_encode($result,JSON_PRETTY_PRINT));echo json_encode($result).PHP_EOL; }finally{while($db->transactionLevel()>0)$db->rollBack();Cache::store('redis')->forget(App\Support\Setting::CACHE_KEY);}