马春杰短网址生成 书签帮助您快速生成短网址而不离开您的网站。
请登录管理后台,在「设置」页面中生成你的 API Key。每个用户的 API Key 都是唯一的,请妥善保管,不要泄露给他人。
cURL(Linux/Mac/Windows):
curl -X POST "https://short.machunjie.com/api.php" \ -d "url=https://example.com&key=YOUR_API_KEY"
PHP:
<?php
$api_url = 'https://short.machunjie.com/api.php';
$params = [
'url' => 'https://example.com',
'key' => 'YOUR_API_KEY'
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $api_url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
echo $result;
?>
JavaScript(Fetch API):
fetch('https://short.machunjie.com/api.php', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: 'url=https://example.com&key=YOUR_API_KEY'
})
.then(response => response.text())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));
成功响应:
https://short.machunjie.com/your-alias
错误响应:
Error: 无效的 API Key Error: URL 参数不能为空 Error: 无效的 URL 格式 Error: 自定义链接已被使用
