咸余翻身API设计文档
- 咸余翻身API设计文档
- 1. 数据库初始化
- 2. 提交问卷答案
- 3. 获取问卷答案(单独的问卷以及所有的问卷信息)
- 4. 创建任务
- 5. 登陆
- 6. 注册
- 7. 获取验证码
- 8. 获取个人/组织信息(获取积分)
- 9. 存储临时照片
- 10. 充值
- 11. 获取图片
- 12. 获取所有接收者名单
- 13. 获取任务
- 14. 修改用户信息
- 15. 完成任务(事件)(涉及转账问题)
- 16. 获取问卷
- 17. 接收任务
- 18. 事件说明:
1. 数据库初始化
![]()
url = "/initial/"
methods = ['GET']
return_msg:
{
'error' : 0/1
'data':
{
'stus': 学生账号信息,
'orgs': 组织账号信息
}
}
2. 提交问卷答案
![]()
url = "/post_answer/"
methods = ['POST']
require:
task_id:
openid:
answer: (使用#进行切分)
return_msg:
{
'error' : 0/1
'data':
{
'msg': '提交成功'/ 错误信息
}
}
3. 获取问卷答案(单独的问卷以及所有的问卷信息)
3.1. 单独一份
url = "/get_answer/"
methods = ['GET']
require:
all: 0
task_id
openid:
return_msg:
{
'error' : 0/1
'data':
{
'msg': '获取成功'/ 错误信息
'answers': [
{
'题目':
'1':
'2':
'3':
'4':
'选项':
}
]
}
}
![]()
3.2. 全部问卷统计
url = "/get_answer/"
methods = ['GET']
require:
all: 1
task_id:
return_msg:
{
'error' : 0/1
'data':
{
'msg': '获取成功'/ 错误信息
'answers': [
{
'题目':
'1':
'2':
'3':
'4':
'统计': [1,2,3,4]
}
]
}
}
![]()
4. 创建任务
![]()
url = '/tasks/create/'
methods = ['POST']
require:
'text':
openid:
limit_time:
limit_num:
title:
content:
tag:
reward:
problem_content: //使用^作为problem的切分,使用$作为题目与答案的切分,使用#作为答案的切分(例子:p1$c1#c2#c3#c4^p2$c1#c2#c3#c4)
'file':
photo:
return_msg:
{
'error': 0/1
'data':
{
'msg': "余额不足/创建成功,已扣除??鱼币/没有图片上传/创建成功/图片上传失败/请将问卷填写完整"
}
}
5. 登陆
![]()
url = "/user/login/"
methods = ['GET', 'POST']
require:
type: student/ organization
email:
password:
return_msg:
{
'error' : 0/1
'error_message': '密码错误/账号不存在'
'data':
{
'openid':
}
}
6. 注册
![]()
url = "/user/register/"
methods = ['POST']
require:
email:
password:
student_id:
sex:
collage:
grade:
name:
validate_code:
return_msg:
{
'error' : 0/1
'error_message': '未获取验证码或验证码过期/验证码错误/帐户已经存在'
'data':
{
'openid':
}
}
7. 获取验证码
![]()
url = "/user/get_verification_code/"
methods = ['POST']
require:
email:
return_msg:
{
'error' : 0/1
'error_message': '原验证码未过期/验证码发送失败/验证码已发送'
}
8. 获取个人/组织信息(获取积分)
成功获取的:
不成功获取的:
![]()
url = "/my/"
methods = ['GET']
require:
openid:
cash: 1表示只获取cash信息,0表示获取全部
return_msg:
error: 0/1
data:
msg: '不存在该账号' (当error为1时有,为0时无)
若是学生
'email':
'student_id':
'name':
'sex':
'collage':
'grade':
'edu_bg':
'cash':
若是组织
'email':
'name':
'cash':
9. 存储临时照片
![]()
url = "/temp/upload/<openid>"
methods = ['POST']
return_msg:
{
'error' : 0/1
'data':
{
'msg': '没有图片上传/创建成功/图片上传失败'
'url': image_path
}
}
10. 充值
![]()
url = "/add_cash/<openid>"
methods = ['POST']
require:
money:
return_msg:
{
'error' : 0/1
'data':
{
'msg': '充钱成功/充钱失败'
}
}
11. 获取图片
![]()
url = "/_uploads/photos/<image_path>"
return picture
12. 获取所有接收者名单
- url: /tasks/get_recipients/
- method: GET
- request:
| 参数名 | 必选 | 类型 | 说明 |
|---|---|---|---|
| task_id | 是 | int | 任务id |
| last_accept_id | 是 | int | 当前显示的接收列表最老的那个last_accept_id,用来获取下滑获取更多recipients,若要获取最新的,则传入-1 |
- response:
{"error": 1, "data": {"msg": "参数错误"}}
{
"error": 0,
"data": {
"msg": "-1"(本次recipients的last_accept_id,如果后面没有更多了,则为-1),
"recipients": [{"openid": 1000002, "email": "email2@qq.com", "password": "", "student_id": "16340002", "name": "16340002", "sex": "未知", "collage": "心理学院", "grade": 2010, "edu_bg": "博士", "tag": "", "signature": "word6 word7 word8 word9 word10 word11 word12 word13 word14 word15 word16 word17 word18", "cash": 3758},{"openid": 1000000, "email": "email0@qq.com", "password": "", "student_id": "16340000", "name": "16340000", "sex": "女", "collage": "心理学院", "grade": 2018, "edu_bg": "博士", "tag": "问卷,其他", "signature": "word16 word17 word18 word19 word20 word21 word22 word23 word24 word25 word26 word27 word28 word29", "cash": 3355}]
}
}
![]()
13. 获取任务
- url: /tasks/search/
- method: GET
- request:
| 参数名 | 必选 | 类型 | 说明 |
|---|---|---|---|
| publisher_id | 否 | int | 发布者id |
| accepter_id | 否 | int | 接收者id |
| tag | 否 | string | 任务标签 |
| text | 否 | string | 根据任务title或content查询 |
| task_id | 否 | int | 任务id |
| last_id | 否 | int | 当前显示的任务列表最老的那个task id,用来获取下滑获取更多task,若要获取最新的,则传入-1 |
| status | 否 | string | 任务状态,与accepter_id搭配使用。(1) all: 所有的任务 (2) ongoing: 进行中,未完成,未过期(3) finished: 已完成(4) complete: 未完成,已过期(只与接受的任务搭配) |
| last_accept_time | 否 | string | 格式:”2019-06-05 22:02:24” 当前显示的接受任务列表中最晚的接受时间,若要获取最新的,则传入空字符串,与accepter_id搭配使用。作用类似last_id |
参数说明:
- publisher_id,accepter_id,tag,text,task_id 最多只能选一个
- 选择 publisher_id,tag,text 作为参数时,或者没有参数时,必须加 last_id 作为参数
http://localhost:5000/tasks/search/?tag=取快递&last_id=-1 - 选择 publisher_id 或 accepter_id 作为参数时,必须加 status 作为参数
http://localhost:5000/tasks/search/?publisher_id=1000003&status=all&last_id=-1 - 选择 accepter_id 作为参数时,必须加 last_accept_time 作为参数 ``` http://localhost:5000/tasks/search/?accepter_id=1000002&status=all&last_accept_time=2019-06-11 23:01:53
http://localhost:5000/tasks/search/?accepter_id=1000002&status=ongoing&last_accept_time=
* 选择 task_id 作为参数时,无需加其他参数
http://localhost:5000/tasks/search/?task_id=1
* response:
{
“error”: 0,
“data”: {
“msg”: “获取成功”/”2019-06-11 23:01:53”(last_accept_time),
“tasks”:[
{
“id”: 1,
“publish_id”: 1000003,
“publish_time”: “2019-06-05 22:02:24”,
“limit_time”: “2019-06-05 22:01:49”,
“limit_num”: 1,
“accept_num”: 0,
“title”: “222”,
“content”: “222”,
“tag”: “取快递”,
“image_path”: “http://localhost:5000/_uploads/photos/ZlBKRp-1.png”,
“reward”: 22,
“publisher”: {“openid”: 1000003, “email”: “email3@qq.com”, “password”: “pass3”, “student_id”: “16340003”, “name”: “16340003”, “sex”: “男”, “collage”: “药学院”, “grade”: 2014, “edu_bg”: “本科”, “tag”: “”, “signature”: “word12 word13 word14 word15 word16 word17 word18 word19 word20 word21 word22”, “cash”: 2299}
},
{
},
...
] } } ``` # 14. 修改用户信息 * url: /user/update/ * method: POST * request:
body:
| 参数名 | 必选 | 类型 | 说明 |
|---|---|---|---|
| openid | 是 | int | 学生或组织id |
| 是 | - | 属性名作为参数名 | |
| 否 | - | 属性名作为参数名 | |
| … | 否 | - | 属性名作为参数名 |
| old_password | 否 | string | 当修改密码时,需要传入旧密码 |
参数说明:
- attr_name可以为以下任意一个以上,个数不限
{"password": "pass3", "student_id": "16340003", "name": "16340003", "sex": "男", "collage": "药学院", "grade": 2014, "edu_bg": "本科", "signature": "word12 word13 word14 word15 word16 word17 word18 word19 word20 word21 word22"} - 若要修改password,则要加一个old_password属性
- response:
{"error": 0, "data": {"msg": "更改成功"}} {"error": 1, "data": {"msg": "不存在该学生或组织"}} {"error": 1, "data": {"msg": '请输入旧密码'}} {'error': 1, "data": {'msg': '旧密码错误'}} {'error': 1, "data": {'msg': '邮箱不可修改'}}
15. 完成任务(事件)(涉及转账问题)
![]()
url: "/finish_task/"
methods: ['POST']
require:
openid:
task_id:
return:
error: 0/1
data:
msg: '还没有接受该任务'/'任务完成, 已获取{}鱼币'/'发生异常'
16. 获取问卷
![]()
url: "/get_problem/<task_id>"
methods: ['GET']
return:
error:
data:
problem_content: 与发布问卷时的一致
17. 接收任务
![]()
url: "/tasks/accept/"
methods: ['POST']
require:
accepter_id:
task_id:
return:
error: 0/1
data:
msg: '不存在该任务/不能接受自己发布的任务/不存在该用户/不能重复接受任务/接受成功/发生异常'
18. 事件说明:
任务发布 -> 任务接受 -> 任务进行时 ->任务完成
扣钱 加钱
问卷发布 -> 问卷接受与填写 -> 问卷提交答案即视为完成
扣钱 加钱