<?php
const API_URL = "https://req.adcombo.com/api/v1/brokers/lead/";
const API_KEY = 'f7f2cbbdc0184aba9ba01606968fa6da';
//example: заполняем свой const API_KEY = ''
function log_broker($request_url, $response)
{
$ip = $_REQUEST['REMOTE_ADDR'];
$date_now = date('Y-m-d H:i:s');
$fp = fopen('brokerLogs.txt', 'a+');
fwrite($fp, "Error send to broker api \nRequest url: {$request_url}\nResponse: {$response}\n\n\n=====================\n\n\n");
fclose($fp);
}
$isCurlEnabled = function(){
return function_exists('curl_version');
};
if (!$isCurlEnabled) {
echo "<pre>";
echo "pls install curl\n";
echo "For *unix open terminal and type this:\n";
echo 'sudo apt-get install curl && sudo apt-get install php-curl';
die;
}
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
$ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$ip = $_SERVER['REMOTE_ADDR'];
}
$args = [
'base_url' => 'http://my-domain.com/',
//example: заполняем свой const 'base_url' => '',
'referrer' => 'http://my-click-site.com',
//example: заполняем свой const 'referrer' => '',
'first_name' => $_POST['first_name'],
'last_name' => $_POST['last_name'],
'email' => $_POST['email'],
'phone' => $_POST['phone'],
'password' => $_POST['password'],
'country_code' =>'MX',
//example: заполняем свой const 'country_code' =>'',
'esub' => '-7EBNQCgQAAAEEA96CAAUBARERChEJChENQhENEgABf2FkY29tYm8BMQQ',
//example: заполняем свой const 'esub' => '',
'ip' => '104.250.183.0',
//example: заполняем свой const 'ip' => '',
];
$url = API_URL.'?api_key='.API_KEY;
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $url,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode($args),
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => array(
'Content-Type: application/json',
'Content-Length: ' . strlen(json_encode($args)))
));
$res = curl_exec($curl);
curl_close($curl);
$res = json_decode($res, true);
if ($res['accepted']) {
if($res['redirect_url']) {
header("Location: " . $res['redirect_url']);
exit();
}else{
echo 'Redirect url is empty';
}
} elseif(isset($res['detail'][0]['loc'])) {
if(array_search('email', $res['detail'][0]['loc'])){
echo 'Invalid email';
}elseif(array_search('esub', $res['detail'][0]['loc'])) {
echo 'Invalid esub';
}
else{
var_dump($res);
}
log_broker($request_url, json_encode($res));
//example: Wrong param, please check and correct it.
}else{
echo '<h2>Error:</h2>';
if($res['error']){
echo $res['error'];
}else{
var_dump($res);
}
}