API 文档
使用我们简单的 REST API 将 ly1.ru 网址缩短功能集成到您的应用中。
🔐 需要认证
API 访问需要认证。使用 Google 登录获取您的 API 密钥。 登录
认证
所有 API 请求都需要使用您的 API 密钥进行认证。在请求头中包含:
Authorization: Bearer YOUR_API_KEY
或使用请求头 X-API-Key :
X-API-Key: YOUR_API_KEY
接口
POST
/api/v1/shorten
创建缩短的网址。
请求参数
| 参数 | 类型 | 描述 |
|---|---|---|
| url 必需 | string | 要缩短的网址(必须是有效的 HTTP/HTTPS 网址) |
| custom 可选 | string | 自定义别名(3-32个字母数字字符) |
请求示例
# Using curl
curl -X POST https://ly1.ru/api/v1/shorten \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"url": "https://example.com/very/long/url", "custom": "mylink"}'
# Using PHP
$ch = curl_init('https://ly1.ru/api/v1/shorten');
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer YOUR_API_KEY',
'Content-Type: application/json'
],
CURLOPT_POSTFIELDS => json_encode([
'url' => 'https://example.com/very/long/url',
'custom' => 'mylink'
])
]);
$response = json_decode(curl_exec($ch), true);
成功响应 (200)
{
"success": true,
"data": {
"code": "mylink",
"short_url": "https://ly1.ru/mylink",
"subdomain_url": "https://mylink.ly1.ru",
"original_url": "https://example.com/very/long/url"
}
}
错误响应 (400/401)
{
"success": false,
"error": "Error message here"
}
错误代码
| Code | 描述 |
|---|---|
400 |
错误请求 — 无效的参数或网址 |
401 |
未授权 — API 密钥无效或缺失 |
405 |
方法不允许 — 请使用 POST |
500 |
服务器内部错误 |
速率限制
目前没有严格的限制,但请合理使用。过多的请求可能导致临时封禁。