智慧校园管理系统 - API对接文档

完整API接口文档,支持多种编程语言,轻松集成物联网设备

测试API接口 返回主页
API概述

智慧校园管理系统提供了一套完整的RESTful API,允许您轻松集成各种物联网设备和第三方系统。所有API都返回JSON格式的数据,支持跨域访问,并提供了多种语言的示例代码。

基本信息
项目
基础URL http://43.142.37.44/api.php
数据格式 JSON
字符编码 UTF-8
认证方式 无需认证(测试环境)
通用响应格式
{ "status": "success", "message": "操作成功", "data": { /* 具体数据内容 */ } }
{ "status": "error", "message": "错误描述", "data": [] }
API接口详情
GET
/api.php?action=dashboard
功能:获取仪表盘数据,包括统计信息、最近告警、安全人员和趋势数据
请求参数

响应示例
{ "status": "success", "message": "仪表板数据获取成功", "data": { "stats": { "total_alerts": 4, "unprocessed_alerts": 3, "high_risk_alerts": 4, "today_alerts": 4, "pending_alerts": 3, "high_risk": 3 }, "recent_alerts": [ { "id": 5129, "event_type": "学生非法闯入", "location": "停车场", "details": "默认上报", "alert_level": "high", "processed": 0, "created_at": "2025-11-18 08:40:41" } ], "staff": [ { "id": 1, "name": "张三", "phone": "13800138001", "email": "zhangsan@example.com" } ], "system_status": { "database": "online", "storage": "normal", "memory": "normal", "uptime": "unknown" }, "trigger_alert": true, "alert_data": { "id": 5129, "event_type": "学生非法闯入", "location": "停车场", "alert_level": "high", "processed": 0, "created_at": "2025-11-18 08:40:41" } } }
代码示例
cURL
JavaScript
Python
MicroPython
curl "http://43.142.37.44/api.php?action=dashboard"
fetch('http://43.142.37.44/api.php?action=dashboard') .then(response => response.json()) .then(data => console.log(data));
import requests response = requests.get('http://43.142.37.44/api.php?action=dashboard') data = response.json() print(data)
import urequests response = urequests.get('http://43.142.37.44/api.php?action=dashboard') print(response.text)
GET
/api.php?action=alerts
功能:获取告警列表,支持多种过滤条件
请求参数
参数名 类型 必需 描述
level string 告警级别过滤 (low, medium, high, critical)
location string 位置过滤 (支持模糊匹配)
processed int 处理状态过滤 (0: 未处理, 1: 已处理)
date_from string 开始日期 (YYYY-MM-DD)
date_to string 结束日期 (YYYY-MM-DD)
limit int 返回数量限制 (默认20,最大100)
offset int 偏移量 (用于分页)
响应示例
{ "status": "success", "data": { "alerts": [ { "id": 5129, "event_type": "学生非法闯入", "location": "停车场", "details": "默认上报", "alert_level": "high", "processed": 0, "created_at": "2025-11-18 08:40:41" } ], "total": 1, "limit": 20, "offset": 0 } }
代码示例
cURL
JavaScript
Python
MicroPython
# 获取所有告警 curl "http://43.142.37.44/api.php?action=alerts" # 获取未处理的警告级别告警 curl "http://43.142.37.44/api.php?action=alerts&level=warning&processed=0"
// 获取所有告警 fetch('http://43.142.37.44/api.php?action=alerts') .then(response => response.json()) .then(data => console.log(data)); // 获取未处理的警告级别告警 fetch('http://43.142.37.44/api.php?action=alerts&level=warning&processed=0') .then(response => response.json()) .then(data => console.log(data));
import requests # 获取所有告警 response = requests.get('http://43.142.37.44/api.php?action=alerts') data = response.json() print(data) # 获取未处理的高风险告警 params = {'level': 'high', 'processed': 0} response = requests.get('http://43.142.37.44/api.php?action=alerts', params=params) data = response.json() print(data)
import urequests # 获取所有告警 response = urequests.get('http://43.142.37.44/api.php?action=alerts') print(response.text) # 获取未处理的高风险告警 response = urequests.get('http://43.142.37.44/api.php?action=alerts&level=high&processed=0') print(response.text)
GET
PUT
DELETE
/api.php?action=alert&id={id}
功能:获取、更新或删除单个告警
GET - 获取单个告警
参数名 类型 必需 描述
id int 告警ID
{ "status": "success", "message": "操作成功", "data": { "id": 5129, "event_type": "学生非法闯入", "location": "停车场", "details": "默认上报", "alert_level": "high", "processed": 0, "created_at": "2025-11-18 08:40:41" } }
PUT - 更新告警状态
参数名 类型 必需 描述
id int 告警ID
processed boolean 处理状态 (true: 已处理, false: 未处理)
processed_by string 处理人姓名
{ "success": true, "message": "Alert updated successfully" }
DELETE - 删除告警
参数名 类型 必需 描述
id int 告警ID
{ "success": true, "message": "Alert deleted successfully" }
代码示例
cURL
JavaScript
Python
MicroPython
# 获取告警详情 curl "http://43.142.37.44/api.php?action=alert&id=1" # 更新告警状态 curl -X PUT "http://43.142.37.44/api.php?action=alert&id=1" \ -H "Content-Type: application/json" \ -d '{"processed":true,"processed_by":"管理员"}' # 删除告警 curl -X DELETE "http://43.142.37.44/api.php?action=alert&id=1"
// 获取告警详情 fetch('http://43.142.37.44/api.php?action=alert&id=1') .then(response => response.json()) .then(data => console.log(data)); // 更新告警状态 fetch('http://43.142.37.44/api.php?action=alert&id=1', { method: 'PUT', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ processed: true, processed_by: '管理员' }) }) .then(response => response.json()) .then(data => console.log(data)); // 删除告警 fetch('http://43.142.37.44/api.php?action=alert&id=1', { method: 'DELETE' }) .then(response => response.json()) .then(data => console.log(data));
import requests import json # 获取告警详情 response = requests.get('http://43.142.37.44/api.php?action=alert&id=1') data = response.json() print(data) # 更新告警状态 update_data = { 'processed': True, 'processed_by': '管理员' } response = requests.put( 'http://43.142.37.44/api.php?action=alert&id=1', headers={'Content-Type': 'application/json'}, data=json.dumps(update_data) ) data = response.json() print(data) # 删除告警 response = requests.delete('http://43.142.37.44/api.php?action=alert&id=1') data = response.json() print(data)
import urequests import ujson # 获取告警详情 response = urequests.get('http://43.142.37.44/api.php?action=alert&id=1') print(response.text) # 更新告警状态 update_data = ujson.dumps({ 'processed': True, 'processed_by': '管理员' }) response = urequests.put( 'http://43.142.37.44/api.php?action=alert&id=1', headers={'Content-Type': 'application/json'}, data=update_data ) print(response.text) # 删除告警 response = urequests.delete('http://43.142.37.44/api.php?action=alert&id=1') print(response.text)
POST
/api.php?action=process_alert
功能:标记指定告警为已处理
请求参数
参数名类型必需描述
idint告警ID
userstring处理人(如 admin/system)
响应示例
{ "status": "success", "message": "告警已标记为已处理", "data": [] }
代码示例
cURL
JavaScript
Python
curl -s -X POST \ -H "Content-Type: application/x-www-form-urlencoded" \ -d "id=5129&user=admin" \ "http://43.142.37.44/api.php?action=process_alert"
const params = new URLSearchParams(); params.append('id', '5129'); params.append('user', 'admin'); fetch('http://43.142.37.44/api.php?action=process_alert', { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, body: params.toString() }) .then(r => r.json()) .then(console.log);
import requests response = requests.post( 'http://43.142.37.44/api.php?action=process_alert', headers={ 'Content-Type': 'application/x-www-form-urlencoded' }, data={ 'id': 5129, 'user': 'admin' } ) print(response.json())
GET
POST
PUT
DELETE
/api.php?action=staff
功能:获取、创建、更新或删除安全人员信息
GET - 获取安全人员列表
{ "success": true, "data": [ { "id": 1, "name": "张三", "phone": "13800138001", "email": "zhangsan@example.com", "status": "active", "created_at": "2023-06-15 10:00:00" } ] }
POST - 创建安全人员
参数名 类型 必需 描述
name string 姓名
phone string 电话号码
email string 电子邮箱
{ "success": true, "message": "Staff created successfully", "data": { "id": 2 } }
PUT - 更新安全人员
参数名 类型 必需 描述
id int 人员ID
name string 姓名
phone string 电话号码
email string 电子邮箱
is_active int 状态 (1: 激活, 0: 停用)
{ "success": true, "message": "Staff updated successfully" }
DELETE - 删除安全人员
参数名 类型 必需 描述
id int 人员ID
{ "success": true, "message": "Staff deleted successfully" }
代码示例
cURL
JavaScript
Python
MicroPython
# 获取安全人员列表 curl "http://43.142.37.44/api.php?action=staff" # 创建安全人员 curl -X POST "http://43.142.37.44/api.php?action=staff" \ -H "Content-Type: application/json" \ -d '{"name":"张三","phone":"13800138001","email":"zhangsan@example.com"}' # 更新安全人员 curl -X PUT "http://43.142.37.44/api.php?action=staff" \ -H "Content-Type: application/json" \ -d '{"id":1,"name":"李四","phone":"13900139001"}' # 删除安全人员 curl -X DELETE "http://43.142.37.44/api.php?action=staff&id=1"
// 获取安全人员列表 fetch('http://43.142.37.44/api.php?action=staff') .then(response => response.json()) .then(data => console.log(data)); // 创建安全人员 fetch('http://43.142.37.44/api.php?action=staff', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ name: '张三', phone: '13800138001', email: 'zhangsan@example.com' }) }) .then(response => response.json()) .then(data => console.log(data)); // 更新安全人员 fetch('http://43.142.37.44/api.php?action=staff', { method: 'PUT', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ id: 1, name: '李四', phone: '13900139001' }) }) .then(response => response.json()) .then(data => console.log(data)); // 删除安全人员 fetch('http://43.142.37.44/api.php?action=staff&id=1', { method: 'DELETE' }) .then(response => response.json()) .then(data => console.log(data));
import requests import json # 获取安全人员列表 response = requests.get('http://43.142.37.44/api.php?action=staff') data = response.json() print(data) # 创建安全人员 new_staff = { 'name': '张三', 'phone': '13800138001', 'email': 'zhangsan@example.com' } response = requests.post( 'http://43.142.37.44/api.php?action=staff', headers={'Content-Type': 'application/json'}, data=json.dumps(new_staff) ) data = response.json() print(data) # 更新安全人员 update_staff = { 'id': 1, 'name': '李四', 'phone': '13900139001' } response = requests.put( 'http://43.142.37.44/api.php?action=staff', headers={'Content-Type': 'application/json'}, data=json.dumps(update_staff) ) data = response.json() print(data) # 删除安全人员 response = requests.delete('http://43.142.37.44/api.php?action=staff&id=1') data = response.json() print(data)
import urequests import ujson # 获取安全人员列表 response = urequests.get('http://43.142.37.44/api.php?action=staff') print(response.text) # 创建安全人员 new_staff = ujson.dumps({ 'name': '张三', 'phone': '13800138001', 'email': 'zhangsan@example.com' }) response = urequests.post( 'http://43.142.37.44/api.php?action=staff', headers={'Content-Type': 'application/json'}, data=new_staff ) print(response.text) # 更新安全人员 update_staff = ujson.dumps({ 'id': 1, 'name': '李四', 'phone': '13900139001' }) response = urequests.put( 'http://43.142.37.44/api.php?action=staff', headers={'Content-Type': 'application/json'}, data=update_staff ) print(response.text) # 删除安全人员 response = urequests.delete('http://43.142.37.44/api.php?action=staff&id=1') print(response.text)
POST
/api.php?action=ingest
功能:设备数据上报接口,用于物联网设备向系统上报事件和数据
请求参数
参数名 类型 必需 描述
event_type string 事件类型 (如: parking_access, perimeter_breach 等)
location string 事件发生位置
person_type string 人员类型 (student, staff, visitor, unknown)
details string 事件详细描述
image_url string 相关图片URL
响应示例
{ "status": "success", "message": "数据接收成功", "data": { "id": "5129", "alert_level": "high" } }
代码示例
cURL
JavaScript
Python
MicroPython
# JSON curl -X POST "http://43.142.37.44/api.php?action=ingest" \ -H "Content-Type: application/json" \ -d '{"event_type":"学生非法闯入","location":"停车场","details":"默认上报","alert_level":"high"}' # 表单 curl -X POST "http://43.142.37.44/api.php?action=ingest" \ -H "Content-Type: application/x-www-form-urlencoded" \ -d "event_type=学生非法闯入&location=停车场&details=默认上报&alert_level=high"
// JSON fetch('http://43.142.37.44/api.php?action=ingest', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ event_type: '学生非法闯入', location: '停车场', details: '默认上报', alert_level: 'high' }) }).then(r => r.json()).then(console.log); // 表单 const p = new URLSearchParams(); p.append('event_type','学生非法闯入'); p.append('location','停车场'); p.append('details','默认上报'); p.append('alert_level','high'); fetch('http://43.142.37.44/api.php?action=ingest', { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, body: p.toString() }).then(r => r.json()).then(console.log);
import requests import json data = { 'event_type': 'parking_access', 'location': '地下停车场入口', 'person_type': 'student', 'details': '学生进入危险区域:停车场' } response = requests.post( 'http://43.142.37.44/api.php?action=ingest', headers={'Content-Type': 'application/json'}, data=json.dumps(data) ) result = response.json() print(result)
import urequests import ujson data = ujson.dumps({ 'event_type': 'parking_access', 'location': '地下停车场入口', 'person_type': 'student', 'details': '学生进入危险区域:停车场' }) response = urequests.post( 'http://43.142.37.44/api.php?action=ingest', headers={'Content-Type': 'application/json'}, data=data ) print(response.text)
DELETE
/api.php?action=alerts_clear
功能:清空所有告警记录
请求参数

