增加文档
This commit is contained in:
parent
dce93c7433
commit
77ebcfaa60
77
doc/api.md
Normal file
77
doc/api.md
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
# 答题游戏接口说明
|
||||||
|
## 一. 说明
|
||||||
|
|
||||||
|
所有接口均需上传sessionid
|
||||||
|
|
||||||
|
通用返回JSON结构, 接口Response的数据结构说明只包含data部分
|
||||||
|
``` JSON
|
||||||
|
{
|
||||||
|
"errcode": 0, //0:成功 2: 缺少必要参数(accountid, sessionid) 4: 帐号被封, 5: 帐号未找到 100: 所有未定义的错误
|
||||||
|
"errmsg": "", //错误描述
|
||||||
|
"data": {}, // 数据
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## 二. 客户端接口列表
|
||||||
|
|
||||||
|
### 1. 获取关卡题目列表
|
||||||
|
|
||||||
|
1. Method: POST
|
||||||
|
2. URI: /api/:accountid/puzzle/list
|
||||||
|
|
||||||
|
| 字段 | 说明 |
|
||||||
|
| -------- | -------------------------------------- |
|
||||||
|
| accountid | 帐号id |
|
||||||
|
|
||||||
|
> POST参数
|
||||||
|
|
||||||
|
|
||||||
|
| 字段 | 说明 |
|
||||||
|
| -------- | -------------------------------------- |
|
||||||
|
| shop | 店铺id |
|
||||||
|
| level | 关卡id |
|
||||||
|
|
||||||
|
3. Response: JSON
|
||||||
|
|
||||||
|
```js
|
||||||
|
{
|
||||||
|
"id": "6080f330b9655b5c0467ee5e", // 题目id
|
||||||
|
"title": "“大丈夫为国捐躯,死而无憾!”这话是谁说的?", // 问题
|
||||||
|
"answers": [ // 可选答案
|
||||||
|
"刘铭传",
|
||||||
|
"徐骧",
|
||||||
|
"刘步蟾",
|
||||||
|
"刘永福"
|
||||||
|
],
|
||||||
|
"type": 1 // 题目类型 1: 普通的文字选择题, 2: 图形
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 1. 获取关卡题目列表
|
||||||
|
|
||||||
|
1. Method: POST
|
||||||
|
2. URI: /api/:accountid/puzzle/answer
|
||||||
|
|
||||||
|
| 字段 | 说明 |
|
||||||
|
| -------- | -------------------------------------- |
|
||||||
|
| accountid | 帐号id |
|
||||||
|
|
||||||
|
> POST参数
|
||||||
|
|
||||||
|
|
||||||
|
| 字段 | 说明 |
|
||||||
|
| -------- | -------------------------------------- |
|
||||||
|
| id | 题目id |
|
||||||
|
| level | 关卡id |
|
||||||
|
| answer | 回答的选项 |
|
||||||
|
|
||||||
|
3. Response: JSON
|
||||||
|
|
||||||
|
```js
|
||||||
|
{
|
||||||
|
result: 1 //答题结果 1: 正确, 0 : 错误
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
@ -92,8 +92,8 @@ export class ApiServer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
private setErrHandler() {
|
private setErrHandler() {
|
||||||
this.server.setNotFoundHandler(function(request: any, reply: { send: (arg0: { code: number; msg: string; }) => void; }){
|
this.server.setNotFoundHandler(function(request: any, reply: { send: (arg0: { errcode: number; errmsg: string; }) => void; }){
|
||||||
reply.send({code: 404, msg: 'page not found'})
|
reply.send({errcode: 404, errmsg: 'page not found'})
|
||||||
});
|
});
|
||||||
this.server.setErrorHandler(function (error: FastifyError, request: FastifyRequest, reply: FastifyReply) {
|
this.server.setErrorHandler(function (error: FastifyError, request: FastifyRequest, reply: FastifyReply) {
|
||||||
let statusCode = error && error.statusCode || 100;
|
let statusCode = error && error.statusCode || 100;
|
||||||
@ -104,7 +104,7 @@ export class ApiServer {
|
|||||||
} else {
|
} else {
|
||||||
logger.error(error)
|
logger.error(error)
|
||||||
}
|
}
|
||||||
reply.code(200).send({code: statusCode, msg: error ? error.message : 'unknown error'})
|
reply.code(200).send({errcode: statusCode, errmsg: error ? error.message : 'unknown error'})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@ -122,7 +122,7 @@ export class ApiServer {
|
|||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
if (!payload.code) {
|
if (!payload.code) {
|
||||||
payload = {
|
payload = {
|
||||||
code: 0,
|
errcode: 0,
|
||||||
data: payload
|
data: payload
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -136,7 +136,7 @@ export class ApiServer {
|
|||||||
self.initControllers();
|
self.initControllers();
|
||||||
self.registerRouter();
|
self.registerRouter();
|
||||||
self.setErrHandler();
|
self.setErrHandler();
|
||||||
// self.setFormatSend();
|
self.setFormatSend();
|
||||||
this.server.listen({port: config.api.port}, (err: any, address: any) => {
|
this.server.listen({port: config.api.port}, (err: any, address: any) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
logger.log(err)
|
logger.log(err)
|
||||||
|
@ -5,7 +5,7 @@ import { ZError } from '../../common/ZError'
|
|||||||
|
|
||||||
class PuzzleController extends BaseController {
|
class PuzzleController extends BaseController {
|
||||||
@role('anon')
|
@role('anon')
|
||||||
@router('post /puzzle/list')
|
@router('post /api/:accountid/puzzle/list')
|
||||||
async list(req, res) {
|
async list(req, res) {
|
||||||
let { shop, level } = req.params
|
let { shop, level } = req.params
|
||||||
let count = 10
|
let count = 10
|
||||||
@ -31,7 +31,7 @@ class PuzzleController extends BaseController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@role('anon')
|
@role('anon')
|
||||||
@router('post /puzzle/answer')
|
@router('post /api/:accountid/puzzle/answer')
|
||||||
async report(req, res) {
|
async report(req, res) {
|
||||||
let { id, answer } = req.params
|
let { id, answer } = req.params
|
||||||
if (!id || !answer) {
|
if (!id || !answer) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user