From 7acdc414fcb94d3c707393daa937c1c51c196828 Mon Sep 17 00:00:00 2001 From: zhenhui <1276357500@qq.com> Date: Wed, 6 May 2026 10:51:57 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=B5=8B=E8=AF=95verifyToken?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/playx-verify-token-callback-test.php | 29 +++++++++++++++----- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/scripts/playx-verify-token-callback-test.php b/scripts/playx-verify-token-callback-test.php index db0b64c..eeddcfe 100644 --- a/scripts/playx-verify-token-callback-test.php +++ b/scripts/playx-verify-token-callback-test.php @@ -94,9 +94,6 @@ if ($payload === false) { exit(1); } -$escapedPayload = str_replace("'", "'\\''", $payload); -$escapedSig = str_replace("'", "'\\''", $signature); - echo "--- 等价 curl(Linux / macOS / Git Bash)---\n"; echo "curl -sS -X POST '" . $url . "' \\\n"; echo " -H 'Content-Type: application/json' \\\n"; @@ -110,10 +107,12 @@ echo "canonical={$canonical}\n\n"; $body = $payload; $ctx = stream_context_create([ 'http' => [ - 'method' => 'POST', - 'header' => "Content-Type: application/json\r\nX-Request-Signature: {$signature}\r\n", - 'content' => $body, - 'timeout' => 15, + 'method' => 'POST', + 'header' => "Content-Type: application/json\r\nX-Request-Signature: {$signature}\r\n", + 'content' => $body, + 'timeout' => 15, + // 4xx/5xx 仍返回响应体,便于查看对端错误说明(否则 file_get_contents 直接 false) + 'ignore_errors' => true, ], 'ssl' => [ 'verify_peer' => true, @@ -128,4 +127,20 @@ if ($result === false) { exit(1); } +$statusLine = isset($http_response_header[0]) ? $http_response_header[0] : ''; +echo "--- HTTP 响应行 ---\n"; +echo $statusLine . "\n"; +if (isset($http_response_header[1])) { + echo "--- 响应头(节选)---\n"; + $max = min(12, count($http_response_header)); + for ($i = 1; $i < $max; $i++) { + echo $http_response_header[$i] . "\n"; + } +} +echo "--- 响应体 ---\n"; echo $result . "\n"; + +if (!preg_match('/\b200\b/', $statusLine)) { + fwrite(STDERR, "\n提示:非 2xx 时请根据响应体与对端核对签名字符串、Body 字段是否与回调网关约定一致。\n"); + exit(2); +}