300) { return false; // 时间戳超出 ±5 分钟 } $stringToSign = strtoupper($method) . "\n" . $path . "\n" . $timestamp . "\n" . $nonce . "\n" . hash('sha256', $body); $expected = hash_hmac('sha256', $stringToSign, $signKey); return hash_equals($expected, strtolower($signature)); } // 在回调入口中使用: // $body = file_get_contents('php://input'); // $ok = yours_open_verify(getenv('YOURS_OPEN_SIGN_KEY'), $_SERVER['REQUEST_METHOD'], parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH), // $_SERVER['HTTP_X_TIMESTAMP'] ?? '', $_SERVER['HTTP_X_NONCE'] ?? '', $body, $_SERVER['HTTP_X_SIGN'] ?? ''); // 命令行自检:php verify.php if (PHP_SAPI === 'cli' && isset($argv) && realpath($argv[0]) === __FILE__) { [, $key, $path, $ts, $nonce, $sign, $bodyFile] = $argv + array_fill(0, 7, ''); exit(yours_open_verify($key, 'POST', $path, $ts, $nonce, (string) file_get_contents($bodyFile), $sign) ? 0 : 1); }