plight · 灯光平台 API

纯 plight 平台对外接口文档(不含物理实验室平台 API)

Base URL: https://plightweb.cn/index.php?r=
目录 一、概述与通用约定 二、认证方式 三、账号 四、帖子与内容 五、评论与点赞 六、站内信 七、勋章 / 反馈 / 授权 / 签到 八、身份快捷验证 九、后台管理 十、错误码 十一、curl 示例

一、概述与通用约定

plight 平台提供基于 JSON 的 HTTP API。除特殊说明外,所有接口使用 POST 方法、Content-Type: application/json

说明
Base URLhttps://plightweb.cn/index.php?r=
请求体 / 响应体JSON
统一响应结构{ "status":200, "message":"", "data":... }
成功HTTP 200 且 status == 200
失败status 为 4xx / 403 / 5xx,message 为原因

二、认证方式

类型载体适用
登录态会话 Cookie PLIGHTSESS需登录的接口;未登录返回 401
身份验证 Key请求头 x-API-Keyidentity_verify 专用

三、账号

3.1 登录
POST公开
index.php?r=api/login
{"username":"xxx","password":"***"}

成功:{ "status":200, "data":{ "id":1, "username":"xxx", "nickname":"昵称" } }

3.2 普通注册
POST公开
index.php?r=api/register
{"username":"xxx","password":"***","email":"可选"}

用户名 3–32 位,密码 ≥6 位;注册后自动登录,返回 data:{id},赠 +50 灯泡 +20 经验。

四、帖子与内容

4.1 发布帖子
POST登录
index.php?r=api/posts
{ "board_id":1, "title":"标题", "content":"<HTML>", "tag":"可选标签" }

返回 data:{id, status}status=1 已公开,0 待审核。需资格的板块要授权。

4.2 个人设置
POST登录
index.php?r=api/post
{ "action":"update_info", "nickname":"", "signature":"", "bio":"", "avatar":"https://", "cover":"https://" }
{ "action":"update_pass", "email":"", "password":"***" }
{ "action":"update_medals", "medal_ids":[1,2,3] }

五、评论与点赞

5.1 评论
POST登录
index.php?r=api/comment
{ "action":"create", "post_id":123, "content":"评论内容" }   // 发表
{ "action":"delete", "id":评论ID }                              // 删除(作者/楼主/管理员)
5.2 点赞 / 打赏
POST登录
index.php?r=api/star
{ "post_id":123, "amount":1 }

amount=1 点赞(再点取消);amount>1 为打赏。返回 data:{starred:true|false}

六、站内信

6.1 站内信
POST登录
index.php?r=api/message
{ "action":"list", "category":0 }          // 0全部 1管理 2通知 3用户通知 4关注通知
{ "action":"read", "id":消息ID }
{ "action":"read_all" }
{ "action":"send", "to_id":用户ID, "content":"内容" }

站内信 30 天自动清理。

七、勋章 / 反馈 / 授权 / 签到

7.1 勋章
POSTlist 公开 / 其余管理员
index.php?r=api/medal
{ "action":"list" }                    // 勋章列表
{ "action":"grant", "user_id":1, "medal_id":2 }
{ "action":"auto" }
7.2 反馈
POSTlist 公开 / solve 管理员
index.php?r=api/feedback
{ "action":"list" }
{ "action":"solve", "id":反馈ID }
7.3 用户授权
POST管理员
index.php?r=api/grant
{ "action":"list" }
{ "action":"add", "user_id":1, "perm":"wenxuan" }
{ "action":"remove", "id":授权ID }
7.4 每日签到
POST登录
index.php?r=api/checkin
{}

每日首次 +10 灯泡 +20 经验;当日重复返回 data:{done:true, gold}

八、身份快捷验证

用于「plight身份快捷验证平台」等外部服务核验用户是否为平台已注册用户。需请求头 x-API-Key(在官网后台配置)。
8.1 校验账号密码(换取一次性 token)
POSTx-API-Key
index.php?r=api/identity_verify
{ "mode":"verify", "username":"xxx", "password":"***" }
8.2 用 token 换取身份
POSTx-API-Key
index.php?r=api/identity_verify
{ "mode":"token", "token":"***" }
8.3 公开身份查询
POSTx-API-Key
index.php?r=api/identity_verify
{ "mode":"lookup", "username":"xxx" }   // 也可用 uid / 平台用户ID

以上三种模式返回 data

{ "uid":"", "username":"", "nickname":"", "role":0, "status":1,
  "is_wushi":1, "wushi_name":"", "wushi_id":"", "level":1, "gold":0,
  "verify_token":"仅 verify 模式返回,5 分钟有效" }

九、后台管理

9.1 后台管理
POST管理员
index.php?r=api/admin
// 帖子
{ "action":"post_review_list" }
{ "action":"post_review", "id":帖子ID, "result":1 }     // 1通过 2驳回
{ "action":"post_delete", "id":帖子ID }
{ "action":"post_feature", "id":帖子ID }
{ "action":"post_sticky", "id":帖子ID, "value":1 }
// 成员
{ "action":"users", "q":"搜索词" }
{ "action":"user_update", "id":1, "role":2, "email":"", "nickname":"", "password":"" }
{ "action":"user_ban", "id":1, "mode":3, "days":7 }     // 2临时禁言 3封禁
{ "action":"user_unban", "id":1 }
// 组织 / 勋章 / 公告 / 站内信
{ "action":"org_list" }
{ "action":"org_create", "name":"组织名", "intro":"简介" }
{ "action":"medal_create", "name":"勋章名", "tier":2, "image":"", "desc":"" }
{ "action":"ann_add", "title":"公告", "content":"", "link":"" }
{ "action":"send_message", "to_id":1, "title":"", "content":"" }

十、错误码

status含义
400请求字段缺失或格式错误
401未登录 / API Key 无效 / token 无效
403权限不足 / 板块无资格 / 账号封禁
404内容或用户不存在
409用户名已占用

十一、curl 示例

# 登录
curl -k -X POST "https://plightweb.cn/index.php?r=api/login" \
  -H "Content-Type: application/json" \
  -d '{"username":"admin","password":"***"}'

# 身份快捷验证
curl -k -X POST "https://plightweb.cn/index.php?r=api/identity_verify" \
  -H "Content-Type: application/json" -H "x-API-Key: ***" \
  -d '{"mode":"verify","username":"xxx","password":"***"}'
上线前请在 app/config.php 中把 app.debug 设为 false,并修改 app.url(plightweb.cn)、app.verify_keywushi.secret