短链接生成器 | 免费在线生成短链接工具
<!DOCTYPE html>
<html>
<head>
<title>API网站</title>
<!-- 添加字体 -->
<link href='https://fonts.googleapis.com/css?family=Montserrat:400,700&display=swap' rel='stylesheet'>
<style>
body {
font-family: 'Montserrat', sans-serif;
background-color: #f5f5f5;
}
<pre><code> .container {
max-width: 800px;
margin: 0 auto;
padding: 20px;
background-color: #fff;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
border-radius: 5px;
}
h1 {
font-size: 2em;
font-weight: bold;
text-align: center;
margin-bottom: 20px;
}
form {
display: flex;
flex-direction: column;
align-items: center;
}
input[type='text'] {
width: 100%;
max-width: 600px;
padding: 10px;
margin-bottom: 20px;
border-radius: 5px;
border: 1px solid #ccc;
font-size: 1.2em;
}
input[type='submit'] {
padding: 10px 20px;
background-color: #007bff;
color: #fff;
border-radius: 5px;
border: none;
font-size: 1.2em;
cursor: pointer;
transition: background-color 0.3s ease;
}
input[type='submit']:hover {
background-color: #0069d9;
}
p {
font-size: 1.2em;
text-align: center;
margin-bottom: 20px;
}
a {
font-size: 1.5em;
font-weight: bold;
color: #007bff;
text-decoration: none;
}
</style>
</code></pre>
</head>
<body>
<div class='container'>
<h1>短链接生成器</h1>
<form action='' method='post'>
<input type='text' name='long_url' placeholder='请输入原始长链接'>
<input type='submit' value='生成短链接'>
</form>
<!-- 根据生成状态显示信息 -->
<?php
// 获取原始长链接
$longUrl = $_POST['long_url'];
<pre><code> // 发送请求生成短链接
$url = 'https://t.apii.cn/?url=' . urlencode($longUrl);
$result = file_get_contents($url);
// 解析返回的 JSON 数据
$data = json_decode($result, true);
// 判断生成状态
if ($data['code'] == 200) {
// 生成成功,显示短链接
$shortUrl = $data['url'];
echo '<p>您的短链接为:</p>';
echo '<a href=' . $shortUrl . '>' . $shortUrl . '</a>';
} else {
// 生成失败,显示失败信息
$errorMsg = $data['msg'];
echo '<p>短链接生成失败,失败原因:' . $errorMsg . '</p>';
}
?>
</div>
</code></pre>
</body>
</html>
原文地址: http://www.cveoy.top/t/topic/l47n 著作权归作者所有。请勿转载和采集!