响应示例
{ "status": "success", "message": "已清空所有告警记录", "data": [] }
代码示例
cURL
JavaScript
Python
MicroPython
curl -X DELETE "http://43.142.37.44/api.php?action=alerts_clear"
fetch('http://43.142.37.44/api.php?action=alerts_clear', { method: 'DELETE' }) .then(response => response.json()) .then(data => console.log(data));
import requests response = requests.delete('http://43.142.37.44/api.php?action=alerts_clear') print(response.json())
import urequests response = urequests.delete('http://43.142.37.44/api.php?action=alerts_clear') print(response.text)
GET
/api.php?action=stats
功能:获取系统统计数据,包括告警级别分布、位置分布和周趋势
请求参数

响应示例
{ "status": "success", "data": { "level_distribution": [ {"alert_level": "high", "count": 10}, {"alert_level": "critical", "count": 2} ], "location_distribution": [ {"location": "停车场", "count": 5}, {"location": "教学楼", "count": 3} ], "weekly_trend": [ {"date": "2025-11-12", "count": 2}, {"date": "2025-11-13", "count": 1} ], "event_type_distribution": [ {"alert_type": "学生非法闯入", "count": 4 } ] } }
代码示例
cURL
JavaScript
Python
MicroPython
curl "http://43.142.37.44/api.php?action=stats"
fetch('http://43.142.37.44/api.php?action=stats') .then(response => response.json()) .then(data => console.log(data));
import requests response = requests.get('http://43.142.37.44/api.php?action=stats') data = response.json() print(data)
import urequests response = urequests.get('http://43.142.37.44/api.php?action=stats') print(response.text)
常见问题
1. 如何处理跨域问题?

