2026年3月

AiPublish

提供一个 token 鉴权的发布接口:POST /api/publish(兼容 POST /action/ai-publish)。

安装

  1. 将插件目录放到:usr/plugins/AiPublish
  2. 在 Typecho 后台启用 AiPublish
  3. 在插件设置中配置:

    • API Token:接口鉴权密钥
    • 默认作者 ID:草稿作者(通常为管理员 ID)

接口

  • 方法:POST
  • 路径:/api/publish
  • 兼容路径:/action/ai-publish
  • Header(二选一):

    • Authorization: Bearer <token>
    • X-API-Token: <token>

可用 GET 做健康检查(不需要 token):

curl 'https://your-site.com/index.php/action/ai-publish'

正常会返回:

{"ok":true,"plugin":"AiPublish","route":"alive"}

请求体(JSON)

{
  "title": "文章标题",
  "content": "正文内容(支持 Markdown)"
}

也支持在请求体里额外传 token 字段。

成功响应

{
  "ok": true,
  "cid": 123,
  "status": "draft",
  "title": "文章标题"
}

调用示例

curl -X POST 'http://115.190.110.58/api/publish' \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer ' \
  -d '{
    "title": "AI 自动写作草稿",
    "content": "这是一篇由 AI 通过 API 创建的草稿。"
  }'

未开启伪静态时请使用:

curl -X POST 'http://115.190.110.58/index.php/action/ai-publish' \
  -H 'Content-Type: application/json' \
  -d '{
    "token": "",
    "title": "AI 自动写作草稿",
    "content": "这是一篇由 AI 通过 API 创建的草稿。"
  }'

或继续使用 Header 传 token:

curl -X POST 'http://115.190.110.58/index.php/action/ai-publish' \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer ' \
  -d '{
    "title": "AI 自动写作草稿",
    "content": "这是一篇由 AI 通过 API 创建的草稿。"
  }'

常见问题

  1. 返回 Sorry but the page you are trying to view does not exist.
    停用并重新启用插件后再测试 https://your-site.com/index.php/action/ai-publish
  2. 返回 Unauthorized
    通常是 token 不一致,或请求头缺少 Bearer 前缀。