For AI agents: the complete documentation index is available at https://api.reyvo.com/llms.txt, and this page is available as Markdown at https://api.reyvo.com/zh/webhooks.md.

EVENTS & DELIVERY

让你的系统及时获知变化

签名事件、至少一次投递、失败重试。业务事件接收端由客户维护。

创建端点后保存一次性返回的 secret。每次投递都是 POST,带 X-UCard-Event-Id 和 X-UCard-Signature: t=<unix 秒>,v1=<hex>,其中 v1 = HMAC-SHA256(secret, t + "." + rawBody)。使用原始请求体验签,时间窗口 ±300 秒。按 event.id 去重,成功返回 2xx;失败后从 1 分钟逐级退避到 24 小时重试,最多 8 次,之后投递变为 dead。顺序不保证。

{
  "id": "evt_…",
  "type": "deposit.credited",
  "data": {
    "deposit_id": "dep_…",
    "amount_cents": 99000
  }
}

事件包括 deposit.credited、card.created、card.updated、card.challenge_created、card.challenge_answered、transaction.*、budget.updated、withdrawal.requested、withdrawal.approved、withdrawal.rejected 和 withdrawal.completed(data.id 是提现单 ID,data.address_suffix 是收款地址末 4 位,其余 data 字段与 Withdrawal 同名)。端点 URL 必须是 HTTPS,且域名已由运营加入 allowlist,否则返回 422 webhook_url_not_allowed。Mock 另外接受 mock://local:它把每次投递记为 HTTP 200,但不真正发送。

import { createHmac, timingSafeEqual } from 'node:crypto';
// header = X-UCard-Signature, rawBody = the request body bytes, unparsed
const match = /^t=(\d+),v1=([a-f0-9]{64})$/.exec(header || '');
if (!match) throw Error('Invalid signature');
const [, timestamp, signatureHex] = match;
if (Math.abs(Date.now() / 1000 - Number(timestamp)) > 300)
  throw Error('Expired event');
const expected = createHmac('sha256', secret)
  .update(timestamp + '.').update(rawBody).digest();
const received = Buffer.from(signatureHex, 'hex');
if (received.length !== expected.length ||
    !timingSafeEqual(received, expected)) throw Error('Invalid signature');

GET /v1/webhook-deliveries 返回投递记录,字段为 id、endpoint、attempts、status(pending、retry、delivered、dead、cancelled)、next_at(Unix 毫秒)和 last_code(最近一次尝试的 HTTP 状态码,连不上时为 0)。记录不含签名和事件原始 body,二者请在接收端校验。POST /v1/webhook-deliveries/{id}/retry 只重排 dead 投递,其他状态返回 404 not_found。Mock 下 POST /v1/mock/webhooks/deliver 执行一轮投递。