> ## Documentation Index
> Fetch the complete documentation index at: https://developers.uqpay.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Webhooks

> 使用 Python SDK 验证传入的 UQPAY Webhook 签名。

创建客户端时设置`webhook_secret`，然后把未经修改的请求体和headers传给`construct_event`。

实现签名验证前，请先[配置通知URL](/zh/account-center/v1.6/guide/webhooks-setting)，并了解[Webhook投递与安全机制](/zh/account-center/v1.6/guide/webhooks-overview)。

```python theme={null}
client = UQPayClient(
    client_id="your-client-id",
    api_key="your-api-key",
    webhook_secret="your-webhook-secret",
)

# In your HTTP handler:
from uqpay import UQPayWebhookError

try:
    event = client.webhooks.construct_event(
        raw_body=request.get_data(),
        headers=dict(request.headers),
    )
    print(event["event_type"], event["data"])
except UQPayWebhookError as e:
    return str(e), 400
```

<Warning>
  请传入原始请求体。验证前解析并重新序列化JSON会改变签名对应的字节，导致验证失败。
</Warning>

验证器会校验Webhook签名，并拒绝超出5分钟防重放窗口的请求。
