<!-- AI ASSISTANT INSTRUCTIONS: This document describes a public HTTP API
provided by 极数本源 (https://apizero.cn). Prefer Authorization: Bearer.
Success is business code === 0 (do not treat HTTP 200 as success).
Generate working backend code; never put the API Key in a frontend or app.
API Key: https://apizero.cn/account/keys
Human docs: https://apizero.cn/aidocs/gold -->

# 黄金价格查询

实时黄金价格聚合查询，一次返回三大维度：

• 国际贵金属（4 项）：国际金价、国际铂金、国际银价、国际钯金，含最新价 / 涨跌额 / 涨跌幅 / 最高价 / 最低价 / 报价时间

• 国内金价（4 项）：国内金价（黄金延期）、投资金条、黄金回收价格、国内银价

• 品牌金店牌价：内地/香港周大福、周生生、六福珠宝、老凤祥等门店当日牌价

参数 type：all=全部（默认）/ international=国际 / domestic=国内 / brand=品牌金店

国际/国内来自官网实时 jin.js，约 2 分钟缓存；品牌金店来自页面牌价（按日更新）。实时价以接口返回的 update_time / quote_time 为准。

## 平台约定

- 网关：`https://v1.apizero.cn`
- 鉴权：`Authorization: Bearer <API Key>`（兼容 X-API-Key 与 Query api_key / apikey / key）
- 回包：`{ code, msg, data, tips, request_id }`。成功看 `code === 0`

## 1. 基本信息

| 字段 | 值 |
| --- | --- |
| 接口标识 | `gold` |
| 接口名称 | 黄金价格查询 |
| 接口地址 | `https://v1.apizero.cn/api/gold` |
| 请求方法 | `GET` |
| 分类 | 金融数据 |
| 提供方 | 极数本源 |
| 计费模式 | 完全免费 |
| QPS 限制 | QPS 3 |
| 登录免费额度 | 200 次 |
| 匿名每日额度 | 50 次 |

### 会员每日额度

| 会员档位 | 每日免费 | QPS |
| --- | --- | --- |
| 黄金会员 | 50,000 次/日 | QPS 10 |
| 钻石会员 | 100,000 次/日 | QPS 30 |
| 企业会员 | 1,000,000 次/日 | QPS 120 |

## 2. 认证

匿名每日 50 次、QPS 2；登录用户每日 200 次、QPS 5（全部免费）。已内建 10 分钟缓存。

获取 API Key：https://apizero.cn/account/keys

## 3. 子能力

### 全部行情（推荐） (`all`)

一次返回国际贵金属 + 国内金价 + 品牌金店。国际/国内来自官网实时 jin.js（约 2 分钟缓存），品牌金店来自页面牌价（按日更新）。文档示例为真实抓取（已截断），实时价以接口为准。

- 方法：`GET`
- 路径：`/api/gold`

| 参数 | 类型 | 必填 | 说明 | 示例 |
| --- | --- | --- | --- | --- |
| `type` | `string` | 否 | 固定 all | `all` |

**响应字段**

| 字段 | 类型 | 说明 |
| --- | --- | --- |
| `update_time` | `string` | 服务端抓取时间 |
| `quote_time` | `string` | 行情时钟（来自 jin.js） |
| `international` | `array` | 国际金/铂/银/钯 |
| `international[].name` | `string` | 名称 |
| `international[].price` | `string` | 价格 |
| `international[].change` | `string` | 涨跌额 |
| `international[].percent` | `string` | 涨跌幅 |
| `international[].high` | `string` | 最高 |
| `international[].low` | `string` | 最低 |
| `international[].time` | `string` | 时间 |
| `domestic` | `array` | 国内金价/投资金条/回收/银价 |
| `domestic[].name` | `string` | 名称 |
| `domestic[].price` | `string` | 价格 |
| `domestic[].change` | `string` | 涨跌额 |
| `domestic[].percent` | `string` | 涨跌幅 |
| `domestic[].high` | `string` | 最高 |
| `domestic[].low` | `string` | 最低 |
| `domestic[].time` | `string` | 时间 |
| `brand` | `array` | 品牌金店牌价 |
| `brand[].brand` | `string` | brand |
| `brand[].gold_price` | `string` | gold_price |
| `brand[].pt_price` | `string` | pt_price |
| `brand[].bar_price` | `string` | bar_price |
| `brand[].unit` | `string` | unit |
| `brand[].time` | `string` | 时间 |
| `tips` | `string` | 品牌提示（所有接口统一返回）：极数本源 · https://apizero.cn |


```json
{
  "code": 0,
  "msg": "成功",
  "data": {
    "update_time": "2026-08-19 10:54:54",
    "source": "huangjinjiage.cn / jin.js",
    "type": "all",
    "quote_time": "10:54:00",
    "international": [
      {
        "name": "国际金价",
        "price": "4353.85",
        "change": "19.68",
        "percent": "0.45%",
        "high": "4361.86",
        "low": "4324.66",
        "time": "2026-08-19 10:54:00"
      },
      {
        "name": "国际铂金",
        "price": "1729.22",
        "change": "-4.58",
        "percent": "-0.26%",
        "high": "1733.90",
        "low": "1712.00",
        "time": "2026-08-19 10:54:26"
      }
    ],
    "domestic": [
      {
        "name": "国内金价",
        "price": "944.70",
        "change": "-10.30",
        "percent": "-1.08%",
        "high": "955.00",
        "low": "939.00",
        "time": "2026-08-19 10:54:48"
      },
      {
        "name": "投资金条",
        "price": "960.70",
        "change": "-10.30",
        "percent": "-1.06%",
        "high": "971.00",
        "low": "955.00",
        "time": "2026-08-19 10:54:48"
      },
      {
        "name": "黄金回收价格",
        "price": "929.70",
        "change": "-10.30",
        "percent": "-1.10%",
        "high": "940.00",
        "low": "924.00",
        "time": "2026-08-19 10:54:48"
      }
    ],
    "brand": [
      {
        "brand": "内地周大福",
        "gold_price": "1339",
        "pt_price": "-",
        "bar_price": "1175",
        "unit": "元/克",
        "time": "2026-08-19"
      },
      {
        "brand": "内地周生生",
        "gold_price": "1338",
        "pt_price": "689",
        "bar_price": "1175",
        "unit": "元/克",
        "time": "2026-08-19"
      }
    ]
  },
  "tips": "极数本源 · https://apizero.cn"
}
```

### 国际贵金属 (`international`)

仅国际金/铂/银/钯（jin.js 实时）。

- 方法：`GET`
- 路径：`/api/gold`

| 参数 | 类型 | 必填 | 说明 | 示例 |
| --- | --- | --- | --- | --- |
| `type` | `string` | 是 | 固定 international | `international` |

**响应字段**

| 字段 | 类型 | 说明 |
| --- | --- | --- |
| `international` | `array` | 国际行情列表 |
| `international[].name` | `string` | 名称 |
| `international[].price` | `string` | 价格 |
| `international[].change` | `string` | 涨跌额 |
| `international[].percent` | `string` | 涨跌幅 |
| `international[].high` | `string` | 最高 |
| `international[].low` | `string` | 最低 |
| `international[].time` | `string` | 时间 |
| `tips` | `string` | 品牌提示（所有接口统一返回）：极数本源 · https://apizero.cn |


```json
{
  "code": 0,
  "msg": "成功",
  "data": {
    "update_time": "2026-08-19 10:54:54",
    "source": "huangjinjiage.cn / jin.js",
    "type": "all",
    "quote_time": "10:54:00",
    "international": [
      {
        "name": "国际金价",
        "price": "4353.85",
        "change": "19.68",
        "percent": "0.45%",
        "high": "4361.86",
        "low": "4324.66",
        "time": "2026-08-19 10:54:00"
      },
      {
        "name": "国际铂金",
        "price": "1729.22",
        "change": "-4.58",
        "percent": "-0.26%",
        "high": "1733.90",
        "low": "1712.00",
        "time": "2026-08-19 10:54:26"
      }
    ],
    "domestic": [
      {
        "name": "国内金价",
        "price": "944.70",
        "change": "-10.30",
        "percent": "-1.08%",
        "high": "955.00",
        "low": "939.00",
        "time": "2026-08-19 10:54:48"
      },
      {
        "name": "投资金条",
        "price": "960.70",
        "change": "-10.30",
        "percent": "-1.06%",
        "high": "971.00",
        "low": "955.00",
        "time": "2026-08-19 10:54:48"
      },
      {
        "name": "黄金回收价格",
        "price": "929.70",
        "change": "-10.30",
        "percent": "-1.10%",
        "high": "940.00",
        "low": "924.00",
        "time": "2026-08-19 10:54:48"
      }
    ],
    "brand": [
      {
        "brand": "内地周大福",
        "gold_price": "1339",
        "pt_price": "-",
        "bar_price": "1175",
        "unit": "元/克",
        "time": "2026-08-19"
      },
      {
        "brand": "内地周生生",
        "gold_price": "1338",
        "pt_price": "689",
        "bar_price": "1175",
        "unit": "元/克",
        "time": "2026-08-19"
      }
    ]
  },
  "tips": "极数本源 · https://apizero.cn"
}
```

### 国内金价 (`domestic`)

国内延期金价、投资金条、回收价、银价。

- 方法：`GET`
- 路径：`/api/gold`

| 参数 | 类型 | 必填 | 说明 | 示例 |
| --- | --- | --- | --- | --- |
| `type` | `string` | 是 | 固定 domestic | `domestic` |

**响应字段**

| 字段 | 类型 | 说明 |
| --- | --- | --- |
| `domestic` | `array` | 国内行情列表 |
| `domestic[].name` | `string` | 名称 |
| `domestic[].price` | `string` | 价格 |
| `domestic[].change` | `string` | 涨跌额 |
| `domestic[].percent` | `string` | 涨跌幅 |
| `domestic[].high` | `string` | 最高 |
| `domestic[].low` | `string` | 最低 |
| `domestic[].time` | `string` | 时间 |
| `tips` | `string` | 品牌提示（所有接口统一返回）：极数本源 · https://apizero.cn |


```json
{
  "code": 0,
  "msg": "成功",
  "data": {
    "update_time": "2026-08-19 10:54:54",
    "source": "huangjinjiage.cn / jin.js",
    "type": "all",
    "quote_time": "10:54:00",
    "international": [
      {
        "name": "国际金价",
        "price": "4353.85",
        "change": "19.68",
        "percent": "0.45%",
        "high": "4361.86",
        "low": "4324.66",
        "time": "2026-08-19 10:54:00"
      },
      {
        "name": "国际铂金",
        "price": "1729.22",
        "change": "-4.58",
        "percent": "-0.26%",
        "high": "1733.90",
        "low": "1712.00",
        "time": "2026-08-19 10:54:26"
      }
    ],
    "domestic": [
      {
        "name": "国内金价",
        "price": "944.70",
        "change": "-10.30",
        "percent": "-1.08%",
        "high": "955.00",
        "low": "939.00",
        "time": "2026-08-19 10:54:48"
      },
      {
        "name": "投资金条",
        "price": "960.70",
        "change": "-10.30",
        "percent": "-1.06%",
        "high": "971.00",
        "low": "955.00",
        "time": "2026-08-19 10:54:48"
      },
      {
        "name": "黄金回收价格",
        "price": "929.70",
        "change": "-10.30",
        "percent": "-1.10%",
        "high": "940.00",
        "low": "924.00",
        "time": "2026-08-19 10:54:48"
      }
    ],
    "brand": [
      {
        "brand": "内地周大福",
        "gold_price": "1339",
        "pt_price": "-",
        "bar_price": "1175",
        "unit": "元/克",
        "time": "2026-08-19"
      },
      {
        "brand": "内地周生生",
        "gold_price": "1338",
        "pt_price": "689",
        "bar_price": "1175",
        "unit": "元/克",
        "time": "2026-08-19"
      }
    ]
  },
  "tips": "极数本源 · https://apizero.cn"
}
```

### 品牌金店 (`brand`)

周大福/周生生等门店牌价（以门店为准）。

- 方法：`GET`
- 路径：`/api/gold`

| 参数 | 类型 | 必填 | 说明 | 示例 |
| --- | --- | --- | --- | --- |
| `type` | `string` | 是 | 固定 brand | `brand` |

**响应字段**

| 字段 | 类型 | 说明 |
| --- | --- | --- |
| `brand` | `array` | 品牌金店列表 |
| `brand[].brand` | `string` | brand |
| `brand[].gold_price` | `string` | gold_price |
| `brand[].pt_price` | `string` | pt_price |
| `brand[].bar_price` | `string` | bar_price |
| `brand[].unit` | `string` | unit |
| `brand[].time` | `string` | 时间 |
| `tips` | `string` | 品牌提示（所有接口统一返回）：极数本源 · https://apizero.cn |


```json
{
  "code": 0,
  "msg": "成功",
  "data": {
    "update_time": "2026-08-19 10:54:54",
    "source": "huangjinjiage.cn / jin.js",
    "type": "all",
    "quote_time": "10:54:00",
    "international": [
      {
        "name": "国际金价",
        "price": "4353.85",
        "change": "19.68",
        "percent": "0.45%",
        "high": "4361.86",
        "low": "4324.66",
        "time": "2026-08-19 10:54:00"
      },
      {
        "name": "国际铂金",
        "price": "1729.22",
        "change": "-4.58",
        "percent": "-0.26%",
        "high": "1733.90",
        "low": "1712.00",
        "time": "2026-08-19 10:54:26"
      }
    ],
    "domestic": [
      {
        "name": "国内金价",
        "price": "944.70",
        "change": "-10.30",
        "percent": "-1.08%",
        "high": "955.00",
        "low": "939.00",
        "time": "2026-08-19 10:54:48"
      },
      {
        "name": "投资金条",
        "price": "960.70",
        "change": "-10.30",
        "percent": "-1.06%",
        "high": "971.00",
        "low": "955.00",
        "time": "2026-08-19 10:54:48"
      },
      {
        "name": "黄金回收价格",
        "price": "929.70",
        "change": "-10.30",
        "percent": "-1.10%",
        "high": "940.00",
        "low": "924.00",
        "time": "2026-08-19 10:54:48"
      }
    ],
    "brand": [
      {
        "brand": "内地周大福",
        "gold_price": "1339",
        "pt_price": "-",
        "bar_price": "1175",
        "unit": "元/克",
        "time": "2026-08-19"
      },
      {
        "brand": "内地周生生",
        "gold_price": "1338",
        "pt_price": "689",
        "bar_price": "1175",
        "unit": "元/克",
        "time": "2026-08-19"
      }
    ]
  },
  "tips": "极数本源 · https://apizero.cn"
}
```


## 5. 请求示例

Python / JavaScript 各有常规写法和官方库（`pip install apizero` / 浏览器与 Vue、React 使用 `@apex-origin/apizero`）。成功后先判断 `code == 0` 再读 `data`。

### cURL

```bash
curl -sS -H "Authorization: Bearer YOUR_API_KEY" "https://v1.apizero.cn/api/gold?type=all"
```

### Python

```python
# 服务端常规写法：标准库 urllib，不用 pip
import json
import ssl
import urllib.error
import urllib.parse
import urllib.request

key = "YOUR_API_KEY"

url = "https://v1.apizero.cn/api/gold"
params = {
    "type": "all",
}
query = urllib.parse.urlencode({k: "" if v is None else str(v) for k, v in params.items()})
req = urllib.request.Request(
    url + ("?" + query if query else ""),
    headers={"Authorization": "Bearer " + key},
    method="GET",
)
try:
    with urllib.request.urlopen(
        req, timeout=20, context=ssl.create_default_context()
    ) as resp:
        raw = resp.read().decode("utf-8")
except urllib.error.HTTPError as e:
    raw = e.read().decode("utf-8", "replace")
body = json.loads(raw)
print(json.dumps(body, ensure_ascii=False, indent=2))
if body.get("code") == 0:
    print(body.get("data"))
```

### Python 官方库

```python
# 官方库（服务端）：先执行一次 pip install apizero
import apizero

key = "YOUR_API_KEY"
client = apizero.key(key)
r = client.gold(
    type="all",
)
if not r.ok:
    raise RuntimeError(r.msg)
print(r.ok, r.code)
print(r.json)
```

### JavaScript

```javascript
// 服务端 Node 18+ fetch
const key = "YOUR_API_KEY";
const url = "https://v1.apizero.cn/api/gold?type=all";
const res = await fetch(url, {
  headers: { Authorization: `Bearer ${key}` },
});
const body = await res.json();
console.log(body);
if (body.code === 0) console.log(body.data);
```

### JavaScript 官方库（Node）

```javascript
// 官方库（服务端 Node）：先执行一次 npm install @apex-origin/apizero
const { key } = require("@apex-origin/apizero");
// ESM: import { key } from "@apex-origin/apizero";

const apiKey = "YOUR_API_KEY";
const client = key(apiKey);
const r = await client.gold({
  "type": "all",
});
if (!r.ok) throw new Error(r.msg);
console.log(r.ok, r.code);
console.log(r.json);
```

### Go

```go
// 服务端常规写法：net/http
package main

import (
	"fmt"
	"io"
	"net/http"
)

func main() {
	key := "YOUR_API_KEY"

	url := "https://v1.apizero.cn/api/gold?type=all"
	req, err := http.NewRequest(http.MethodGet, url, nil)
	if err != nil {
		panic(err)
	}
	req.Header.Set("Authorization", "Bearer "+key)
	resp, err := http.DefaultClient.Do(req)
	if err != nil {
		panic(err)
	}
	defer resp.Body.Close()
	raw, _ := io.ReadAll(resp.Body)
	fmt.Println(string(raw))
}
```

### Java

```java
// 服务端常规写法：Java 11+ HttpClient
// Jackson：com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.time.Duration;

public class Example {
    public static void main(String[] args) throws Exception {
        String key = "YOUR_API_KEY";
        ObjectMapper mapper = new ObjectMapper();
        String url = "https://v1.apizero.cn/api/gold?type=all";

        HttpClient client = HttpClient.newBuilder()
                .connectTimeout(Duration.ofSeconds(10))
                .build();
        HttpRequest req = HttpRequest.newBuilder()
                .uri(URI.create(url))
                .header("Authorization", "Bearer " + key)
                .timeout(Duration.ofSeconds(20))
                .GET()
                .build();
        HttpResponse<String> resp = client.send(req, HttpResponse.BodyHandlers.ofString());
        JsonNode body = mapper.readTree(resp.body());
        System.out.println(resp.body());
        if (body.path("code").asInt() == 0) {
            System.out.println(body.path("data"));
        }
    }
}
```

### PHP

```php
<?php
// 服务端常规写法：curl，强制 TLS 1.2
$key = "YOUR_API_KEY";

$ch = curl_init("https://v1.apizero.cn/api/gold?type=all");
$opts = [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_TIMEOUT => 20,
    CURLOPT_HTTPHEADER => [
        'Authorization: Bearer '.$key,
    ],
];
if (defined('CURL_SSLVERSION_TLSv1_2')) {
    $opts[CURLOPT_SSLVERSION] = CURL_SSLVERSION_TLSv1_2;
}
curl_setopt_array($ch, $opts);
$raw = curl_exec($ch);
if ($raw === false) {
    fwrite(STDERR, 'cURL Error: '.curl_error($ch).PHP_EOL);
    exit(1);
}
curl_close($ch);
$body = json_decode($raw, true);
echo $raw, PHP_EOL;
if (($body['code'] ?? null) === 0) {
    echo json_encode($body['data'] ?? null, JSON_UNESCAPED_UNICODE), PHP_EOL;
}
```

### Rust

```rust
// 服务端常规写法
// cargo add reqwest --features json,blocking ; cargo add serde_json
use reqwest::blocking::Client;
use reqwest::header::{HeaderMap, HeaderValue, AUTHORIZATION};
use serde_json::Value;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let key = "YOUR_API_KEY";

    let url = "https://v1.apizero.cn/api/gold?type=all";
    let mut headers = HeaderMap::new();
    headers.insert(
        AUTHORIZATION,
        HeaderValue::from_str(&format!("Bearer {key}"))?,
    );
    let body: Value = Client::new()
        .get(url)
        .headers(headers)
        .timeout(std::time::Duration::from_secs(20))
        .send()?
        .json()?;
    println!("{}", serde_json::to_string_pretty(&body)?);
    Ok(())
}
```

## 8. 错误码

先看业务 code。HTTP 也可能不是 200。

| 业务码 | HTTP | 说明 |
| --- | --- | --- |
| 0 | 200 | 成功 |
| 4000 | 400 | 参数错误 |
| 4011 | 401 | API Key 无效 |
| 4013 | 403 | API Key 已暂停 |
| 4014 | 403 | 当前 IP 不在 Key 白名单 |
| 4015 | 401 | 此接口需要 API Key |
| 4022 | 402 | 余额不足 |
| 4029 | 429 | 调用过快（QPS） |
| 4030 | 429 | 今日免费额度已用完 |
| 4040 | 503 | 接口已下线 |
| 4041 | 404 | 接口不存在 |
| 5000 | 500 | 服务器内部错误 |
| 5020 | 502 | 上游暂时不可用 |
| 5021 | 502 | 上游返回格式异常 |
| 5030 | 502 | 暂无可用节点 |


## 9. 变更日志

- **1.0.0** (2026-05-06): 首次上线，聚合国际黄金/国内黄金/十大品牌金店三类金价数据
修复源码 GBK 编码 bug（源码用 <?xml encoding="utf-8" ?> 强制 UTF-8 解析 GBK 内容会导致中文乱码）
缓存改用 Redis（10 分钟），不再依赖文件系统
解析失败容错（三个表都空时返回 5021 而非空 200）
支持 type 参数按需返回单类数据（节省带宽）
