import { useState } from "react"; import { Check, Copy } from "lucide-react"; const ORIGIN = typeof window !== "undefined" ? window.location.origin : "https://goods.tangshasha.com"; const BASE = `${ORIGIN}/api/v1`; function CopyBtn({ text }: { text: string }) { const [done, setDone] = useState(false); return ( ); } function Code({ children }: { children: string }) { return (
{children}
{path}
{desc}
{params && params.length > 0 && (| 参数 | 必填 | 说明 |
|---|---|---|
| {p.name} | {p.required ? "是" : "否"} | {p.desc} |
{example}
{response}
天工商品档案公共仓提供公开、只读、免鉴权的商品事实 REST API,任何人都可直接调用, 用于按条码/名称查询商品的客观资料(品牌、品类、净含量、产地、配料、营养成分、Nutri-Score、 厂商建议零售价快照等)。返回均为 JSON(UTF-8)。本服务不含任何购买/交易接口。
{BASE}
page(默认 1)、
size(默认 20,最大 100)。
404,错误体形如
{` {"error":{"code","message","request_id"}}`}。
API 默认匿名可用:无需任何凭证即可调用,按来源 IP 计入一个较低的默认频率额度。 如需更高额度并让用量归属到你,可在运营方申请一枚 API Key,请求时通过请求头携带:
{`# 二选一
curl -H "X-API-Key: og_live_xxxxxxxx" ${BASE}/products/search?q=牛奶
curl -H "Authorization: Bearer og_live_xxxxxxxx" ${BASE}/products/search?q=牛奶`}
采用固定窗口限流(每分钟)。每个响应都会回写以下响应头,便于客户端自适应:
| 响应头 | 含义 |
|---|---|
| X-RateLimit-Limit | 当前窗口允许的最大请求数 |
| X-RateLimit-Remaining | 当前窗口剩余可用次数 |
| X-RateLimit-Reset | 窗口重置的 Unix 时间戳(秒) |
| Retry-After | 超额时返回,建议等待的秒数 |
超过额度返回 429 Too Many Requests,错误码
rate_limited;无效或已吊销的 Key 返回
401,错误码 invalid_api_key。