Tagasubok ng webhook
Mag-log in bilang may-ari o admin ng number, o mag-paste ng API key ng number (scope webhooks:manage) at ilagay ang number sa itaas. Hanggang doon: mga halimbawa at verify code lamang.
Ipadala sa URL
Sinusuri kung sumasagot ang iyong URL.
BodyHindi binago = ang sariling halimbawa ng API ng uring iyon. Hanggang 16 KB.
Secret, format, mga custom header
Test URL
Pansamantalang URL na nagtatago ng ipinapadala rito (1 oras, 50 request). Ilagay ito sa isang webhook o ipadala rito sa itaas; lalabas dito ang mga request nang live.
Mga naka-save na webhook
I-verify ang code
import crypto from "node:crypto";
// rawBody: the body exactly as received (Buffer or string), eg express.raw({ type: "application/json" })
export function verifyWebhook(rawBody, header, secret, toleranceSeconds = 300) {
const t = /(?:^|,)\s*t=(\d+)/.exec(header ?? "")?.[1];
const v1 = [...(header ?? "").matchAll(/(?:^|,)\s*v1=([0-9a-f]+)/g)].map((m) => m[1]); // every v1=: two while an old secret is kept
if (!t || v1.length === 0 || Math.abs(Date.now() / 1000 - Number(t)) > toleranceSeconds) return false;
const expected = crypto.createHmac("sha256", secret).update(t + ".").update(rawBody).digest("hex");
return v1.some((v) => v.length === expected.length && crypto.timingSafeEqual(Buffer.from(v), Buffer.from(expected)));
}
// const ok = verifyWebhook(req.body, req.get("X-App2email-Signature"), process.env.WEBHOOK_SECRET); import hashlib, hmac, re, time
def verify_webhook(raw_body: bytes, header: str, secret: str, tolerance: int = 300) -> bool:
t = re.search(r"(?:^|,)\s*t=(\d+)", header or "")
v1 = re.findall(r"(?:^|,)\s*v1=([0-9a-f]+)", header or "") # every v1=: two while an old secret is kept
if not t or not v1 or abs(time.time() - int(t.group(1))) > tolerance:
return False
expected = hmac.new(secret.encode(), t.group(1).encode() + b"." + raw_body, hashlib.sha256).hexdigest()
return any(hmac.compare_digest(v, expected) for v in v1)
# ok = verify_webhook(request.get_data(), request.headers.get("X-App2email-Signature"), WEBHOOK_SECRET) <?php
function verify_webhook(string $rawBody, string $header, string $secret, int $tolerance = 300): bool {
if (!preg_match('/(?:^|,)\s*t=(\d+)/', $header, $t)) return false;
preg_match_all('/(?:^|,)\s*v1=([0-9a-f]+)/', $header, $m); // every v1=: two while an old secret is kept
if (!$m[1] || abs(time() - (int)$t[1]) > $tolerance) return false;
$expected = hash_hmac('sha256', $t[1] . '.' . $rawBody, $secret);
foreach ($m[1] as $v) if (hash_equals($expected, $v)) return true;
return false;
}
// $ok = verify_webhook(file_get_contents('php://input'), $_SERVER['HTTP_X_APP2EMAIL_SIGNATURE'] ?? '', getenv('WEBHOOK_SECRET'));