أداة اختبار Webhook
سجّل الدخول كمالك الرقم أو مديره، أو ألصق مفتاح واجهة برمجية لهذا الرقم (الصلاحية webhooks:manage)، وأدخل الرقم أعلاه. حتى ذلك الحين: العينات ورمز التحقق فقط.
أرسل إلى عنوان URL
يتحقق من أن عنوانك يستجيب.
المحتوىبدون تغيير = العينة الخاصة بالواجهة البرمجية لذلك النوع. 16 KB كحد أقصى.
السر، والصيغة، والترويسات المخصصة
عنوان اختبار
عنوان مؤقت يحفظ ما يُرسل إليه (ساعة واحدة، و50 طلباً). ضعه في webhook أو أرسل إليه أعلاه؛ تظهر الطلبات هنا مباشرة.
الـ webhooks المحفوظة
تحقق من الكود
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'));