Saltar al contenido principal
La plataforma envía la firma en el encabezado X-Telehealth-Signature en hexadecimal minúsculas (sin prefijo). Debe calcular HMAC-SHA256 del cuerpo raw (UTF-8) con el secret y comparar en hex minúsculas.
<?php
function verifyWebhookSignature(string $rawBody, string $signatureHeader, string $secret): bool {
    $expected = hash_hmac('sha256', $rawBody, $secret, false); // false = hex en minúsculas
    return hash_equals($expected, $signatureHeader);
}

// En su endpoint que recibe el webhook:
$rawBody = file_get_contents('php://input');
$signature = $_SERVER['HTTP_X_TELEHEALTH_SIGNATURE'] ?? '';
$secret = 'SU_WEBHOOK_SECRET';

if (!verifyWebhookSignature($rawBody, $signature, $secret)) {
    http_response_code(401);
    exit('Invalid signature');
}
$payload = json_decode($rawBody, true);
// Procesar $payload según $payload['event'] o header X-Telehealth-Event