快速入门
五步完成:从测试密钥到保留一笔预订,再到收到 Webhook。
1. 创建测试密钥
在后台打开“开发者”,切换到“测试”模式,创建一个只读密钥。密钥只显示一次,请立即复制,并保存在环境变量 API_KEY 中。
2. 验证密钥
GET /me 会返回您的账户、密钥的模式和权限范围。这一步能用,后面的都能用。
curl "https://api.opentourbase.com/api/supplier/v1/me" \
-H "Authorization: Bearer $API_KEY"{
"data": {
"key": {
"id": "ush_test_Ab12Cd34Ef56Gh78Ij90Kl12",
"label": "Website back-end",
"mode": "test",
"scopes": [
"products:read",
"events:read"
]
},
"supplier": {
"id": "0b0f6a0e-5a57-4a10-9f6c-2f7f7a5d3c11",
"name": "Aurora Tours",
"currency": "GEL",
"currencyPrecision": 2,
"timeZone": "Asia/Tbilisi"
}
}
}3. 列出您的产品
测试密钥读取的是您真实的产品目录、余位和价格,所以您看到的就是您将要销售的。
curl "https://api.opentourbase.com/api/supplier/v1/products?limit=25" \
-H "Authorization: Bearer $API_KEY"4. 保留并确认一笔测试预订
找到一个出发班次,保留名额,然后确认。这需要密钥拥有 bookings:write 权限:给密钥完全访问权限,或单独加上这个权限。测试预订不收款,也不会通知任何游客。
curl "https://api.opentourbase.com/api/supplier/v1/options/{optionUuid}/availability?local_date=2026-12-05" \
-H "Authorization: Bearer $API_KEY"curl -X POST "https://api.opentourbase.com/api/supplier/v1/bookings" \
-H "Authorization: Bearer $API_KEY" \
-H "Idempotency-Key: $(uuidgen)" \
-H "Content-Type: application/json" \
-d '{"optionId":"{optionId}","availabilityId":"{availabilityId}","units":[{"unitId":"{unitId}","quantity":2}],"reference":"ORDER-1042"}'curl -X POST "https://api.opentourbase.com/api/supplier/v1/bookings/{uuid}/confirm" \
-H "Authorization: Bearer $API_KEY" \
-H "Idempotency-Key: $(uuidgen)" \
-H "Content-Type: application/json" \
-d '{"contact":{"fullName":"Ana Beridze","email":"ana@example.com"},"payment":{"mode":"offline"}}'5. 接收 Webhook
在“开发者 › Webhooks”中添加一个地址,然后点击“发送测试事件”。一秒内您的服务器就会收到一个已签名的请求。信任它之前,先校验签名。
import crypto from "node:crypto";
export function verify(rawBody, headers, secret, toleranceSec = 300) {
const id = headers["webhook-id"], ts = headers["webhook-timestamp"], sig = headers["webhook-signature"];
if (!id || !ts || !sig || Math.abs(Date.now() / 1000 - Number(ts)) > toleranceSec) return false;
const key = Buffer.from(secret.replace(/^whsec_/, ""), "base64");
const expected = crypto.createHmac("sha256", key).update(`${id}.${ts}.${rawBody}`).digest("base64");
return sig.split(" ").some((p) => {
const [v, s] = p.split(",");
return v === "v1" && s && s.length === expected.length && crypto.timingSafeEqual(Buffer.from(s), Buffer.from(expected));
});
}