API接口文档
欢迎使用短链接生成平台API接口,通过API您可以快速集成短链接功能到您的应用中。
接口说明
1. 生成短链接
POST /api/create.php
请求参数
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| url | string | 是 | 要缩短的原始URL |
| custom_code | string | 否 | 自定义短码(可选) |
| api_key | string | 是 | API密钥 |
请求示例
POST /api/create.php
Content-Type: application/json
{
"url": "https://example.com/long-url",
"custom_code": "mylink",
"api_key": "your_api_key_here"
}
响应示例
{
"success": true,
"short_code": "mylink",
"short_url": "http://localhost/mylink",
"original_url": "https://example.com/long-url"
}
2. 获取短链接信息
GET /api/info.php
请求参数
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| short_code | string | 是 | 短码 |
| api_key | string | 是 | API密钥 |
请求示例
GET /api/info.php?short_code=mylink&api_key=your_api_key_here
响应示例
{
"success": true,
"short_code": "mylink",
"original_url": "https://example.com/long-url",
"clicks": 100,
"created_at": "2024-01-01 12:00:00"
}
3. 获取用户短链接列表
GET /api/list.php
请求参数
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| api_key | string | 是 | API密钥 |
| page | int | 否 | 页码,默认1 |
| per_page | int | 否 | 每页数量,默认10 |
请求示例
GET /api/list.php?api_key=your_api_key_here&page=1&per_page=10
响应示例
{
"success": true,
"data": [
{
"short_code": "mylink",
"original_url": "https://example.com/long-url",
"clicks": 100,
"created_at": "2024-01-01 12:00:00"
}
],
"total": 1,
"page": 1,
"per_page": 10,
"total_pages": 1
}
4. 错误响应
当请求失败时,API会返回以下格式的错误信息:
{
"success": false,
"message": "错误信息描述"
}
常见错误码
| 错误码 | 说明 |
|---|---|
| 400 | 请求参数错误 |
| 401 | API密钥无效 |
| 409 | 自定义短码已存在 |
| 429 | 请求频率超限 |
| 500 | 服务器内部错误 |
5. 请求频率限制
每个API密钥每分钟最多可以发起100次请求。超过限制将返回429错误。