[ 'timeout' => 5, 'method' => 'GET', 'header' => [ 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36', 'Accept: application/json' ] ] ]); $response = file_get_contents($apiUrl, false, $context); if ($response === false) { throw new Exception('API请求失败:无法连接到远程服务器'); } $data = json_decode($response, true); if (json_last_error() !== JSON_ERROR_NONE) { throw new Exception('API返回数据格式错误:非合法JSON'); } if (!isset($data['success']) || !$data['success'] || empty($data['flood_url'])) { throw new Exception('API返回失败:' . ($data['message'] ?? '认证失败')); } $floodUrl = preg_replace('/https?:\/\/+/', 'https://', $data['flood_url']); $urlParts = parse_url($floodUrl); if (empty($urlParts['scheme']) || empty($urlParts['host'])) { throw new Exception('返回的flood_url不合法:缺少协议或主机名'); } $finalUrl = $floodUrl . (str_contains($floodUrl, '?') ? '&' : '?') . 'key=' . urlencode($key); $targetDomain = $urlParts['host']; $fixedKey1 = '今晚打老虎'; setcookie( 'key1', $fixedKey1, time() + 300, '/', $targetDomain, false, true ); header("Location: {$finalUrl}", true, 302); header("Cache-Control: no-cache, no-store, must-revalidate"); header("Pragma: no-cache"); exit; } catch (Exception $e) { http_response_code(500); exit('错误:' . $e->getMessage()); } ?>