优化测试verifyToken接口脚本

This commit is contained in:
2026-05-06 10:51:57 +08:00
parent 907f7cb315
commit 7acdc414fc

View File

@@ -94,9 +94,6 @@ if ($payload === false) {
exit(1);
}
$escapedPayload = str_replace("'", "'\\''", $payload);
$escapedSig = str_replace("'", "'\\''", $signature);
echo "--- 等价 curlLinux / macOS / Git Bash---\n";
echo "curl -sS -X POST '" . $url . "' \\\n";
echo " -H 'Content-Type: application/json' \\\n";
@@ -114,6 +111,8 @@ $ctx = stream_context_create([
'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);
}