# 金店参考价格:5 分钟接入,从注册到拿到今日金价
> 接口 2145(金店参考价格)· 免费 · 请求方式 POST/GET · 返回 JSON · 适用人群:新注册用户、初级开发者 · 阅读时间约 5 分钟
## 核心要点
- 金店参考价格提供各大金店黄金、铂金每日参考价,注册后即可免费调用。
- 拿金价必须走「两步」:先调 2145-1 取品牌 _id,再用 _id 调 2145-2 取实时价。
- 三种语言(Python / cURL / Node.js)示例替换 AppKey 即可运行。
## Why:这跟我有什么关系
做珠宝柜台报价、金价小程序、公众号每日推文,都需要一份权威的「今日金价」。金店参考价格接口把各大金店的黄金、铂金参考价汇总成 API,每天 13:40 更新,注册就能免费调。下面用 5 分钟带你在本地跑通第一条金价数据。
## What:前置条件与接口速览
**前置条件**:① 已在 ShowAPI 注册并获取 AppKey([AppKey 管理](https://www.showapi.com/apiGateway/view/2145));② 网络可访问 `route.showapi.com`。
| 项 | 值 |
|---|---|
| 接口 | 金店参考价格(apiCode=2145) |
| 接入点1 | 支持金店 `2145-1`,返回品牌清单 |
| 接入点2 | 最新价格 `2145-2`,按品牌 _id 返回金价 |
| 请求方式 | POST / GET |
| 返回格式 | JSON |
| 计费 | 免费(有档位限流) |
## How:接入步骤
**步骤 1|取 AppKey**
在控制台复制你的 AppKey,下文用 `YOUR_APPKEY` 占位。
**步骤 2|取品牌清单(2145-1)**
```python
import requests
url = "https://route.showapi.com/2145-1"
resp = requests.post(
url,
params={"appKey": "YOUR_APPKEY"},
headers={"content-type": "application/x-www-form-urlencoded"},
timeout=10,
)
data = resp.json()
if data.get("showapi_res_code") == 0 and data["showapi_res_body"]["ret_code"] == 0:
for item in data["showapi_res_body"]["data"]:
print(item["_id"], item["brand"])
else:
print("查询失败:", data.get("showapi_res_error"))
```
```bash
curl -X POST "https://route.showapi.com/2145-1?appKey=YOUR_APPKEY" \
-H "content-type: application/x-www-form-urlencoded"
```
```javascript
const resp = await fetch("https://route.showapi.com/2145-1?appKey=YOUR_APPKEY", {
method: "POST",
headers: { "content-type": "application/x-www-form-urlencoded" },
});
const data = await resp.json();
if (data.showapi_res_code === 0 && data.showapi_res_body.ret_code === 0) {
data.showapi_res_body.data.forEach((it) => console.log(it._id, it.brand));
}
```
**步骤 3|用 _id 取实时金价(2145-2)**
把步骤 2 返回的某个 `_id` 填入下面的 `id`。
```python
import requests
brand_id = "5da958ead3fb8b0eefc6a3d2" # 来自「支持金店」接入点返回的 _id
url = "https://route.showapi.com/2145-2"
resp = requests.post(
url,
params={"appKey": "YOUR_APPKEY"},
data={"id": brand_id},
headers={"content-type": "application/x-www-form-urlencoded"},
timeout=10,
)
body = resp.json()["showapi_res_body"]
if body["ret_code"] == 0:
print(body["brand"], "黄金", body["goldPrice"], "铂金", body["platinumPrice"], body["auLastDate"])
elif body["ret_code"] == -1:
print("未找到该品牌:", body.get("remark"))
```
```bash
curl -X POST "https://route.showapi.com/2145-2?appKey=YOUR_APPKEY" \
-H "content-type: application/x-www-form-urlencoded" \
-d "id=5da958ead3fb8b0eefc6a3d2"
```
```javascript
const brandId = "5da958ead3fb8b0eefc6a3d2";
const resp = await fetch("https://route.showapi.com/2145-2?appKey=YOUR_APPKEY", {
method: "POST",
headers: { "content-type": "application/x-www-form-urlencoded" },
body: new URLSearchParams({ id: brandId }),
});
const body = (await resp.json()).showapi_res_body;
if (body.ret_code === 0) {
console.log(body.brand, "黄金", body.goldPrice, "铂金", body.platinumPrice, body.auLastDate);
} else if (body.ret_code === -1) {
console.log("未找到该品牌:", body.remark);
}
```
> CTA:复制上面任意一段,把 `YOUR_APPKEY` 换成你自己的,即可在本地拿到今日金价。
## 返回示例与解析
**2145-1 返回(品牌清单,节选)**
```python
{
"showapi_res_error": "",
"showapi_fee_num": 1,
"showapi_res_code": 0,
"showapi_res_id": "67a5aa89fb638c27e149bc47",
"showapi_res_body": {
"ret_code": 0,
"data": [
{ "_id": "5da958e9d3fb8b0eefc6a3d1", "brand": "潮宏基" }
]
}
}
```
**2145-2 返回(某品牌金价)**
```python
{
"showapi_res_error": "",
"showapi_fee_num": 1,
"showapi_res_code": 0,
"showapi_res_id": "67a5aaf5fb638c27e15696c2",
"showapi_res_body": {
"ret_code": 0,
"platinumPrice": 409,
"_id": "5da958ead3fb8b0eefc6a3d2",
"remark": "",
"auLastDate": "2025-02-07",
"showapi_fee_code": 0,
"ptLastDate": "2025-02-07",
"brand": "周大生",
"goldPrice": 869
}
}
```
字段含义:`goldPrice` 黄金参考价(元/克,示例 869)、`platinumPrice` 铂金参考价(示例 409)、`auLastDate`/`ptLastDate` 价格日期、`brand` 品牌中文名、`ret_code` 0 成功。完整字段见[金店参考价格:返回字段与状态码全解](https://www.showapi.com/guides/gold-price-response-codes-2145)。
## 进阶 / 边界
- **两步依赖是铁律**:2145-2 必须传 2145-1 返回的 `_id`,不能直接按品牌名查价。
- **示例 _id 不等于任意品牌**:文档示例里 2145-1 的 `_id`(潮宏基)与 2145-2 的示例 `id`(周大生)不是同一家,请务必用 2145-1 真实返回的 `_id`。
- 免费但有档位限流,批量拉取请参考[缓存策略](https://www.showapi.com/guides/gold-price-cache-cost-2145)。
## FAQ
**Q:接口真的免费吗?**
是的,注册后默认可免费调用;为防止滥用设有使用档位限制,权益档次可用平台积分兑换更高调用档位。具体档位数字以官方档位说明为准。
**Q:为什么调 2145-2 要传 _id?**
最新价格接入点按品牌 id 查询,而品牌 id 来自「支持金店」接入点(2145-1)的返回。两步是设计上的依赖关系。
**Q:返回里没有铂金价怎么办?**
铂金价字段为 `platinumPrice`,示例值 409。若个别品牌未提供铂金价,该字段可能缺失或为空,属正常边界,建议在展示时做空值兜底。
**Q:价格每天几点更新?**
最新价格接入点每天 13:40 更新;支持金店(品牌清单)则为每年不定期更新一次。
## 相关能力 / 下一步阅读
- [金店参考价格:返回字段与状态码全解](https://www.showapi.com/guides/gold-price-response-codes-2145)
- [金店参考价格:两步调用工作流](https://www.showapi.com/guides/gold-price-two-step-2145)
- [金店参考价格:金价每日 13:40 更新,如何设计缓存策略节省调用成本](https://www.showapi.com/guides/gold-price-cache-cost-2145)
- **本系列共 12 篇**:查看[金店参考价格 · 官方指南总目录](https://www.showapi.com/guides/gold-price-guides-2145)