API Documentation
This page contains detailed documentation for the 2J Game API, including global interface descriptions, error code definitions, amount parameters, game types, and more. By reading this page, developers can understand how to interact with 2J Game servers, how to handle different types of game requests, and how to handle API error codes.
Seamless Wallet Mode and Transfer Wallet Mode are two wallet modes provided by 2J Game. OPs can choose the appropriate mode based on their needs.
Seamless Wallet Mode
Seamless Wallet Mode refers to the seamless integration of user account balances between OP and 2J, where users do not need to perform deposits and withdrawals between OP and 2J. When players play on the 2J platform (such as betting and payout actions), 2J will operate the player's account by calling OP's interface.
Interaction Flow
Integration Documentation
Click to view Seamless Wallet Mode Integration Documentation
Transfer Wallet Mode
Transfer Wallet Mode refers to the transfer operation of user account balances between OP and 2J. OP needs to call 2J's interface to perform deposits and withdrawals for player accounts. When players play on the 2J platform (such as betting and payout actions), 2J will directly operate the player's account, and OP can query the player's account balance by calling 2J's interface.
Interaction Flow
Integration Documentation
Click to view Transfer Wallet Mode Integration Documentation
Global Interface Description
Amount Parameters
Amount parameters in interface interactions between OP and 2J servers are in li (厘) units, with data type int64.
1 yuan = 1000 li
1 fen = 10 li
Interface Signature
Every request between OP and 2J servers must carry parameters in the querystring, as shown in the following example:
/seamless/launch?mch=108&ts=1710230433000&sign=f764e34bb223966caf66d88e8e1c817f
Query parameter description:
- mch is the identifier ID assigned by 2J to the accessing OP (usually a three-digit or four-digit ID)
- ts is timestamp in milliseconds
- sign, the sign generation rule is MD5(httpjsonbody+ts+key), OP needs to request a key from 2J before integration
Example code for calculating 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()
## If the final call URL is: /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)
Signature Test Tool
You can use the interactive signature test tool below to verify your signature calculations:
Response Structure
All interface response structures contain the following fields:
{
"header": {
"code": 0, // Error code, 0 means normal, non-0 means abnormal
"msg": "", // Error message
"timestamp": 1709716095516
},
}
Common Interfaces
1. User Registration /open2j/c/create
/open2j/c/create
is renamed from/open/seamless/create
, please update your code.
Method: POST
URI: /open2j/c/create
Description: Used to register user information on the 2J server.
Request Body:
Content-Type: application/json
{
"op_id": "xxx-xxx-aaa", // OP side user's unique identifier, required
"user_info": {
"nickname": "player01", // OP player nickname. Note: emoji special characters not supported
"gender": 0, // 0-unknown, 1-female, 2-male
"cnt": "ph", // Default country
"lan": "en" // Default language
}
}
Parameter description:
Parameter | Type | Description | Note |
---|---|---|---|
op_id | string | Unique user identifier from OP side | Required |
user_info | object | User information | Required |
user_info.nickname | string | Player nickname from OP | Required |
user_info.gender | int | Player gender from OP | Required |
user_info.cnt | string | Default country | Optional |
user_info.lan | string | Default language | Optional |
Response Body:
Content-Type: application/json
{
"header": {
"code": 0,
"trace_id": "9cd0bfd22447bf607d20a3c2ac4e304a",
"msg": "",
"timestamp": 1710310573038
}// Common response header
}
2. Get Game Link /open2j/c/launch
/open2j/c/launch
is renamed from/open/seamless/launch
, please update your code.
Method: POST
URI: /open2j/c/launch
Description: Used to get game link interface.
Request Body:
Content-Type: application/json
{
"op_id": "xxx-xxx-aaa", // Required. OP side user's unique identifier
"game_id": 65005, // Required. Game ID
"lang": "en-US",
"backlink": "http://xxxxx.com?a=ss", // Return to OP address
"device_type": 2, // Optional. Player client type 1: h5, 2: android, 3: ios
"device_id": "AD19939", // Optional. Player client device unique ID
"ret_lobby_btn": false, // Optional. Whether to show return to lobby button
"full_screen": 1, // Optional. Controls whether to automatically enter fullscreen when using browser 1: don't enter fullscreen 2: automatically enter fullscreen, if not provided, controlled by 2j server
"auto_create_account": false, // Optional. Whether to automatically create an account, true: automatically create an account, false: do not automatically create an account
"keep_token": false // Optional. Whether to keep token unchanged
}
Parameter description:
Parameter | Type | Description | Note |
---|---|---|---|
op_id | string | Unique user identifier from OP side | Required |
game_id | int | Game ID | Required |
lang | string | Language | Optional |
backlink | string | Return URL to OP | Optional |
device_type | int | Client device type 1: h5, 2: android, 3: ios | Optional |
device_id | string | Unique device ID of client | Optional |
ret_lobby_btn | bool | Whether to display return to lobby button | Optional |
full_screen | int | Control auto fullscreen in browser mode | Optional |
auto_create_account | bool | Whether to automatically create an account | Optional |
keep_token | bool | Whether to keep token unchanged | Optional |
- game_id detailed list can be found here
- lang reference: https://zh.wikipedia.org/wiki/ISO_639-1
- backlink: Controls the logic executed by the exit game button in the game
- If about:blank or empty is passed, triggers code:
window.close()
- If a link is passed, triggers code:
window.location.href=backlink
- If using Iframe to open the game, you can use setting backlink parameter as script, for example: javascript:window.parent.postMessage({ type: 'exit_customer_page'}, '*'), this will trigger the parent page's onmessage event, then the parent page can handle according to the type parameter.
- If about:blank or empty is passed, triggers code:
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. Evict User /open2j/c/evict
open2j/c/evict
is renamed from/open/seamless/evict
, please update your code.
Method: POST
URI: /open2j/c/evict
Description: Provided to OP for evicting users. If the player is in a game, they will be forcibly exited from the game.
Note: After being evicted, the player will receive a popup notification informing them of the eviction, but if OP did not provide a
backlink
parameter when calling/open2j/c/launch
, the player will not be able to return to the OP side.
Request Body:
Content-Type: application/json
{
"op_id": "xxx-xxx-aaa", // Required. OP side user's unique identifier
}
Response Body:
Content-Type: application/json
Note: If the player is in multiple games, the game information will be returned for the latest active game.
{
"header": {
"code": 0,
"trace_id": "9cd0bfd22447bf607d20a3c2ac4e304a",
"msg": "",
"timestamp": 1710310573038
},
"game_info": {
"game_id": 1006, // Game ID
"join_at": 1720686368, // Join time
"leave_at": 1720686368, // Leave time
}
}
4. Detect User Gaming Status /open2j/c/detect-user-gaming
Method: POST
URI: /open2j/c/detect-user-gaming
Description: Used to detect user's gaming status.
Request Body:
Content-Type: application/json
{
"op_id": "xxx-xxx-aaa" // Required. Unique user identifier from OP side
}
Response Body:
Content-Type: application/json
{
"header": {
"code": 0,
"trace_id": "9cd0bfd22447bf607d20a3c2ac4e304a",
"msg": "",
"timestamp": 1710310573038
},
"is_gaming": false, // Whether the user is in game
"game_ids": [1006] // List of game IDs
}