游戏接口
本文描述公开 HTTP 接口。除健康检查外均使用 POST,携带 Content-Type: application/json 和 token: YOUR_TOKEN;接口地址使用当前应用审核后提供的基础地址。认证、错误与重试规则见签名认证。下列编号、地址、玩家与金额均为示例。
游戏目录
POST /api/v1/gamelist
取得游戏目录。无参数,发送空对象。响应 message 是 JSON 字符串,需要再解析一次;字段表描述解码后的对象。
{}
{
"success": true,
"message": "{\"list\":[{\"game_code\":\"baccarat\",\"name\":\"百家乐\",\"game_type\":\"table\",\"thumb_url\":\"https://games.example.invalid/thumb/baccarat.png\",\"priority\":1,\"status\":1,\"version\":\"1\"}],\"timestamp\":1792000000}"
}
message 解码后的业务对象(用于阅读,不是另一次 HTTP 响应):
{
"list": [
{
"game_code": "baccarat",
"name": "百家乐",
"game_type": "table",
"thumb_url": "https://games.example.invalid/thumb/baccarat.png",
"priority": 1,
"status": 1,
"version": "1"
}
],
"timestamp": 1792000000
}
| 字段 | 类型 | 说明 |
|---|---|---|
| list | array | 游戏数组;允许为空 |
| timestamp | integer | 目录生成时间,Unix 秒;不是游戏数量或版本号 |
| list[].game_code | string | 稳定游戏标识,作为启动接口 game 参数 |
| list[].name | string | 游戏显示名称 |
| list[].game_type | string | 服务端目录分类:table、betting、slots、fishing |
| list[].thumb_url | string | 缩略图地址,使用返回值 |
| list[].priority | integer | 推荐排序值,接入方按升序排列,同值按 game_code 排序 |
| list[].status | integer | 游戏配置状态,1 表示启用;接入方只展示可用项 |
| list[].version | string | 游戏资源版本文本,当前可能为空;不能依赖它判断接口版本 |
服务端不承诺数组已按推荐值排序。目录不返回 game_id、room_mode、hot_priority。默认场次由服务端处理,不要根据目录名重建游戏 URL。
启动游戏
POST /api/v1/user/launch_url
为已在第三方站点登录的玩家获取游戏入口。调用必须来自第三方服务端,不能允许浏览器指定任意其他玩家身份。
| 字段 | 类型 | 说明 |
|---|---|---|
| user | string · 必填 | 稳定且区分大小写的玩家编码,1–32 位 ASCII 字母、数字、下划线或短横线 |
| game | string · 必填 | 游戏目录中的 game_code |
| name | string · 可选 | 昵称,省略默认 user;不是唯一标识 |
| avatar | string · 可选 | 头像目录中的资源名;默认 default,不能传任意图片 URL |
| country_code | string · 可选 | 大写 ISO 两位国家/地区代码,如 CN;默认空字符串 |
| theme | string · 可选 | 传递给游戏入口的主题参数;默认空字符串,是否支持取决于游戏 |
| room_id | integer · 可选 | 房间定位;普通入口由默认房间配置决定 |
| server_id / table_id | integer · 可选 | 指定机台时与 room_id 一起传入,必须来自当前机台目录 |
| watch | boolean · 可选 | 指定机台时的观战意图,默认 false;是否允许由游戏判断 |
{
"user": "test-player-001",
"name": "测试玩家",
"avatar": "default",
"country_code": "CN",
"game": "baccarat",
"theme": "0"
}
{
"success": true,
"user_key": "WALLET_SESSION_KEY",
"game": "baccarat",
"launch_url": "https://games.example.invalid/?session=OPAQUE_SESSION&game=baccarat&theme=0&serverUrl=wss%3A%2F%2Fgames.example.invalid%2Fws"
}
| 字段 | 类型 | 说明 |
|---|---|---|
| success | boolean | 业务是否成功 |
| user_key | string | 钱包会话标识,保留在服务端用于回调核对 |
| game | string | 实际返回的游戏标识;已在线玩家可能返回当前游戏 |
| launch_url | string | 完整启动链接,仅此链接交给玩家浏览器;视为敏感会话数据 |
不同合作方下相同 user 独立。获取链接不代表已登录游戏或钱包已开启。重复调用可能重新签发入口;已在线时可能恢复当前游戏,必须读取响应 game。不能自行拼接、长期缓存或公开 launch_url。lobby_url 当前不改变返回行为;iframe 返回使用浏览器交互。
业务失败常见 message:invalid user code(玩家编码不合规)、invalid country_code、invalid user_code(创建玩家失败,也可能是请求游戏无效)、invalid game_code、machine unavailable(目录位置失效)、default room unavailable、profile update failed。这些错误可能以 HTTP 200、success=false 返回,不应自动无限重试。
玩家状态
POST /api/v1/user/status
查询当前合作方下玩家的运行状态。user 为必填字符串,与启动时完全一致。
{
"user": "test-player-001"
}
{
"success": true,
"status": "offline"
}
{
"success": true,
"game_code": "baccarat",
"status": "online",
"session": "OPAQUE_SESSION",
"session_timestamp": 1792000000,
"session_time": 60,
"login_timestamp": 1792000010,
"login_time": 50,
"balance": 10000000,
"open_status": 2
}
| 字段 | 类型 | 说明 |
|---|---|---|
| status | string | online 或 offline;钱包是否结算完成须另行核对 |
| game_code / session | string · 条件返回 | 内存中存在玩家时返回;session 是敏感启动会话 |
| session_timestamp / session_time | integer · 条件返回 | 入口签发的 Unix 秒/距签发的秒数 |
| login_timestamp / login_time | integer · 仅在线 | 登录 Unix 秒/在线秒数 |
| balance | integer · 条件返回 | 服务端余额快照,原始整数单位,不替代第三方账本 |
| open_status | integer · 条件返回 | 0 未发起,1 等待,2 成功收到开户回调,3 失败;非结算完成状态 |
缺少 user 返回 success=false、message="user code empty"。没有运行记录时只返回 success/status;不要假定所有可选字段存在。
请求退出
POST /api/v1/user/kick
user 为必填字符串。通知当前玩家退出,不是同步结算接口。
{
"user": "test-player-001"
}
{
"success": true,
"status": "pending"
}
响应 status 为 pending 表示退出通知已下发,offline 表示当前不在线。缺少 user 返回 user code empty。两种成功状态都不代表 close 回调完成;提现、调账须依据第三方已核对的钱包状态。超时先查询状态,不要把 HTTP 超时视为退出未执行。
头像目录
POST /api/v1/avatars
无参数,发送空对象。此接口直接返回顶层 list,不需要解析 message。
{}
{
"success": true,
"list": [
{
"avatar": "default",
"url": "https://games.example.invalid/avatars/default.png"
}
]
}
| 字段 | 类型 | 说明 |
|---|---|---|
| list | array | 可选头像目录 |
| list[].avatar | string | 启动接口 avatar 参数的资源名 |
| list[].url | string | 头像展示地址 |
公开机台目录
POST /api/v1/game/tables
无参数,返回有效快照;message 为 JSON 字符串。仅上报机台的游戏会出现在目录中,空数组不表示全部游戏不可用。
{}
{
"success": true,
"message": "{\"tables\":[{\"server_id\":101,\"room_id\":1,\"game_id\":100,\"table_id\":1,\"game_code\":\"example-game\",\"occupied\":false,\"players\":0,\"capacity\":1,\"jackpot\":\"100000\"}]}"
}
message 解码后的业务对象(用于阅读,不是另一次 HTTP 响应):
{
"tables": [
{
"server_id": 101,
"room_id": 1,
"game_id": 100,
"table_id": 1,
"game_code": "example-game",
"occupied": false,
"players": 0,
"capacity": 1,
"jackpot": "100000"
}
]
}
| 字段 | 类型 | 说明 |
|---|---|---|
| tables | array | 当前公开机台快照 |
| tables[].game_code | string | 对外游戏标识 |
| tables[].server_id / room_id / table_id | integer | 启动时一起提交的目标位置,不是可自行编造的编号 |
| tables[].game_id | integer | 本接口仍返回内部游戏编号;接入方使用 game_code 关联目录 |
| tables[].occupied | boolean | 当前人数达到容量,不构成座位预留 |
| tables[].players / capacity | integer | 当前人数/容量 |
| tables[].jackpot | string · 可选 | 显示奖池的原始整数文本,仅用于展示 |
超过 15 秒未更新的实例快照不输出。目录与启动之间存在时间差;启动返回 machine unavailable 时刷新目录并重新选择。
游戏动态
POST /api/v1/game/activity
用于在线人数和中奖展示,不是交易查询接口。cursor 为可选字符串,首次为空;后续原样提交上次返回的 cursor,不要解析或自己构造。
{
"cursor": ""
}
{
"success": true,
"message": "{\"cursor\":\"EPOCH:42\",\"reset\":true,\"games\":[{\"game_code\":\"baccarat\",\"online\":12,\"stale\":false}],\"wins\":[{\"event_id\":\"101:example-event\",\"game_code\":\"baccarat\",\"nickname\":\"示例玩家\",\"avatar\":\"default\",\"country_code\":\"CN\",\"amount\":\"1000\",\"amount_type\":\"net_win\",\"occurred_at\":1792000000}]}"
}
message 解码后的业务对象(用于阅读,不是另一次 HTTP 响应):
{
"cursor": "EPOCH:42",
"reset": true,
"games": [
{
"game_code": "baccarat",
"online": 12,
"stale": false
}
],
"wins": [
{
"event_id": "101:example-event",
"game_code": "baccarat",
"nickname": "示例玩家",
"avatar": "default",
"country_code": "CN",
"amount": "1000",
"amount_type": "net_win",
"occurred_at": 1792000000
}
]
}
| 字段 | 类型 | 说明 |
|---|---|---|
| cursor | string | 下次请求使用的游标 |
| reset | boolean | 首次请求、游标无效/过期或服务重启时为 true;前端重置旧动态缓存 |
| games | array | 游戏在线快照 |
| games[].game_code | string | 游戏标识 |
| games[].online | integer | 有效实例人数总和,含机器人,不是本合作方真人数 |
| games[].stale | boolean | 该游戏存在超过 15 秒未更新的实例;过期人数不计入 online |
| wins | array | 本次动态,最多 100 条;按 event_id 去重 |
| wins[].event_id / game_code | string | 展示事件编号/游戏标识 |
| wins[].nickname / avatar / country_code | string | 显示资料,国家可为空,不是玩家唯一身份 |
| wins[].amount | string | 正整数文本,原始金额单位 |
| wins[].amount_type | string | 当前为 net_win,净赢展示 |
| wins[].occurred_at | integer | 事件发生时间,Unix 秒 |
真人动态按合作方过滤,机器人动态共享。首次或 reset 从全局最新至多 20 个序号开始,过滤后可能更少;内存保留最多 2000 条、展示窗口约 10 分钟,不保证历史重放。持续使用返回 cursor 获取后续批次。无参数 limit 或历史时间范围查询,不得据此对账。
健康检查
GET /api/v1/health
无请求体,无需 token。此接口只检查 HTTP 入口就绪情况。
{
"status": "ok",
"pending": 0
}
| 字段 | 类型 | 说明 |
|---|---|---|
| status | string | ok 表示入口就绪;starting 表示启动中,两者均可能为 HTTP 200 |
| pending | integer | HTTP 入口当前待处理请求数 |
健康检查成功不能证明数据库、全部游戏实例、WebSocket 或第三方回调健康。公开路由不提供充值、余额修改或历史账本查询接口。