Created
April 3, 2025 07:17
-
-
Save dvygolov/5f16c7e021a211367fa8efede30ab8c5 to your computer and use it in GitHub Desktop.
Binom + Telegram postback script that notifies buyers about new deposits
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Binom Postback Filter Middleware v0.2 | |
* by Yellow Web (https://yellowweb.top) | |
* This script receives postback data from Binom tracker | |
* about registrations and deposits, | |
* filters out registrations (cnv_status = 'reg'), | |
* and only forwards deposits (cnv_status = 'dep') to the Telegram bot. | |
*/ | |
$telegramBotToken = ''; | |
$telegramChatId = ''; | |
$messageTemplate = <<<EOF | |
🎰{campaign_group_name}, new deposit! | |
Status: *{cnv_status}* | |
GEO: *{t2}* | |
Creo: *{t6}* | |
Adset: *{t4}* | |
Camp: *{t3}* | |
Offer: *{offer_name}* | |
ClickID: *{clickid}* | |
Time: *{date}* | |
EOF; | |
$logFile = 'cpadeppush.log'; | |
// Receive the postback data | |
$postData = $_REQUEST; | |
// If no POST data, check if data was sent as JSON | |
if (empty($postData)) { | |
$inputJSON = file_get_contents('php://input'); | |
$postData = json_decode($inputJSON, true); | |
} | |
// Log all postbacks for debugging | |
logToFile($postData, $logFile); | |
// Check if the postback data contains status | |
if (!isset($postData['cnv_status'])) { | |
$msg = 'Error: No cnv_status field in postback data'; | |
logToFile($msg, $logFile); | |
die($msg); | |
} | |
// Only forward postbacks with status = 'dep' to Telegram | |
if ($postData['cnv_status'] === 'dep') { | |
// Replace placeholders with actual values from the postback | |
$message = $messageTemplate; | |
foreach ($postData as $key => $value) { | |
$message = str_replace('{'.$key.'}', $value, $message); | |
} | |
// Send message to Telegram | |
sendToTelegram($message, $telegramBotToken, $telegramChatId); | |
$msg = "Success: Deposit postback forwarded to Telegram"; | |
logToFile($msg, $logFile); | |
echo $msg; | |
} else { | |
// For other statuses (like 'reg'), just acknowledge receipt | |
$msg = "Success: Postback received, but not forwarded (status: {$postData['cnv_status']})"; | |
logToFile($msg, $logFile); | |
echo $msg; | |
} | |
/** | |
* Log data to a file with timestamp | |
* | |
* @param mixed $data Data to log (array or string) | |
* @param string $logFile Path to the log file | |
* @return bool Success status | |
*/ | |
function logToFile($data, $logFile) { | |
$timestamp = date('[Y-m-d H:i:s] '); | |
// Handle different data types | |
if (is_array($data) || is_object($data)) { | |
$logData = $timestamp . json_encode($data) . PHP_EOL; | |
} else { | |
$logData = $timestamp . $data . PHP_EOL; | |
} | |
// Append to the log file | |
return file_put_contents($logFile, $logData, FILE_APPEND); | |
} | |
/** | |
* Send message to Telegram | |
* | |
* @param string $message Message to send | |
* @param string $botToken Telegram bot token | |
* @param string $chatId Telegram chat ID | |
* @return bool Success status | |
*/ | |
function sendToTelegram($message, $botToken, $chatId) { | |
$url = "https://api.telegram.org/bot{$botToken}/sendMessage"; | |
$postFields = [ | |
'chat_id' => $chatId, | |
'text' => $message, | |
'parse_mode' => 'Markdown' | |
]; | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, $url); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($ch, CURLOPT_POST, true); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields); | |
$response = curl_exec($ch); | |
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); | |
curl_close($ch); | |
return ($httpCode >= 200 && $httpCode < 300); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Binom S2S postback example to use the script:
https://cpagency.top/cpadeppush.php?campaign_group_name={campaign_group_name}&cnv_status={cnv_status}&t2={t2}&t3={t3}&t4={t4}&t6={t6}&offer_name={offer_name}&clickid={clickid}&date={date}