识别豆瓣观影的链接并解析
This commit is contained in:
浪子
2024-07-27 09:13:57 +08:00
parent 52f8e45de0
commit 1c18ec0593
3 changed files with 112 additions and 39 deletions
+26
View File
@@ -0,0 +1,26 @@
<?php
$movie_id = $_GET['id'];
$api_url = "https://api.loliko.cn/movies/{$movie_id}";
$context = stream_context_create([
'http' => [
'ignore_errors' => true,
'timeout' => 10 // 设置10秒超时
]
]);
$response = file_get_contents($api_url, false, $context);
if ($response === FALSE) {
header("HTTP/1.1 500 Internal Server Error");
echo json_encode(['error' => 'Failed to fetch data from API']);
} else {
$responseData = json_decode($response, true);
if (json_last_error() === JSON_ERROR_NONE) {
header('Content-Type: application/json');
echo $response;
} else {
header("HTTP/1.1 500 Internal Server Error");
echo json_encode(['error' => 'Invalid JSON response from API']);
}
}