Files
dpl/scripts/fuc-xb-acceptance/mapi.php
T

15 lines
2.6 KiB
PHP

<?php
ini_set('display_errors','0');umask(0077);$private='/var/www/wwwroot/fuc-xb-test/private/live-acceptance-20261104';chdir('/www/wwwroot/fuuuu.cloud');require 'config/.config.php';$dsn=!empty($_ENV['db_socket'])?'mysql:unix_socket='.$_ENV['db_socket']:'mysql:host='.$_ENV['db_host'].';port='.$_ENV['db_port'];$p=new PDO($dsn.';dbname='.$_ENV['db_database'].';charset=utf8mb4',$_ENV['db_username'],$_ENV['db_password'],[PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION]);$p->exec('SET TRANSACTION READ ONLY');$p->beginTransaction();$v=$p->query("SELECT item,value FROM config WHERE item IN ('epay_pid','epay_key','epay_url')")->fetchAll(PDO::FETCH_KEY_PAIR);$p->rollBack();
$old= file_get_contents('/www/wwwroot/fuuuu.cloud/src/Services/Gateway/Epay.php');
if(!str_contains($old,"'mapi.php'"))throw new RuntimeException('Old API contract not confirmed');
$k=$v['epay_key'];$out=[];
foreach(['alipay','wxpay']as$type){
$html=file_get_contents($private.'/cashier-'.$type.'.html');$doc=new DOMDocument();@$doc->loadHTML($html);$args=[];foreach($doc->getElementsByTagName('input')as$input)if($input->hasAttribute('name'))$args[$input->getAttribute('name')]=$input->getAttribute('value');
if((float)($args['money']??0)!==1.0||($args['type']??'')!==$type)throw new RuntimeException('Observed fixture mismatch');
unset($args['sign'],$args['sign_type']);$args['pid']=$v['epay_pid'];$args['out_trade_no']='QA-MAPI-20261104-'.$type.'-'.bin2hex(random_bytes(4));$args['sitename']='FUC-XB-TEST';$args['clientip']='45.8.112.190';ksort($args);$pairs=[];foreach($args as$a=>$b)if($b!==''&&$b!==null)$pairs[]=$a.'='.$b;$args['sign']=md5(implode('&',$pairs).$k);$args['sign_type']='MD5';
$curl=curl_init(rtrim($v['epay_url'],'/').'/mapi.php');curl_setopt_array($curl,[CURLOPT_POST=>true,CURLOPT_POSTFIELDS=>http_build_query($args),CURLOPT_RETURNTRANSFER=>true,CURLOPT_FOLLOWLOCATION=>false,CURLOPT_TIMEOUT=>25,CURLOPT_SSL_VERIFYPEER=>true,CURLOPT_SSL_VERIFYHOST=>2]);$body=curl_exec($curl);$status=curl_getinfo($curl,CURLINFO_HTTP_CODE);$tls=curl_getinfo($curl,CURLINFO_SSL_VERIFYRESULT);curl_close($curl);$j=is_string($body)?json_decode($body,true):null;
file_put_contents($private.'/mapi-'.$type.'.response',is_string($body)?$body:'');
$out[]=['type'=>$type,'http_status'=>$status,'tls_verify_result'=>$tls,'json_response'=>is_array($j),'code'=>is_array($j)&&is_scalar($j['code']??null)?$j['code']:null,'has_payurl'=>is_array($j)&&!empty($j['payurl']),'has_qrcode'=>is_array($j)&&!empty($j['qrcode']),'actual_payment'=>false];
}
echo json_encode(['old_fuc_native_api_contract_confirmed'=>true,'unpaid_api_request_only'=>true,'real_money_paid'=>0,'cases'=>$out]);