API 文档
接口返回 JSON,支持跨域调用。
1. 创建短链接 POST /api/shorten
- Content-Type
application/json或application/x-www-form-urlencoded- url
- 必填,需要缩短的原始链接(http / https)
- code
- 可选,自定义短码,字母数字下划线短横线,最长 32 位
- expires_at
- 可选,过期时间,任意可被
strtotime解析的字符串,如2030-01-01 12:00:00 - title
- 可选,备注名称
- note
- 可选,备注说明
请求示例
curl -X POST https://link.wanghui.work/api/shorten \ -H "Content-Type: application/json" \ -d '{"url":"https://example.com/a/b/c","code":"abc123","expires_at":"2030-01-01 00:00:00"}'
成功响应
{
"ok": true,
"code": "abc123",
"target": "https://example.com/a/b/c",
"short_url": "https://link.wanghui.work/abc123",
"expires_at": "2030-01-01 00:00:00"
}
| 状态码 | 含义 |
|---|---|
200 | 创建成功 |
400 | 参数不合法(链接格式错误、短码不符合规则等) |
409 | 短码已被占用 |
429 | 触发限流,每 IP 每 600 秒最多 30 次 |
2. 查询统计 GET /api/stats
- code
- 必填,要查询的短码
curl "https://link.wanghui.work/api/stats?code=abc123" { "ok": true, "total": 128, "link": { "code": "abc123", "clicks": 128, ... }, "series": [{ "day": "2026-10-01", "count": 12 }] }
3. 短码跳转
直接访问 https://link.wanghui.work/{code} 即可 302 跳转到目标地址;访问 https://link.wanghui.work/{code}+ 可查看公开统计卡片。
停用或已过期的短链将返回 404 页面,且不会计入统计。