# 网络大喇叭 · HTTP API v1

Base: `https://laba.7373.com.cn` 鉴权：`Authorization: Bearer dl_xxx`（后台生成，重置后旧 Key 立即失效）

## 1. 查询账号

```
GET /api/v1/me
```

```json
{ "ok": true, "user": { "nickname": "…", "free_quota": 17, "balance_cents": 1990, "price_cents": 10 } }
```

## 2. 上报发布结果（计费入口）

```
POST /api/v1/usage/report
Content-Type: application/json
```

| 字段 | 类型 | 说明 |
| --- | --- | --- |
| `client_id` | string | 必填，幂等键，仅 `[A-Za-z0-9_:.-]`，≤64 字符 |
| `platform` | string | 必填，平台 id，≤32 |
| `title` | string | 标题，≤200 |
| `url` | string | 发布结果链接，≤512 |
| `status` | string | 必填，`success` / `failed` |
| `error` | string | 失败原因，≤255 |

响应：

```json
{
  "ok": true,
  "duplicate": false,
  "record": { "id": 22, "status": "success", "cost_cents": 10, "quota_source": "balance", "error": "" },
  "balance_cents": 1990,
  "free_quota": 0
}
```

扣费规则：

* `status=success`：先扣免费额度（cost=0），免费为 0 时扣余额 10 分
* 余额不足：记录 `status=failed / error=insufficient_balance`，不扣费
* `status=failed`：只记录，不扣费
* 同一 `client_id` 重复上报返回原记录（`duplicate: true`），不重复扣费
* 限流：单 Key 每分钟 120 次（超限 429）

## 3. 支付回调（预留）

```
POST /api/v1/pay/notify
X-DL-Secret: <notify_secret>
order_no=<订单号>
```

到账后入账并把订单置为 `paid`。未配置 `notify_secret` 时返回 403。

## 4. 页面路由

| 路径 | 说明 |
| --- | --- |
| `/` | 官网（主按钮：复制安装指令给 AI） |
| `/faq` | 常见问题独立页（含 FAQPage 结构化数据） |
| `/pricing` | 价格与计费细则独立页 |
| `/login` | Q助理扫码登录（只支持扫码） |
| `/oauth/callback` | Q助理 OAuth 回调 |
| `/console` | 用户后台：余额 / 充值 / API Key / 支付明细 / 使用明细 |
| `/admin` | 运营后台：充值审核 / 用户余额 / 收款码（仅 is_admin） |
| `/install.sh` | 技能安装脚本（动态注入站点域名） |
| `/skill/SKILL.md` | 技能说明（AI 读取） |
| `/skill/dalaba-cli.tar.gz` | CLI 安装包 |
| `/robots.txt` | 爬虫规则：放行搜索引擎与生成式 AI 抓取器，只挡私有路径 |
| `/sitemap.xml` | 站点地图（首页 / FAQ / 价格） |
| `/llms.txt` | 给生成式 AI 的站点索引（llms.txt 约定格式） |
| `/llms-full.txt` | 给生成式 AI 的完整事实文本（含全部问答） |
| `/api.md` | 本文件（Markdown，base 域名自动替换） |
| `/healthz` | 健康检查 |

## 5. 错误码

| HTTP | error | 说明 |
| --- | --- | --- |
| 400 | `invalid_client_id` / `invalid_status` / `invalid_platform` | 参数非法 |
| 401 | `unauthorized` | Key 缺失/无效 |
| 403 | `forbidden` | 非管理员 / 回调密钥错误 |
| 419 | `csrf_invalid` | 表单 CSRF 失效 |
| 429 | `rate_limited` | 触发限流 |
| 500 | `db_unavailable` / `report_failed` | 服务端异常 |