Dragon and Tiger
APIs
当前回合
GET /games/:game/current-round
const gameId = route.params.id;
axios.get(`/games/${gameId}/current-round`).then(response => {
console.log(response);
}).catch(error => {
console.log(error);
});
{
"data": {
"id": 4117,
"transaction": "20240510131730",
"game": {
"id": 1,
"name": "Dragon and Tiger",
"subtitle": "Draw every 60 seconds",
"thumbnail": "https://example.com/games/thumbnails/dragon-and-tiger.png",
"description": "Dragon and Tiger (Draw every 60 seconds).",
"meta": {
"seconds": "60",
"dragon": "1.96",
"tie": "15.68",
"tiger": "1.96"
}
},
"payload": null,
"status": 0,
"created_at": "2024-05-10T13:17:30.000000Z",
"draw_at": "2024-05-10T13:18:00.000000Z",
"created_timestamp": 1715347050,
"draw_timestamp": 1715347080
}
}
往期回合
默认响应最近100条记录,不包含未结束的回合(当前回合)。
GET /games/:game/rounds
const gameId = route.params.id;
axios.get(`/games/${gameId}/rounds`).then(response => {
console.log(response);
}).catch(error => {
console.log(error);
});
查询回合
GET /games/:game/rounds/:round
const gameId = route.params.id;
const roundId = 1;
axios.get(`/games/${gameId}/rounds/${roundId}`).then(response => {
console.log(response);
}).catch(error => {
console.error(error);
});
{
"data": {
"id": 4117,
"transaction": "20240510131730",
"game": {
"id": 1,
"name": "Dragon and Tiger",
"subtitle": "Draw every 30 seconds",
"thumbnail": "https://example.com/games/thumbnails/dragon-and-tiger.png",
"description": "Dragon and Tiger (Draw every 30 seconds).",
"meta": {
"seconds": "30",
"dragon": "1.96",
"tie": "15.68",
"tiger": "1.96"
}
},
"payload": [
{
"suit": 2,
"value": 12
},
{
"suit": 2,
"value": 13
}
],
"status": 1,
"created_at": "2024-05-10T13:17:30.000000Z",
"draw_at": "2024-05-10T13:18:00.000000Z",
"created_timestamp": 1715347050,
"draw_timestamp": 1715347080
}
}
下单
POST /bets
dragon or tiger or tie
const gameId = 1;
const roundId = 1;
axios.post(`/bets`, {
game_id: gameId, // 游戏ID
round_id: roundId, // 回合ID
bets: [
{
unit_bet: 1000, // 单价
quantity: 1, // 数量
value: 'dragon', // 值
},
{
unit_bet: 1000,
quantity: 1,
value: 'tiger',
},
{
unit_bet: 1000,
quantity: 1,
value: 'tie',
},
]
}).then(() => {
// successful
}).catch(error => {
console.error(error);
// 422 Unprocessable Content 表单验证未通过
// 429 Too Many Requests 手速太快了,别点那么快~
// 401 Unauthorized 未登录
// 500 Internal Server Error 服务器错误
});
错误代码参考
| 代码 | 说明 |
|---|---|
| 42201 | 余额不足 |
| 42202 | 游戏维护 |
| 42203 | 回合已结束(本轮已开奖) |
只有以上错误,才会响应 code 字段,其他错误不会响应 code 字段。
if (error.response.status === 422) {
const data = error.response.data;
if (typeof data.code !== 'undefined') {
switch(data.code) {
// ...
}
}
// ...
}
// ...
错误响应示例
HTTP Status Code: 422
{
"message": "The round is closed.",
"errors": {
"round_id": [
"The round is closed."
]
},
"code": 42203
}
下单记录
const gameId = 1;
axios.get(`/games/${gameId}/my-bets`).then(response => {
console.log(response);
}).catch(error => {
console.error(error);
});
WebSockets
新回合开始
const gameId = route.params.id;
Echo.channel(`games.${gameId}`)
.listen('RoundCreated', (e) => {
console.log(e);
});
{
"data": {
"id": 4117,
"transaction": "20240510131730",
"game": {
"id": 1,
"name": "Dragon and Tiger",
"subtitle": "Draw every 60 seconds",
"thumbnail": "https://example.com/games/thumbnails/dragon-and-tiger.png",
"description": "Dragon and Tiger (Draw every 60 seconds).",
"meta": {
"seconds": "60",
"dragon": "1.96",
"tie": "15.68",
"tiger": "1.96"
}
},
"payload": null,
"status": 0,
"created_at": "2024-05-10T13:17:30.000000Z",
"draw_at": "2024-05-10T13:18:00.000000Z",
"created_timestamp": 1715347050,
"draw_timestamp": 1715347080
}
}
回合结束
const gameId = route.params.id;
Echo.channel(`games.${gameId}`)
.listen('RoundClosed', (e) => {
console.log(e);
});
{
"data": {
"id": 4117,
"transaction": "20240510131730",
"game": {
"id": 1,
"name": "Dragon and Tiger",
"subtitle": "Draw every 30 seconds",
"thumbnail": "https://example.com/games/thumbnails/dragon-and-tiger.png",
"description": "Dragon and Tiger (Draw every 30 seconds).",
"meta": {
"seconds": "30",
"dragon": "1.96",
"tie": "15.68",
"tiger": "1.96"
}
},
"payload": [
{
"suit": 2,
"value": 12
},
{
"suit": 2,
"value": 13
}
],
"status": 1,
"created_at": "2024-05-10T13:17:30.000000Z",
"draw_at": "2024-05-10T13:18:00.000000Z",
"created_timestamp": 1715347050,
"draw_timestamp": 1715347080
}
}
