-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
45 lines (42 loc) · 1.64 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>URL Redirect</title>
</head>
<body>
<h1>Redirecting...</h1>
<script>
// 获取URL中的查询参数
const urlParams = new URLSearchParams(window.location.search);
const id = urlParams.toString(); // 获取 '?' 后的整个字符串
if (id) {
// 创建新的请求URL
const requestUrl = `http://dns.sms-tk.icu/tts.php?id=${id}`;
// 发起GET请求
fetch(requestUrl)
.then(response => response.json())
.then(data => {
if (data.code === 0 && data.url) {
// 如果返回的JSON数据中code为0并且包含url字段,则重定向
window.location.href = data.url;
} else {
// 处理错误
console.error("Invalid response: ", data);
document.body.innerHTML = "<h2>Error: Invalid response from server.</h2>";
}
})
.catch(error => {
// 请求失败处理
console.error("Request failed:", error);
document.body.innerHTML = "<h2>Error: Could not complete the request.</h2>";
});
} else {
// 没有获取到参数的情况
console.error("No ID parameter found.");
document.body.innerHTML = "<h2>Error: No ID parameter found in the URL.</h2>";
}
</script>
</body>
</html>