<!-- 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/wzry -->

# 王者战力查询

王者荣耀全国战力查询，一接口聚合「英雄列表 + 区服战力分布」2 大功能。

• action=heroes — 返回 130+ 个英雄完整目录（中文名 / ename / 称号 / 头像 URL），优先腾讯官方源 https://pvp.qq.com/web201605/js/herolist.json

• action=query — 查询某英雄在某区服的全国战力分布数据，返回 90 条左右的省市区战力榜（含同地区相近排名）

支持 4 大区服：
  · aqq = Android QQ
  · awx = Android 微信
  · iqq = iOS QQ
  · iwx = iOS 微信

查询类型：
  · all = 完整 heroList（按 level 混合排列，约 90 项）
  · min = 各级（省/市/区）最低战力 + 相近排名（rank ≤ +100）
  · max = 各级（省/市/区）最高战力 + 相近排名

## 平台约定

- 网关：`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. 基本信息

| 字段 | 值 |
| --- | --- |
| 接口标识 | `wzry` |
| 接口名称 | 王者战力查询 |
| 接口地址 | `https://v1.apizero.cn/api/wzry` |
| 请求方法 | `GET` |
| 分类 | 生活服务 |
| 提供方 | 极数本源 |
| 计费模式 | 完全免费 |
| QPS 限制 | 3 req/s |
| 登录免费额度 | 20 次 |
| 匿名每日额度 | 5 次 |

### 会员每日额度

| 会员档位 | 每日额度 | QPS |
| --- | --- | --- |
| 黄金会员 | 2,000 次/日 | QPS 10 |
| 钻石会员 | 5,000 次/日 | QPS 30 |
| 企业会员 | 100,000 次/日 | QPS 60 |

## 2. 认证

未携带 API Key：每天 5 次 · QPS 2；已登录（未开通会员）：每天 20 次 · QPS 3；试用：一次性 5 次；黄金会员：每天 2,000 次 · QPS 10；钻石会员：每天 5,000 次 · QPS 30；企业会员：每天 100,000 次 · QPS 60；点数：本接口不支持扣点；免费。英雄列表缓存 24h、战力数据缓存 1h。

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

## 3. 子能力

### 英雄列表 (`heroes`)

返回全部英雄 list（name / title / ename / avatar）。ename 即后续 query 的 hero_id。文档示例为真实抓取（仅展示前几条）。

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

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

**响应字段**

| 字段 | 类型 | 说明 |
| --- | --- | --- |
| `action` | `string` | heroes |
| `count` | `integer` | 英雄总数 |
| `list` | `array` | 英雄列表：name / title / ename / avatar |
| `list[].name` | `string` | 名称 |
| `list[].title` | `string` | 标题 |
| `list[].ename` | `string` | ename |
| `list[].avatar` | `string` | avatar |
| `tips` | `string` | 品牌提示（所有接口统一返回）：极数本源 · https://apizero.cn |


```json
{
  "code": 0,
  "msg": "成功",
  "data": {
    "action": "heroes",
    "count": 131,
    "list": [
      {
        "name": "廉颇",
        "title": "正义爆轰",
        "ename": "105",
        "avatar": "https://game.gtimg.cn/images/yxzj/img201606/heroimg/105/105.jpg"
      },
      {
        "name": "小乔",
        "title": "恋之微风",
        "ename": "106",
        "avatar": "https://game.gtimg.cn/images/yxzj/img201606/heroimg/106/106.jpg"
      },
      {
        "name": "赵云",
        "title": "苍天翔龙",
        "ename": "107",
        "avatar": "https://game.gtimg.cn/images/yxzj/img201606/heroimg/107/107.jpg"
      }
    ]
  },
  "tips": "极数本源 · https://apizero.cn"
}
```

### 战力查询 (`query`)

按英雄 + 区服查询战力分布。hero 与 hero_id 二选一。文档示例为赵云 / Android QQ 真实抓取（rank_data 已截断）。

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

