// When you need a short link, send the user a solve URL with an ID $chat_id = $incomingChatId; $target = urlencode("https://mega.nz/file/7k5CEDab#LClTOMB..."); $session = uniqid(); // map this to the Telegram user in DB/cache $solveUrl = "https://proxtgbot.xtglinks.com/xtgbotnew/xtg-solve.php?target={$target}&session={$session}"; sendMessage($chat_id, "Please open this link in your browser to finish verification and get the short link:\n\n{$solveUrl}"); // ========================================= // XTG Links API Handler - Cloudflare Safe // ========================================= function shortenWithXtg($apiKey, $longUrl) { $endpoint = "https://xtglinks.com/api"; $postData = http_build_query([ 'api' => $apiKey, 'url' => $longUrl ], '', '&', PHP_QUERY_RFC3986); $ch = curl_init($endpoint); curl_setopt_array($ch, [ CURLOPT_POST => true, CURLOPT_POSTFIELDS => $postData, CURLOPT_RETURNTRANSFER => true, CURLOPT_HEADER => false, CURLOPT_FOLLOWLOCATION => true, CURLOPT_MAXREDIRS => 5, CURLOPT_CONNECTTIMEOUT => 15, CURLOPT_TIMEOUT => 25, CURLOPT_SSL_VERIFYPEER => true, CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36', CURLOPT_REFERER => 'https://xtglinks.com/', CURLOPT_HTTPHEADER => [ 'Accept: application/json, text/html;q=0.9,*/*;q=0.8', 'Content-Type: application/x-www-form-urlencoded' ], ]); $response = curl_exec($ch); $error = curl_error($ch); $status = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); if ($response === false) { error_log("❌ cURL error: $error"); return ['error' => true, 'message' => $error]; } if (stripos($response, ' true, 'message' => 'Cloudflare CAPTCHA encountered. Try client-side redirect or change IP.' ]; } $json = json_decode($response, true); if (json_last_error() === JSON_ERROR_NONE && !empty($json['shortened'] ?? $json['short'])) { return ['success' => true, 'data' => $json]; } return [ 'error' => true, 'message' => "Unexpected response (HTTP $status): " . substr($response, 0, 200) ]; }