API

开放 API 接口

游戏价格、评分、在线人数查询接口 — 提供 REST API(推荐,API Key 鉴权)与 AJAX 兼容接口两套接入方式

REST API(推荐)

  • 基础地址:https://www.zhuhaiyun.cn/wp-json/yz/v1
  • 鉴权方式:请求头 X-YZ-API-Key,或 GET 参数 api_key
  • 获取 Key:后台「Steam 采集 → API 管理」生成,每个 Key 独立设置每分钟限额
  • 限流规则:超限返回 HTTP 429;Key 无效返回 401/403
  • 返回格式:JSON,业务成功 code=0
REST

端点一览

/wp-json/yz/v1/*
方法端点说明参数
GET/games/search游戏搜索keyword(必填)
GET/games/compare游戏对比(2-6 款)ids=42,58,100
GET/games/{id}/price-history价格历史(含版本事件标注)—
GET/games/{id}/rating-history好评率历史—
GET/games/{id}/player-history在线人数历史—
POST/alerts创建价格预警game_id、alert_type、target_price 等

调用示例

# Header 鉴权(推荐)
curl -H "X-YZ-API-Key: 你的KEY" \
  "https://www.zhuhaiyun.cn/wp-json/yz/v1/games/compare?ids=42,58,100"

# 查询参数鉴权(简单场景)
curl "https://www.zhuhaiyun.cn/wp-json/yz/v1/games/search?keyword=巫师&api_key=你的KEY"

接入说明

  • 端点地址:https://www.zhuhaiyun.cn/wp-admin/admin-ajax.php
  • 请求方式:POST(application/x-www-form-urlencoded)
  • 身份验证:所有接口需传 nonce 参数
  • Nonce 生成:前端通过 wp_create_nonce('yz_game_nonce') 生成
  • 返回格式:JSON,code=0 表示成功

AJAX 兼容接口(旧)

以下接口需 nonce 鉴权,仅供已接入方兼容使用。新接入请优先使用上方 REST API。

POST

价格历史查询

action=get_price_history

返回某款游戏的价格历史数据(含原价、折扣、史低价),按时间升序排列。

请求参数

参数名类型 / 说明
game_idint(必填)— 游戏文章 ID
noncestring(必填)— 安全令牌

返回示例

{"code":0,"dates":["2026-01-01 00:00:00"],"prices":[29.00],"original_prices":[59.00],"discounts":[50],"hist_low":29.00,"hist_low_date":"2026-01-01 00:00:00"}

调用示例 (JavaScript)

fetch('https://www.zhuhaiyun.cn/wp-admin/admin-ajax.php', {
  method: 'POST',
  headers: {'Content-Type': 'application/x-www-form-urlencoded'},
  body: new URLSearchParams({
    action: 'get_price_history',
    nonce: yzGameData.nonce,
    game_id: /* 你的值 */  })
})
.then(r => r.json())
.then(data => console.log(data));
POST

好评率历史查询

action=get_rating_history

返回某款游戏的好评率及评论数历史数据。

请求参数

参数名类型 / 说明
game_idint(必填)— 游戏文章 ID
noncestring(必填)— 安全令牌

返回示例

{"code":0,"dates":["2026-01-01 00:00:00"],"ratings":[92],"reviews":[154823]}

调用示例 (JavaScript)

fetch('https://www.zhuhaiyun.cn/wp-admin/admin-ajax.php', {
  method: 'POST',
  headers: {'Content-Type': 'application/x-www-form-urlencoded'},
  body: new URLSearchParams({
    action: 'get_rating_history',
    nonce: yzGameData.nonce,
    game_id: /* 你的值 */  })
})
.then(r => r.json())
.then(data => console.log(data));
POST

在线人数历史查询

action=get_player_history

返回某款游戏的在线人数历史。近 7 天返回小时级数据,更早返回日级聚合(取每日最大值)。

请求参数

参数名类型 / 说明
game_idint(必填)— 游戏文章 ID
noncestring(必填)— 安全令牌

返回示例

