task-svr/docs/api.md
2024-01-17 15:49:18 +08:00

541 lines
9.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Task相关接口
### 说明
1. 通用返回格式, errcode=0 表示无错误
2. 如无特别说明, 以下接口的 Response 格式指的是 data 字段
3. 接口名中带\*的表示, 需要验证 token, token 可以设置 header 的 Authorization: Bearer JWT_token, 或 Post body 的 token 字段, 或 Get 的 query token
```json
{
"errcode": Number,
"errmsg": String,
"data": {}
}
```
### 1. 钱包预登录
#### Request
- URL`/api/wallet/nonce?address=`
- 方法:`GET`
query param
| Name | Type | Desc |
| ------- | ------ | -------- |
| address | string | 钱包地址 |
#### Response
```json
{
"nonce": String,
"tips": String
}
```
### 2. 钱包登录
客户端在获得钱包地址后,须先调用预登录方法获取 nonce 和 tips, 然后调用钱包进行 EIP-721 签名.
登录成功后返回的 jwt 需要保存至本地存储, 再次载入后, 可解析并获取 exp 字段, 判断当前 token 是否已经过期
#### Request
- URL`/api/wallet/login`
- 方法:`POST`
- 头部:
- Content-type: application/json
- Body:
```json
{
"activity": String,
"signature": String,
"message": SiweMessage
}
```
SiweMessage说明: https://docs.login.xyz/sign-in-with-ethereum/quickstart-guide/creating-siwe-messages
SiweMessage的nonce说明(具体参考例子):
```
1. 从钱包预登录接口获取nonce
2. nonce = nonce + '|' + 钱包类型字符串 // 比如okx钱包, nonce|okx
3. 使用 活动id 作为 key, 调用aesEncrypt 加密步骤2的字符串
4. 将hex string 转换成base58, 传给SiweMessage
```
#### Response
```json
{
"token": String,
}
```
### 3. 活动信息
#### Request
- URL`/api/activity/:id`
- 方法:`GET`
- 参数:
- `id`当前活动的ID
#### Response
```js
{
"_id": "TwitterConnect", // 任务id
"name": "活动名称",
"description": "活动描述",
"tasks": [ // 该活动需要完成的任务
{
"id": "任务id",
"task": "任务类型",
"title": "任务名",
"desc": "任务描述",
"type": 1, //任务类型, 1: 一次性任务, 2: 日常任务
"repeat": 1, // 任务可重复次数
"pretasks": ["task id 1"], //前置任务
"score": 0, // 完成任务可获得的积分
"category": "", // 任务分类
"cfg": {}, // 其他一些任务相关配置参数, 比如icon, 或者其他未考虑的参数
"end": false, // 是否已经结束
"autoclaim": false // 任务完成后是否自动获取奖励
}
],
"startTime": 1702628292366, // 活动开始时间
"endTime": 1705220292366 // 活动结束时间
}
```
### 4. *用户任务进度
#### Request
- URL`/api/tasks/progress`
- 方法:`POST`
- 头部:
- Authorization: Bearer JWT_token
- Body: {}
#### Response
```js
[
{
"status": 2, // 任务状态, 0: 未开始, 1: 进行中, 2: 成功, 9: 失败
"id": "TwitterConnect", // 任务id
"timeStart": 1703150269527, // 任务开始时间
"data": { // 当前任务带的额外信息, 比如twitter的id和昵称等
"username": "zhl01",
"userid": "564269223"
},
"timeFinish": 1703150280059 // 任务结束时间
}
]
```
### 5.\* 开始某个任务
#### Request
- URL`/api/tasks/begin_task`
- 方法:`POST`
- 头部:
- Authorization: Bearer JWT_token
body:
```js
{
"task": "TwitterFollow" // 任务id
}
```
#### Response
```json
{
"status": 1, // 任务状态, 0: 未开始, 1: 进行中, 2: 成功, 9: 失败
"id": "TwitterFollow", // 任务id
"timeStart": 1703150294051 // 任务开始时间
}
```
### 6.\* 检查任务状态
#### Request
- URL`/api/tasks/check_task`
- 方法:`GET`
- 头部:
- Authorization: Bearer JWT_token
body:
```js
{
"task": "TwitterFollow" // 任务id
}
```
#### Response
```json
{
"status": 1, // 任务状态, 0: 未开始, 1: 进行中, 2: 成功, 9: 失败
"id": "TwitterFollow", // 任务id
"timeStart": 1703150294051, // 任务开始时间
"timeFinish": 1703151338598
}
```
### 7.\* 获取任务奖励
#### Request
- URL`/api/tasks/claim`
- 方法:`GET`
- 头部:
- Authorization: Bearer JWT_token
body:
```js
{
"task": "TwitterFollow" // 任务id
}
```
#### Response
```json
{
"status": 1, // 任务状态, 0: 未开始, 1: 进行中, 2: 成功, 9: 失败
"id": "TwitterFollow", // 任务id
"timeStart": 1703150294051, // 任务开始时间
"timeFinish": 1703151338598
}
```
### 8.\* 提交邀请码
#### Request
- URL`/api/activity/upload_invite_code`
- 方法:`GET`
- 头部:
- Authorization: Bearer JWT_token
body:
```js
{
"code": "邀请人的邀请码"
}
```
#### Response
> 只要不返回errcode, 即表示上传成功
```json
{}
```
### 9. 积分排行榜
#### Request
- URL`/api/activity/leaderboard/:activity/:page`
- 方法:`GET`
- 头部:
- Authorization: Bearer JWT_token
- 参数:
- `activity`当前活动的ID
- `page` (返回数据的分页序号, 0 开始)
> 默认返回50条记录, 如果要返回不同数量, query param传 limit
#### Response
```json
[
{
"rank": 1, // 排名, 从1开始
"address": "钱包地址",
"invite": "邀请人的地址",
"score": 获得的积分,
"yesterday": 上一日得分
}
]
```
### 10.\* 用户状态
#### Request
- URL`/api/user/state`
- 方法:`GET`
- 头部:
- Authorization: Bearer JWT_token
#### Response
```json
{
"address": "钱包地址",
"boost": 1, // 正常值为1
"boostExpire": 0, // 计算得分时, 如果boost过期, 即使boost大于1, 也不计算boost
"twitterId": "",
"twitterName": "",
"discordId": "",
"discordName": "",
"scoreToday": 100, // 今日获得积分
"scoreTotal": 200, // 总积分
"rankTotal": "-",
"invite": "邀请人address",
"inviteCount": 0, // 我邀请的用户总数
"inviteScore": 0, // 我邀请用户总数获得的分数
"code": "自己的邀请码"
}
```
### 11.\* boost
#### Request
- URL`/api/user/state/boost`
- 方法:`GET`
- 头部:
- Authorization: Bearer JWT_token
#### Response
```json
{
"boost": 1, // 正常值为1
"boostExpire": 0, // 计算得分时, 如果boost过期, 即使boost大于1, 也不计算boost
}
```
### 12.\* 签到列表
#### Request
- URL`/api/user/checkin/list/:tag`
- 方法:`GET`
- 头部:
- Authorization: Bearer JWT_token
query param
| Name | Type | Desc |
| ------- | ------ | -------- |
| tag | string | last: 最新, 前一天+今天, 1month: 当月 |
#### Response
```json
[
{
"address": "钱包地址",
"day": "20240105", // 格式化后签到日期, 时区按SG(UTC+8)
"time": 1704436745, // 具体的签到时间
"count": 0 //连签天数
},
]
```
### 13.\* 抽奖状态
#### Request
- URL`/api/lottery/stats`
- 方法:`GET`
- 头部:
- Authorization: Bearer JWT_token
#### Response
```json
{
"amount": 1, // 今日可抽数量
"daily": 0, // 今日通过每日签到获得的抽奖机会
"share": 0, // 今日通过邀请获得的抽奖机会
"gacha": 0, // 今日通过gacha获得的抽奖机会
"used": 0, // 今日已抽数量
"day": "20240110",
"items": [{
"id": "thunder",
"amount": 1, //数量
}]
}
```
### 14.\* 活动配置
#### Request
- URL`/api/lottery/items`
- 方法:`GET`
- 头部:
- Authorization: Bearer JWT_token
#### Response
```json
{
"start": "活动开始时间",
"end": "活动结束时间",
"items": [
{
"id": "物品id",
"name": "物品名称",
"amount": 1 //物品数量
},
]
}
```
### 15.\* 抽奖
#### Request
- URL`/api/lottery/draw`
- 方法:`GET`
- 头部:
- Authorization: Bearer JWT_token
#### Response
```json
{
"id": "物品id 或 empty(未获得任何奖励)",
"amount": "数量"
}
```
### 16.\* 合成
#### Request
- URL`/api/lottery/fusion`
- 方法:`POST`
- 头部:
- Authorization: Bearer JWT_token
#### Response
```json
{
"id": "物品id",
"amount": "数量"
}
```
### 17.\* 查询抽奖历史记录
#### Request
- URL`/api/lottery/history`
- 方法:`POST`
- 头部:
- Authorization: Bearer JWT_token
body:
```json
{
"day": "20240111", // 按日查询, 传格式化后的日期(yyyyMMDD), "all"表示查询所有
"page": 1, // 分页, 从1开始, 可为空, 默认1
"limit": 10, // 分页记录数, 可为空, 默认10
}
```
#### Response
```json
{
"count": 100, //记录总数
"page": 1, // 分页
"limit": 10, // 分页记录数
"records":[{
"id": "物品id",
"day": "20240111",
"amount": "数量"
}]
}
```
### 18.\* 用户已质押列表
#### Request
- URL`/api/stake/list`
- 方法:`GET`
- 头部:
- Authorization: Bearer JWT_token
#### Response
```json
[
{
"nft": "nft地址",
"nftid": "1", // nftid
"start": 12312111, //质押开始时间
"cd": 11111, // cd时间, 从开始质押开始计算cd, cd未到的话, 无法赎回
"stakeTime": 11222, //质押时长
}
]
```
### 19.\* Claim USDT
#### Request
- URL`/api/lottery/claim_usdt`
- 方法:`GET`
- 头部:
- Authorization: Bearer JWT_token
#### Response
```json
{
"token": "0x1304E6AA241eE3C9ea44Db9e593e85Ae76eC41F1",
"amount": "20000000000000000",
"startTime": 1705041164,
"saltNonce": "111",
"signature": "签名"
}
```