Advertisement
alexx876

Untitled

Jun 1st, 2019
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.95 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  * Базовая конфигурация
  5.  */
  6. // * Апи ключ вашего акканута
  7. $apiKey = 'cbc53e26510159991b17e10b8ff050f9';
  8. // * Домен проекта на который происходит отправка заказов
  9. $domain = 'shakes.pro';
  10. // Урл оригинального лендинга, необходим для корректого расчета Вашей статистики
  11. $landingUrl = 'http://nc.neurosystem7.com';
  12. // * Идентификатор оффера на который вы льете
  13. $offerId = '10';
  14. // Код потока заведенного в системе, если указан, статистика будет записываться на данный поток
  15. $streamCode = 'eefx';
  16. // Страница, отдаваемая при успешном заказе
  17. $successPage = 'success.html';
  18. // Страница, отдаваемая в случае ошибки
  19. $errorPage = 'index.html';
  20. /**
  21.  * Формирование отправляемого заказа
  22.  */
  23. $url = "http://$domain?r=/api/order/in&key=$apiKey";
  24. $order = [
  25.     'countryCode' => (!empty($_POST['country']) ? $_POST['country'] : ($_GET['country'] ? $_GET['country'] : 'RU')),
  26.     'createdAt' => date('Y-m-d H:i:s'),
  27.     'ip' => (!empty($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : null), // ip пользователя
  28.     'landingUrl' => $landingUrl,
  29.     'name' => (!empty($_POST['name']) ? $_POST['name'] : ($_GET['name'] ? $_GET['name'] : '')),
  30.     'offerId' => $offerId,
  31.     'phone' => (!empty($_POST['phone']) ? $_POST['phone'] : ($_GET['phone'] ? $_GET['phone'] : '')),
  32.     'referrer' => (!empty($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null),
  33.     'streamCode' => $streamCode,
  34.     'sub1' => (!empty($_GET['sub1']) ? $_GET['sub1'] : ''),
  35.     'sub2' => (!empty($_GET['sub2']) ? $_GET['sub2'] : ''),
  36.     'sub3' => (!empty($_GET['sub3']) ? $_GET['sub3'] : ''),
  37.     'sub4' => (!empty($_GET['sub4']) ? $_GET['sub4'] : ''),
  38.     'userAgent' => (!empty($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '-'),
  39. ];
  40.  
  41. //TELEGRAM NOTIFICTION
  42. //НАСТРОЙКИ
  43. $chatId = ''; //id пользователя кому отправлять сообщение
  44. $content  = "ID: $offerId\nИмя: ".$order['name']."\nТелефон: ".$order['phone']; //Уведомление
  45.  
  46. //не трогать далее
  47. $url = 'https://api.telegram.org/bot871266550:AAGgFIZJ8sgQV8vrp8DPOgqqA451gPVFx3E/sendMessage?' . http_build_query(
  48. [
  49.     'chat_id' => $chatId,
  50.     'text' => $content,
  51. ]);
  52.        
  53. $options = array(
  54.     'http' => array(
  55.         'header' => "Content-type: application/x-www-form-urlencoded\r\n",
  56.         'method' => 'GET'
  57.     )
  58. );
  59. $context = stream_context_create($options);
  60. file_get_contents($url, false, $context);
  61. //TELEGRAM NOTIFICTION
  62.  
  63. /**
  64.  * Отправка заказа
  65.  */
  66. /**
  67.  * @see http://php.net/manual/ru/book.curl.php
  68.  */
  69. $curl = curl_init();
  70. /**
  71.  * @see http://php.net/manual/ru/function.curl-setopt.php
  72.  */
  73. curl_setopt($curl, CURLOPT_URL, $url);
  74. curl_setopt($curl, CURLOPT_POST, true);
  75. curl_setopt($curl, CURLOPT_POSTFIELDS, $order);
  76. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  77. /**
  78.  * @see http://php.net/manual/ru/language.exceptions.php
  79.  */
  80. try {
  81.     $responseBody = curl_exec($curl);
  82.     // тело оказалось пустым
  83.     if (empty($responseBody)) {
  84.         throw new Exception('Error: Empty response for order. ' . var_export($order, true));
  85.     }
  86.     /**
  87.      * @var StdClass $response
  88.      */
  89.     $response = json_decode($responseBody, true);
  90.     // возможно пришел некорректный формат
  91.     if (empty($response)) {
  92.         throw new Exception('Error: Broken json format for order. ' . PHP_EOL . var_export($order, true));
  93.     }
  94.     // заказ не принят API
  95.     if ($response['status'] != 'ok') {
  96.         throw new Exception('Success: Order is accepted. '
  97.             . PHP_EOL . 'Order: ' . var_export($order, true)
  98.             . PHP_EOL . 'Response: ' . var_export($response, true)
  99.         );
  100.     }
  101.     /**
  102.      * логируем данные об обработке заказа
  103.      * @see http://php.net/manual/ru/function.file-put-contents.php
  104.      */
  105.     @file_put_contents(
  106.         __DIR__ . '/order.success.log',
  107.         date('Y.m.d H:i:s') . ' ' . $responseBody,
  108.         FILE_APPEND
  109.     );
  110.     curl_close($curl);
  111.  
  112.     if(!empty($successPage) && is_file(__DIR__ . '/' . $successPage)) {
  113.         include __DIR__ . '/' . $successPage;
  114.     }
  115. } catch (Exception $e) {
  116.     /**
  117.      * логируем ошибку
  118.      * @see http://php.net/manual/ru/function.file-put-contents.php
  119.      */
  120.     @file_put_contents(
  121.         __DIR__ . '/order.error.log',
  122.         date('Y.m.d H:i:s') . ' ' . $e->getMessage() . PHP_EOL . $e->getTraceAsString(),
  123.         FILE_APPEND
  124.     );
  125.  
  126.     if(!empty($errorPage) && is_file(__DIR__ . '/' . $errorPage)) {
  127.         include __DIR__ . '/' . $errorPage;
  128.     }
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement