task-svr/docs/uaw.md
2024-03-22 19:51:51 +08:00

629 lines
10 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.

# UAW相关接口
### 说明
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 开始)
> 默认返回100条记录, 如果要返回不同数量, query param传 limit
#### Response
```json
[
{
"rank": 1, // 排名, 从1开始
"level": 1, // 段位
"nickname": "昵称",
"score": 1 //获得的积分
}
]
```
### 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": "自己的邀请码",
"mapopen": 0, // 地图开启状态, 0: 未开启, 1: 已开启
}
```
### 11.\* 签到列表
#### 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, //连签天数
"total": 10 //累计签到天数
},
]
```
### 12.\* 探索状态
#### Request
- URL`/api/game/stat`
- 方法:`GET`
- 头部:
- Authorization: Bearer JWT_token
#### Response
```js
{
ticket: 1, // 可用探索次数
todayStat: 0, // 当日签到状态, 0: 未签到, 1: 已签到,但未领取 9:已签到, 已领取
todayTickets: 1, // 当日签到可领取次数
daysTotal: 1, // 累计签到天数
daysSeq: 1, // 连续签到天数
totalStat: [{ // 累计签到状态
days: 3, // 天数
tickets: 2, // 满足条件后可领取数量
state: 0, // 领取状态: 0: 未领取, 1: 可领取, 9: 已领取
}],
signCfg: [{ // 连续签到配置
days: 2, //天数
tickets: 1, //额外增加的次数
}]
}
```
### 13.\* 探索
#### Request
- URL`/api/game/step`
- 方法:`POST`
- 头部:
- Authorization: Bearer JWT_token
body:
```js
{
"step": 2 // 使用的次数
}
```
#### Response
```js
{
score: 20, //获得积分数量
chest: [{
id: '1112323131', // 获得宝箱id
level: 1, //宝箱品级
}]
}
```
### 14.\* 领取累计签到奖励
#### Request
- URL`/api/user/checkin/claim`
- 方法:`POST`
- 头部:
- Authorization: Bearer JWT_token
body:
```js
{
"days": 3 // 领取的累计签到天数
}
```
#### Response
```js
{
ticket: 2, //获得探索次数
}
```
### 15.\* 已邀请列表
#### Request
- URL`/api/activity/invite_list`
- 方法:`GET`
- 头部:
- Authorization: Bearer JWT_token
#### Response
```js
[{
level: 1, // 段位
nickname: '用户昵称',
score: 100, // 获得的积分
}]
```
### 16.\* 宝箱列表
#### Request
- URL`/api/chest/list`
- 方法:`GET`
- 头部:
- Authorization: Bearer JWT_token
#### Response
```js
[{
id: 1, // 箱子id
stat: 0, // 0: 锁定, 1: 正常
shareCode: '箱子的分享码',
level: 1, // 箱子品级
maxBonus: 10, // 最大可助力数量
scoreInit: 5, // 初始可获得积分
scoreBonus: 10, // 助力增加的分数
bonusCount: 2, // 已助力次数
}]
```
### 17.\* 宝箱助力记录
#### Request
- URL`/api/chest/enhance/list`
- 方法:`POST`
- 头部:
- Authorization: Bearer JWT_token
body:
```js
{
chestid: '12312313' // 宝箱id
}
```
#### Response
```js
[{
level: 1, // 段位
nickname: '用户昵称',
score: 100, // 获得的积分
}]
```
### 18.\* 宝箱助力
#### Request
- URL`/api/chest/enhance`
- 方法:`POST`
- 头部:
- Authorization: Bearer JWT_token
body:
```js
{
code: '131aasd`1' // 宝箱的分享码
}
```
#### Response
```js
{
score: 100, // 自己获得的积分
}
```
### 19.\* 开启宝箱(这个应该会修改)
#### Request
- URL`/api/chest/open`
- 方法:`POST`
- 头部:
- Authorization: Bearer JWT_token
body:
```js
{
chestid: '131aasd`1' // 宝箱id
}
```
#### Response
```js
{
score: 100, // 获得的积分
}
```
### 20.\* 宝箱开启记录
#### Request
- URL`/api/chest/open/history`
- 方法:`GET`
- 头部:
- Authorization: Bearer JWT_token
#### Response
```js
[{
chest: '123123123',
level: 1, // 箱子品级
score: 100, // 获得的积分
time: 111 // 开启时间
}]
```
### 21.\* 积分详情列表
#### Request
- URL`/api/activity/score_list`
- 方法:`GET`
- 头部:
- Authorization: Bearer JWT_token
#### Response
```js
[{
score: 100, // 获得的积分
type: '', // 获取原因
time: 111 // 开启时间
}]
```
### 22.\* 开启地图
#### Request
- URL`/api/game/open`
- 方法:`GET`
- 头部:
- Authorization: Bearer JWT_token
> 返回没errcode就表示开启成功
### 23.\* 检查签到并领取奖励
#### Request
- URL`/api/user/checkin`
- 方法:`POST`
- 头部:
- Authorization: Bearer JWT_token
#### Response
```js
{
ticket: 1 // 获得的探索次数
}
```