API Documenation
本页面包含了 2J Game API 的详细说明,包括全局接口说明、错误码定义、金额参数、游戏类型等内容。通过阅读本页面,开发者可以了解如何与 2J Game 的服务器进行交互,如何处理不同类型的游戏请求,以及如何处理 API 返回的错误码。
Seamless Wallet 模式 和 Transfer Wallet 模式 是 2J Game 提供的两种钱包模式,OP 可根据自身需求选择合适的模式。
无缝钱包模式
无缝钱包(Seamless Wallet)模式是指用户的账户余额在 OP 和 2J 之间实现无缝对接,用户无需在 OP 和 2J 之间进行充值和提现操作。玩家在 2J 平台进行游玩时(如下注、派彩行为),2J 会通过调用 OP 的接口取操作玩家的账户。
交互流程
接入文档
点击查看 无缝钱包模式接入文档
转账钱包模式
转账钱包(Transfer Wallet)模式是指用户的账户余额在 OP 和 2J 之间实现转账操作,OP 需要调用 2J 的接口对玩家账号进行充值和提现操作,玩家在 2J 平台进行游玩时(如下注、派彩行为),2J 会直接操作玩家的账户,OP 可以通过调用 2J 的接口查询玩家的账户余额。
交互流程
接入文档
点击查看 转账钱包模式接入文档
全局接口说明
金额参数
OP 和 2J服务器之间接口交互中涉及到的金额参数都以厘为单位,数据类型为int64。
1元 = 1000厘
1分 = 10厘
接口签名
OP 和 2J 服务器之间每个请求 querystring 中都必须携带参数,参照如下案例:
/seamless/launch?mch=108&ts=1710230433000&sign=f764e34bb223966caf66d88e8e1c817f
Query 参数说明:
- mch 是 2J分配给接入OP的标识id(通常为三位或者四位id)
- ts 时间戳, milisecond
- sign, sign的生成规则为MD5(httpjsonbody+ts+key), OP 接入前需要向 2J 申请一个 key
计算sign的示例代码如下:
Python
import hashlib
def compute_md5(jsonbody, ts_str, key):
m = hashlib.md5()
m.update(jsonbody.encode('utf-8'))
m.update(ts_str.encode('utf-8'))
m.update(key.encode('utf-8'))
return m.hexdigest()
## 假如调用url最终为: /open2j/c/create?mch=xxx&ts=1718675696497&sign=your_sign
jsonbody = '''{"brd": "wl", "op_id": "60095050427", "user_info": {"cnt": "ph", "gender": 0, "lan": "en", "nickname": "60095050427"}}'''
ts_str = "1718675696497"
key = "example_key"
your_sign = compute_md5(jsonbody, ts_str, key)
## cbc16eea6ad1af1f63955d24b314e13a
print(your_sign)
Go
import "crypto/md5"
func ComputeMd5(dataStr []byte, key []byte) string {
h := md5.New()
h.Write(dataStr)
if len(key) > 0 {
h.Write(key)
}
return fmt.Sprintf("%x", h.Sum(nil))
}
body := `{"brd": "wl", "op_id": "60095050427", "user_info": {"cnt": "ph", "gender": 0, "lan": "en", "nickname": "60095050427"}}`
ts := "1718675696497"
key := "example_key"
part1 := []byte(body + ts)
part2 := []byte(key)
// cbc16eea6ad1af1f63955d24b314e13a
your_sign := ComputeMd5(part1, part2)
签名测试工具
您可以使用下面的交互式签名测试工具来验证您的签名计算:
响应结构
所有接口的响应结构体都包含以下字段:
{
"header": {
"code": 0, // 错误编码,0表示正常, 非0表示异常
"msg": "", // 错误提示
"timestamp": 1709716095516
},
}
通用接口
1. 用户注册 /open2j/c/create
/open2j/c/create
由/open/seamless/create
更名而来, 烦请更新。
Method: POST
URI: /open2j/c/create
Description: 用于在 2J 服务器上注册用户信息。
Request Body:
Content-Type: application/json
{
"op_id": "xxx-xxx-aaa", // op侧用户的唯一标识, required
"user_info": {
"nickname": "player01", // op 玩家昵称。注意:不支持 emoji 特殊字符
"gender": 0, // 0-unknow, 1-famale, 2-male
"cnt": "ph", // 默认国家
"lan": "en" // 默认语言
}
}
参数说明:
参数 | 类型 | 说明 | 备注 |
---|---|---|---|
op_id | string | op侧用户唯一标识 | 必要 |
user_info | object | 用户信息 | 必要 |
user_info.nickname | string | op 玩家昵称 | 必要 |
user_info.gender | int | op 玩家性别 | 必要 |
user_info.cnt | string | 默认国家 | 可选 |
user_info.lan | string | 默认语言 | 可选 |
Response Body:
Content-Type: application/json
{
"header": {
"code": 0,
"trace_id": "9cd0bfd22447bf607d20a3c2ac4e304a",
"msg": "",
"timestamp": 1710310573038
}// 通用响应header
}
2. 获取游戏链接 /open2j/c/launch
/open2j/c/launch
由/open/seamless/launch
更名而来, 烦请更新。
Method: POST
URI: /open2j/c/launch
Description: 用于获取游戏链接接口。
Request Body:
Content-Type: application/json
{
"op_id": "xxx-xxx-aaa", // 必填。op侧用户的唯一标识
"game_id": 65005, // 必填。游戏id
"lang": "en-US",
"backlink": "http://xxxxx.com?a=ss", // 返回 OP 地址
"device_type": 2, // 可选。玩家客户端类型 1: h5, 2: android, 3: ios
"device_id": "AD19939", // 可选。玩家客户端设备唯一id
"ret_lobby_btn": false, // 可选。是否显示返回大厅按钮
"full_screen": 1, // 可选。控制在使用浏览器情况下,是否自动进入全屏 1: 不进入全屏 2: 自动进入全屏,该参数未传由2j服务器控制是否自动进入全屏
"auto_create_account": false, // 可选。是否自动创建账号, true: 自动创建账号, false: 不自动创建账号
"keep_token": false // 可选。是否保持 token 不变
}
参数说明:
参数 | 类型 | 说明 | 备注 |
---|---|---|---|
op_id | string | op侧用户唯一标识 | 必要 |
game_id | int | 游戏id | 必要 |
lang | string | 语言 | 可选 |
backlink | string | 返回 OP 地址 | 可选 |
device_type | int | 玩家客户端类型 1: h5, 2: android, 3: ios | 可选 |
device_id | string | 玩家客户端设备唯一id | 可选 |
ret_lobby_btn | bool | 是否显示返回大厅按钮 | 可选 |
full_screen | int | 控制在使用浏览器情况下,是否自动进入全屏 | 可选 |
auto_create_account | bool | 是否自动创建账号 | 可选 |
keep_token | bool | 是否保持 token 不变 | 可选 |
- game_id 详细清单可参考这里
- lang 参考:https://zh.wikipedia.org/wiki/ISO_639-1
- backlink: 控制游戏中退出游戏按钮执行的逻辑
- 如果传 about:blank 或者为空 触发代码:
window.close()
- 如果传链接 触发代码:
window.location.href=backlink
- 如果是用Iframe的方式打开游戏,可以使用设置backlink参数为脚本的方式使用,例如:javascript:window.parent.postMessage({ type: 'exit_customer_page'}, '*'), 这样会触发父页面的onmessage事件,然后父页面可以根据type参数做相应的处理。
- 如果传 about:blank 或者为空 触发代码:
Response Body:
Content-Type: application/json
{
"header": {
"code": 0,
"trace_id": "9cd0bfd22447bf607d20a3c2ac4e304a",
"msg": "",
"timestamp": 1710310573038
},
"url": "http://abc.zzz?brd=default&chn=&lang=en-US&launch=blackjack&mch=108&opid=demo10087&token=6defed39fd6a4e98add31a4e1ead5172&version=1"
}
3. 踢出用户 /open2j/c/evict
路由
/open2j/c/evict
由/open/seamless/evict
更名而来, 烦请更新。
Method: POST
URI: /open2j/c/evict
Description: 提供给 OP 用于踢出用户, 如果玩家在游戏中,会被强制退出游戏。
注意:这里玩家被踢出后,会收到一个弹窗通知告知玩家被踢出,但如果 OP 在调用
/open2j/c/launch
时没有提供backlink
参数,会导致玩家无法返回 OP 端。
Request Body:
Content-Type: application/json
{
"op_id": "xxx-xxx-aaa", // 必填。op侧用户的唯一标识
}
Response Body:
Content-Type: application/json
注意:如果玩家同时在多个游戏中,那么 game_info 只会返回最近活跃的游戏。
{
"header": {
"code": 0,
"trace_id": "9cd0bfd22447bf607d20a3c2ac4e304a",
"msg": "",
"timestamp": 1710310573038
},
"game_info": {
"game_id": 1006, // 游戏id
"join_at": 1720686368, // 加入时间
"leave_at": 1720686368, // 离开时间
}
}
4. 查询玩家游戏状态 /open2j/c/detect-user-gaming
Method: POST
URI: /open2j/c/detect-user-gaming
Description: 用于查询玩家游戏状态。
Request Body:
Content-Type: application/json
{
"op_id": "xxx-xxx-aaa" // 必填。op侧用户的唯一标识
}
Response Body:
Content-Type: application/json
{
"header": {
"code": 0,
"trace_id": "9cd0bfd22447bf607d20a3c2ac4e304a",
"msg": "",
"timestamp": 1710310573038
},
"is_gaming": false, // 是否在游戏中
"game_ids": [1006] // 游戏id列表
}