支持 GET 或 POST(表单 / JSON)。调用后返回 JSON,包含短码与完整短链 域名/r/XXXX。后端基于 PHP + JSON 文件存储,自动生成 4 位短码并记录。
| 参数 | 必填 | 说明 |
|---|---|---|
| url | 是 | 目标网址,需以 http:// 或 https:// 开头 |
| expire | 否 | 有效期(小时),0 或不传 = 永久 |
{
"success": true,
"code": "5Ic",
"short_url": "https://你的域名/r/5Ic",
"original_url": "https://example.com",
"expire_at": 0,
"expire_at_str": "永久"
}
访问短链 域名/r/5Ic 将通过 iframe 防红方式加载目标网址;过期或不存在时显示提示页。所有记录可在 生成记录 查看(需密码)。
# GET 方式(浏览器可直接打开)
curl "api.php?url=https://example.com&expire=24"
# POST 方式(表单)
curl -X POST "api.php" \
-d "url=https://example.com" \
-d "expire=24"
const params = new URLSearchParams();
params.append('url', 'https://example.com');
params.append('expire', '24'); // 0 = 永久
const res = await fetch('api.php', {
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body: params.toString()
});
const data = await res.json();
console.log(data.short_url); // https://你的域名/r/XXXX
import requests
resp = requests.post('api.php', data={
'url': 'https://example.com',
'expire': 24, # 0 = 永久
})
data = resp.json()
print(data['short_url']) # https://你的域名/r/XXXX
<?php
$qs = http_build_query([
'url' => 'https://example.com',
'expire' => 24, // 0 = 永久
]);
$ctx = stream_context_create(['http' => [
'method' => 'POST',
'header' => 'Content-Type: application/x-www-form-urlencoded',
'content' => $qs,
]]);
$json = file_get_contents('api.php', false, $ctx);
$data = json_decode($json, true);
echo $data['short_url']; // https://你的域名/r/XXXX
密钥在 config.php 的 secret 中设置。也可直接访问 records.php 网页管理。