| 参数 | 类型 | 必填 | 说明 | 示例 |
| --- | --- | --- | --- | --- |
| `action` | `string` | 是 | 固定 query | `query` |
| `hero` | `string` | 否 | 英雄中文名 | `赵云` |
| `hero_id` | `integer` | 否 | 英雄 ename，优先级高于 hero | `107` |
| `zone` | `string` | 是 | aqq / awx / iqq / iwx | `aqq` |
| `type` | `string` | 否 | all / min / max | `all` |

**响应字段**

| 字段 | 类型 | 说明 |
| --- | --- | --- |
| `hero` | `object` | 英雄信息：name / title / ename / avatar |
| `hero.name` | `string` | 名称 |
| `hero.title` | `string` | 标题 |
| `hero.ename` | `string` | ename |
| `hero.avatar` | `string` | avatar |
| `zone` | `object` | 区服：code / system / platform |
| `zone.code` | `string` | code |
| `zone.system` | `string` | system |
| `zone.platform` | `string` | 平台 |
| `rank_data` | `array` | 各地区战力/排名条目 |
| `rank_data[].address` | `string` | address |
| `rank_data[].level` | `string` | level |
| `rank_data[].adcode` | `string` | adcode |
| `rank_data[].rank` | `number` | rank |
| `syn_date` | `string` | 数据同步日期 |
| `tips` | `string` | 品牌提示（所有接口统一返回）：极数本源 · https://apizero.cn |


```json
{
  "code": 0,
  "msg": "成功",
  "data": {
    "action": "query",
    "hero": {
      "name": "赵云",
      "title": "苍天翔龙",
      "ename": "107",
      "avatar": "https://game.gtimg.cn/images/yxzj/img201606/heroimg/107/107.jpg"
    },
    "zone": {
      "code": "aqq",
      "system": "Android",
      "platform": "QQ"
    },
    "type": "全部",
    "type_code": "all",
    "syn_date": "2026-07-30",
    "rank_data": [
      {
        "address": "内蒙古",
        "level": "province",
        "adcode": "2082639256508563456",
        "rank": 9577
      },
      {
        "address": "青海",
        "level": "province",
        "adcode": "2082639256507777024",
        "rank": 9601
      },
      {
        "address": "中国澳门",
        "level": "province",
        "adcode": "2082639256514805760",
        "rank": 9601
      }
    ]
  },
  "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/wzry?action=query&hero=%E8%B5%B5%E4%BA%91&hero_id=107&zone=aqq&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/wzry"
params = {
    "action": "query",
    "hero": "赵云",
    "hero_id": 107,
    "zone": "aqq",
    "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.wzry(
    action="query",
    hero="赵云",
    hero_id=107,
    zone="aqq",
    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/wzry?action=query&hero=%E8%B5%B5%E4%BA%91&hero_id=107&zone=aqq&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.wzry({
  "action": "query",
  "hero": "赵云",
  "hero_id": 107,
  "zone": "aqq",
  "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/wzry?action=query&hero=%E8%B5%B5%E4%BA%91&hero_id=107&zone=aqq&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/wzry?action=query&hero=%E8%B5%B5%E4%BA%91&hero_id=107&zone=aqq&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/wzry?action=query&hero=%E8%B5%B5%E4%BA%91&hero_id=107&zone=aqq&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/wzry?action=query&hero=%E8%B5%B5%E4%BA%91&hero_id=107&zone=aqq&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): 首次上线，聚合英雄列表 + 全国战力 2 个 action
英雄列表双源容灾：腾讯官方失败自动降级 yxsaoma.com
内置 MD5 签名（warzoneSignKey20240515 + timestamp + 字典序拼接）
英雄列表缓存 24h、战力数据缓存 1h
type=min/max 时按 level（省/市/区）分组，输出 extreme + similar（rank 差距 ≤ +100 相近排名）
find_hero 同时支持 hero（中文名）和 hero_id（ename）两种定位方式