{"code":0,"dates":["2026-01-01","2026-09-10 12:00:00"],"players":[52318,48211]}

调用示例 (JavaScript)

fetch('https://www.zhuhaiyun.cn/wp-admin/admin-ajax.php', {
  method: 'POST',
  headers: {'Content-Type': 'application/x-www-form-urlencoded'},
  body: new URLSearchParams({
    action: 'get_player_history',
    nonce: yzGameData.nonce,
    game_id: /* 你的值 */  })
})
.then(r => r.json())
.then(data => console.log(data));
POST

价格预警订阅

action=subscribe_price_alert

创建价格预警。支持 5 种类型:target_price(目标价)、historical_low(史低)、discount_threshold(折扣阈值)、price_drop(降价通知)、any_discount(折扣提醒)。

请求参数

参数名类型 / 说明
game_idint(必填)— 游戏文章 ID
alert_typestring(必填)— 预警类型
target_pricefloat — 目标价(alert_type=target_price 时必填)
threshold_valuefloat — 折扣阈值(alert_type=discount_threshold 时必填)
notify_channelsstring — 通知渠道,逗号分隔(email,site,webhook,wechat)
webhook_urlstring — Webhook URL(notify_channels 含 webhook 时必填)
emailstring — 邮箱(未登录用户必填)
noncestring(必填)— 安全令牌

返回示例

{"code":0,"msg":"订阅成功!降价时将自动通知您"}

调用示例 (JavaScript)

fetch('https://www.zhuhaiyun.cn/wp-admin/admin-ajax.php', {
  method: 'POST',
  headers: {'Content-Type': 'application/x-www-form-urlencoded'},
  body: new URLSearchParams({
    action: 'subscribe_price_alert',
    nonce: yzGameData.nonce,
    game_id: /* 你的值 */
    alert_type: /* 你的值 */
    target_price: /* 你的值 */
    threshold_value: /* 你的值 */
    notify_channels: /* 你的值 */
    webhook_url: /* 你的值 */
    email: /* 你的值 */  })
})
.then(r => r.json())
.then(data => console.log(data));
POST

游戏搜索

action=search_games

按关键词搜索游戏,返回最多 10 条结果。

请求参数

参数名类型 / 说明
keywordstring(必填)— 搜索关键词
noncestring(必填)— 安全令牌

返回示例

{"code":0,"data":[{"id":42,"appid":730,"name":"Counter-Strike 2","header":"https://...","price":0,"is_free":true}]}

调用示例 (JavaScript)

fetch('https://www.zhuhaiyun.cn/wp-admin/admin-ajax.php', {
  method: 'POST',
  headers: {'Content-Type': 'application/x-www-form-urlencoded'},
  body: new URLSearchParams({
    action: 'search_games',
    nonce: yzGameData.nonce,
    keyword: /* 你的值 */  })
})
.then(r => r.json())
.then(data => console.log(data));
POST

游戏对比

action=compare_games

批量获取多款游戏的对比数据。支持 2-6 款游戏。

请求参数

参数名类型 / 说明
game_idsstring(必填)— 游戏 ID 列表,逗号分隔(如 "42,58,100")
noncestring(必填)— 安全令牌

返回示例

{"code":0,"data":[{"id":42,"name":"...","price_final":29,"discount":50,"rating":92,"players":52318,"genres":["FPS","动作"],...}]}

调用示例 (JavaScript)

fetch('https://www.zhuhaiyun.cn/wp-admin/admin-ajax.php', {
  method: 'POST',
  headers: {'Content-Type': 'application/x-www-form-urlencoded'},
  body: new URLSearchParams({
    action: 'compare_games',
    nonce: yzGameData.nonce,
    game_ids: /* 你的值 */  })
})
.then(r => r.json())
.then(data => console.log(data));

使用须知

所有数据来源于 Steam 官方 API,仅供学习与研究参考。请勿高频请求(建议每次间隔 ≥ 0.8 秒)。价格预警每日最多检查一次,同一预警 24 小时内最多通知一次。商业使用需获得 Valve Corporation 授权。