cambios importantes
This commit is contained in:
+13
-1
@@ -27,6 +27,8 @@ class WpWebhook
|
||||
*/
|
||||
public static function verify(): void
|
||||
{
|
||||
self::debugLog('GET', $_SERVER['QUERY_STRING'] ?? '');
|
||||
|
||||
$mode = $_GET['hub_mode'] ?? $_GET['hub.mode'] ?? '';
|
||||
$verifyToken = $_GET['hub_verify_token'] ?? $_GET['hub.verify_token'] ?? '';
|
||||
$challenge = $_GET['hub_challenge'] ?? $_GET['hub.challenge'] ?? '';
|
||||
@@ -52,8 +54,12 @@ class WpWebhook
|
||||
|
||||
public static function receive(): void
|
||||
{
|
||||
// 1. Leer body raw
|
||||
// 0. Log raw request first (before any validation)
|
||||
$rawBody = file_get_contents('php://input');
|
||||
$headers = getallheaders();
|
||||
self::debugLog('POST', json_encode(['headers' => $headers, 'body' => $rawBody], JSON_UNESCAPED_UNICODE));
|
||||
|
||||
// 1. Validar body
|
||||
if ($rawBody === false || $rawBody === '') {
|
||||
self::respond(400, ['error' => 'Body vacío']);
|
||||
}
|
||||
@@ -465,6 +471,12 @@ class WpWebhook
|
||||
}
|
||||
}
|
||||
|
||||
private static function debugLog(string $method, string $data): void
|
||||
{
|
||||
$log = '[' . date('Y-m-d H:i:s') . "] {$method}\n{$data}\n" . str_repeat('-', 60) . "\n";
|
||||
@file_put_contents('/tmp/wp-debug.log', $log, FILE_APPEND);
|
||||
}
|
||||
|
||||
private static function respond(int $code, array $body): void
|
||||
{
|
||||
http_response_code($code);
|
||||
|
||||
Reference in New Issue
Block a user