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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
| <?php
$jsonString = file_get_contents('config.json');
$config = json_decode($jsonString, true); $username = $config['username']; $password = $config['password']; $loginUrl = $config['loginUrl']; $activeUsersUrl = $config['activeUsersUrl'];
function curlRequest($url, $postFields = null, $headers = []) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); if (!is_null($postFields)) { curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($postFields)); } if (!empty($headers)) { curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); } $response = curl_exec($ch); if (curl_errno($ch)) { curl_close($ch); return null; } curl_close($ch); return json_decode($response, true); }
function generateRandomString($length = 50) { $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; $charactersLength = strlen($characters); $randomString = ''; for ($i = 0; $i < $length; $i++) { $randomString .= $characters[rand(0, $charactersLength - 1)]; } return $randomString; }
$authResponse = curlRequest($loginUrl, ['username' => $username, 'password' => $password], ['Content-Type: application/json']); $token = $authResponse['token'] ?? '';
if ($token) { $activeUsersData = curlRequest($activeUsersUrl, null, ['Authorization: Bearer ' . $token]); $activeUsers = isset($activeUsersData[0]['x']) ? $activeUsersData[0]['x'] : 'Unavailable';
$people=2;
$message = $activeUsers > $people ? "抱歉,当前在线用户数已达到限制。": "在线用户数少于指定人数,欢迎访问。";
echo "<!DOCTYPE html> <html> <head> <title>LZY's GPT 在线用户检查</title> <style> body { font-family: 'Arial', sans-serif; margin: 0; padding: 0; background-color: #f4f4f4; color: #333; } .container { max-width: 600px; margin: 50px auto; padding: 20px; background-color: #fff; box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); } h1 { color: #0066cc; } p { line-height: 1.6; } .alert { padding: 20px; background-color: #f44336; /* Red */ color: white; margin-bottom: 15px; } .info { padding: 20px; background-color: #2196F3; /* Blue */ color: white; margin-bottom: 15px; } a { color: #2196F3; text-decoration: none; font-weight: bold; } </style>"; if ($activeUsers < $people+1) { $randomString = generateRandomString(); setcookie("auth", $randomString, time() + 1800); echo "<meta http-equiv='refresh' content='3; url=http://gpt.lzyyyyyy.fun/guest'>"; } echo "</head> <body> <div class='container'> <h1>欢迎使用LZY's GPT。</h1>"; if ($activeUsers < $people+1) { echo "<div class='info'>{$message}</div> <p>三秒后将自动跳转...</p>"; } else { echo "<div class='alert'>{$message}</div> <p>这会使用人数有点多噢,不如去 <a href='https://lzyyyyyy.fun'>fugu's 博客</a>逛逛叭~</p>"; } echo " </div> </body> </html>"; } else { echo "<div class='container'> <div class='alert'>无法认证,请检查配置。</div> </div>"; }
|