完整 RESTful API 接口定义、请求参数、响应格式、错误码说明。接口总数 70+ 个。
https://api.example.com/v1{
"success": true,
"message": "操作成功",
"data": {},
"code": 200
}
| 错误码 | 说明 |
|---|---|
| 200 | 成功 |
| 400 | 请求参数错误 |
| 401 | 未授权(Token无效或过期) |
| 403 | 权限不足 |
| 404 | 资源不存在 |
| 500 | 服务器内部错误 |
Authorization: Bearer <token>
Content-Type: application/json
POST /api/auth/miniprogram/login
请求参数:
{
"code": "微信登录code"
}
响应数据:
{
"success": true,
"data": {
"token": "eyJhbGciOiJIUzI1NiIs...",
"user": {
"id": "user_001",
"openid": "oXXXX",
"phone": null,
"name": null,
"avatar": null,
"role": "researcher",
"isNewUser": true
}
}
}
POST /api/auth/bindPhone
请求参数: phoneCode(微信获取手机号的 code)
POST /api/auth/admin/login
请求参数: username, password
GET /api/user/profile
GET /api/user/statistics
GET /api/task/my-list
Query 参数: status, keyword, page, pageSize
GET /api/task/:id
POST /api/task/:id/start
POST /api/task/create
请求体含 title, description, geofenceId, formTemplateId, deadline, requirePhoto, photoLabels, maxAssignees, dispatchMode, openForGrab 等。
编辑任务 PUT /api/task/:id、删除 DELETE /api/task/:id、发布 POST /api/task/:id/publish、管理端列表 GET /api/task/admin/list。
POST /api/checkin 提交打卡;GET /api/checkin/:assignmentId 获取打卡记录;POST /api/checkin/validate 校验位置是否在围栏内。
POST /api/upload/image 上传照片(multipart/form-data);DELETE /api/photo/:id 删除;GET /api/photo/list/:assignmentId 获取任务照片列表。
POST /api/ocr/recognize 通用文字识别;POST /api/ocr/receipt 票据识别;POST /api/ocr/product 商品识别。
GET /api/form/template/:id 获取模板;POST /api/form/draft 保存草稿;POST /api/form/submit 提交表单。管理端:列表、创建、编辑、删除、复制模板。
GET /api/geofence/list 围栏列表;GET /api/geofence/:id 详情;POST /api/geofence/create 创建(circle/polygon);PUT /api/geofence/:id 编辑;DELETE /api/geofence/:id 删除。
GET /api/grab/list 可抢任务列表(支持 latitude, longitude, radius);POST /api/grab/:taskId 抢单。
GET /api/review/pending 待审核列表;GET /api/review/:submissionId 审核详情;POST /api/review/:submissionId/approve 通过;POST /api/review/:submissionId/reject 驳回;POST /api/review/batch 批量审核。
GET /api/statistics/task 任务统计;GET /api/statistics/researcher 调研员统计;POST /api/export/data 导出数据(xlsx 等)。
GET /api/message/list 消息列表;POST /api/message/:id/read 标记已读;POST /api/message/readAll 全部已读。
// 登录
const { code } = await wx.login();
const res = await wx.request({
url: 'https://api.example.com/v1/api/auth/miniprogram/login',
method: 'POST',
data: { code }
});
// 获取任务列表需在 header 中携带 Authorization: Bearer <token>
import axios from 'axios';
const api = axios.create({
baseURL: 'https://api.example.com/v1',
headers: { 'Content-Type': 'application/json' }
});
api.interceptors.request.use((config) => {
const token = localStorage.getItem('token');
if (token) config.headers.Authorization = `Bearer ${token}`;
return config;
});