Skip to content

Webhook 实现

签名验证

python
import hmac
import hashlib

def verify_signature(payload, signature, secret, timestamp):
    message = f"{timestamp}.{payload}"
    expected = hmac.new(
        secret.encode(),
        message.encode(),
        hashlib.sha256
    ).hexdigest()
    return hmac.compare_digest(signature, expected)

最佳实践

  1. 始终验证签名 - 确保请求来自 FluxiQ
  2. 快速响应 - 在 5 秒内返回 2xx 状态码
  3. 幂等处理 - 使用 Event-Id 防止重复处理
  4. 异步处理 - 将耗时操作放入后台队列

Documentação da API FluxiQ NPC