API 文档

智慧校园物联网综合管理系统 · RESTful 接口说明(基于当前线上 `api.php` / `alert_api.php`)

Base URL:
公共接口:/api.php?action=... · 兼容入口:/alert_api.php
说明: 设备上报、看板查询走站点根目录公共 API(无需后台 Cookie)。 /admin/api.php 为管理后台专用,需先登录,本文只作索引。
GET health GET dashboard GET stats GET alerts GET devices GET staff POST ingest POST alert_process POST alerts_clear POST alert_api.php

GET 健康检查 公开

/api.php?action=health
{
  "status": "ok",
  "service": "智慧校园物联网API",
  "version": "2.0",
  "time": "2026-07-28 12:00:00"
}

GET 仪表盘 公开

/api.php?action=dashboard

返回统计、最近告警、用户摘要、系统状态等。

GET 统计 公开

/api.php?action=stats

GET 告警列表 公开

/api.php?action=alerts&level=&processed=&location=

GET 设备列表 公开

/api.php?action=devices

GET 人员 / 用户 公开

/api.php?action=staff

返回 users 表摘要字段(id、username、nickname、联系方式、角色等)。

POST 上报告警 公开

/api.php?action=ingest

JSON Body 示例:

{
  "event_type": "parking_access",
  "location": "地下停车场入口",
  "message": "检测到异常通行",
  "details": "可选详情",
  "alert_level": "high",
  "person_type": "student"
}

成功时返回 success / id / alert_id

JS 客户端也可使用:

smartCampus.sendAlert({
  event_type: "parking_access",
  location: "地下停车场入口",
  person_type: "student"
});

POST 标记已处理 公开

/api.php?action=alert_process (别名 process_alert)
{ "id": 123, "user": "admin" }

批量:action=alert_process_until,同样 POST { id, user }

POST / DELETE 清空已处理历史 公开

/api.php?action=alerts_clear

POST 兼容设备入口 公开

/alert_api.php

旧设备端可用 JSON 或表单字段:

管理后台 API 需登录

/admin/api.php?action=dashboard|alerts|alert|stats|staff|alerts_clear

需先访问 /admin/login.html 登录(Session / Remember Cookie)。