API已配置CORS支持,允许来自特定域名的跨域请求。如果您遇到跨域问题,请确保您的请求来源在允许的域名列表中,或者联系管理员添加您的域名。

2. 如何处理API限流?

API实施了基本的限流措施,每个IP地址在60秒内最多可以发起30次请求。如果超过限制,您将收到429状态码和"请求过于频繁,请稍后再试"的错误消息。请合理控制请求频率。

3. 如何处理错误响应?

所有API错误都遵循统一的响应格式,包含success字段(false)、message字段(错误描述)和可选的error字段(详细错误信息)。请根据这些信息进行相应的错误处理。

4. 如何处理认证?

当前测试环境不需要认证。在生产环境中,可能需要添加API密钥或其他认证方式。请参考最新的API文档或联系管理员获取认证信息。

5. 如何处理大数据量?

对于可能返回大量数据的接口(如告警列表),API支持分页参数(limit和offset)。建议合理设置limit参数,避免一次性获取过多数据。同时,系统也实现了缓存机制,可以提高频繁请求的响应速度。

更新日志
版本 1.0.0 (2023-06-15)
  • 初始版本发布
  • 支持仪表盘数据获取
  • 支持告警管理(获取、更新、删除)
  • 支持安全人员管理(获取、创建、更新、删除)
  • 支持设备数据上报
  • 支持统计数据获取
  • 实现CORS支持和基本限流