回调
提交 query 时传入 callback_url,query 到达终态 (completed、timeout 或 failed) 后,API 会向该地址发送 1 次 POST 请求。
POST /your/path HTTP/1.1Content-Type: application/json; charset=utf-8User-Agent: geoeval-callbackX-Geoeval-Signature: t=1798000095,v1=5257a869e7...请求体与 GET /v1/queries/{query_id} 的返回一致,录屏链接在发送时重新签发。其中的 callback 字段表示本次投递成功后的状态。
- 必须使用
https、公网可达,且不带用户名密码和#片段。 - 拒绝内网地址,解析到内网地址的公网域名同样会被拒绝。
- 不跟随重定向,请直接填写最终地址。
- 请在 10 秒内返回任意
2xx,耗时处理放到应答之后执行。 - 未按时应答时,按 30 秒、1 分钟、2 分钟指数退避重试,间隔最长 30 分钟,最多 10 次;仍未成功则
callback.status变为failed。 - 同一回调可能投递多次,请按
query_id保证幂等。
X-Geoeval-Signature 格式为 t=<unix 秒>,v1=<hex>。v1 使用提交该 query 的 API Key 对应的签名密钥计算 HMAC-SHA256(secret, "<t>.<原始请求体>")。轮换密钥后的 24 小时内会携带 2 个 v1,任一匹配即通过。建议拒绝与当前时间相差超过 5 分钟的请求。
HMAC 必须对原始请求体计算;解析 JSON 后再序列化会改变字节内容。
import { createHmac, timingSafeEqual } from "node:crypto";
// 校验 X-Geoeval-Signature。rawBody 为收到的原始请求体 (未经任何 JSON 解析),// secret 为提交该 query 的 API Key 签名密钥 (whsec_...)。export function verifyCallback(rawBody: string | Buffer, header: string, secret: string, toleranceSeconds = 300): boolean { const parts = header.split(",").map((part) => part.split("=")); const timestamp = parts.find(([name]) => name === "t")?.[1]; if (!timestamp || Math.abs(Date.now() / 1000 - Number(timestamp)) > toleranceSeconds) return false; const expected = createHmac("sha256", secret).update(`${timestamp}.`).update(rawBody).digest(); // 轮换密钥后会有 2 个 v1 值,匹配其中 1 个即可 return parts.some(([name, value = ""]) => { if (name !== "v1") return false; const given = Buffer.from(value, "hex"); return given.length === expected.length && timingSafeEqual(given, expected); });}import hashlibimport hmacimport time
def verify_callback(raw_body: bytes, header: str, secret: str, tolerance_seconds: int = 300) -> bool: # 校验 X-Geoeval-Signature。raw_body 为收到的原始请求体,secret 为 whsec_... parts = [part.split("=", 1) for part in header.split(",")] timestamp = next((value for name, value in parts if name == "t"), None) if timestamp is None or abs(time.time() - int(timestamp)) > tolerance_seconds: return False expected = hmac.new(secret.encode(), timestamp.encode() + b"." + raw_body, hashlib.sha256).hexdigest() # 轮换密钥后会有 2 个 v1 值,匹配其中 1 个即可 return any(name == "v1" and hmac.compare_digest(value, expected) for name, value in parts)若删除了提交该 query 的 Key,回调因无法签名会被放弃;仅吊销 Key 不受影响。