<?php
declare(strict_types=1);
namespace app\common {
class Serve {public static function push(string $a,array $d=[],int $delay=0):bool{throw new \RuntimeException('Sign queue forbidden');}public static function pushJump(string $a,array $d=[]):bool{throw new \RuntimeException('Sign queue forbidden');}}
class UserApi {public function run($a,$p=[]):array{throw new \RuntimeException('Sign external sync forbidden');}}
class QwRobot {public static function pushMsgFormat($d,$t='',$type='msg',$s=0){throw new \RuntimeException('Sign robot forbidden');}public static function pushMsg($p,$t=''){throw new \RuntimeException('Sign robot forbidden');}}
}
namespace app\common\library\wechat {
function curl_init(){return (object)['url'=>null];}
function curl_setopt($h,$option,$value){if($option===CURLOPT_URL)$h->url=$value;if($option===CURLOPT_POSTFIELDS)$h->body=$value;return true;}
function curl_exec($h){$u=parse_url($h->url);if(($u['scheme']??'')!=='https'||($u['host']??'')!=='api.weixin.qq.com'||!in_array($u['path']??'',['/cgi-bin/token','/wxa/getwxacodeunlimit'],true))throw new \RuntimeException('Unknown network boundary');$kind=$u['path']==='/cgi-bin/token'?'token':'wx_png';file_put_contents(getenv('SIGN_RUNTIME').'/external-leaves.jsonl',json_encode(['scenario'=>$_SERVER['HTTP_X_PILOT_SCENARIO']??'PROBE','kind'=>$kind,'params'=>$kind==='wx_png'?json_decode($h->body,true):[],'params_sha256'=>hash('sha256',$h->body??''),'network_sent'=>false])."\n",FILE_APPEND|LOCK_EX);return $kind==='token'?'{"access_token":"SYNTHETIC_PRIVATE_SIGN_TOKEN","expires_in":7200}':base64_decode('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII=');}
function curl_close($h){}
function curl_error($h){return 'Synthetic boundary error';}
}
namespace PHPQRCode {
class QRcode {public static function png($text,$outfile=false,$level='L',$size=3,$margin=4,$saveandprint=false){$root=realpath(getenv('SIGN_ROOT').'/public');$dir=realpath(dirname($outfile));if(!$root||!$dir||$dir!==$root.'/uploads/temp')throw new \RuntimeException('QR file outside private root');file_put_contents($outfile,base64_decode('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII='));file_put_contents(getenv('SIGN_RUNTIME').'/external-leaves.jsonl',json_encode(['scenario'=>$_SERVER['HTTP_X_PILOT_SCENARIO']??'PROBE','kind'=>'qr_png','text'=>$text,'text_sha256'=>hash('sha256',$text),'file'=>basename($outfile),'file_private'=>true,'network_sent'=>false])."\n",FILE_APPEND|LOCK_EX);}}
}
