Advertisement
alexx876

Untitled

Jun 1st, 2019
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.00 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. $chatsId = [1,2,3]; //id пользователя кому отправлять сообщение
  44. $content  = "ID: $offerId\nИмя: ".$order['name']."\nТелефон: ".$order['phone']; //Уведомление
  45.  
  46. foreach ($chatsId as $chatId)  {
  47.     //не трогать далее
  48.     $url = 'https://api.telegram.org/bot871266550:AAGgFIZJ8sgQV8vrp8DPOgqqA451gPVFx3E/sendMessage?' . http_build_query(
  49.     [
  50.         'chat_id' => $chatId,
  51.         'text' => $content,
  52.     ]);
  53.            
  54.     $options = array(
  55.         'http' => array(
  56.             'header' => "Content-type: application/x-www-form-urlencoded\r\n",
  57.             'method' => 'GET'
  58.         )
  59.     );
  60.     $context = stream_context_create($options);
  61.     file_get_contents($url, false, $context);
  62. }
  63. //TELEGRAM NOTIFICTION
  64.  
  65. /**
  66.  * Отправка заказа
  67.  */
  68. /**
  69.  * @see http://php.net/manual/ru/book.curl.php
  70.  */
  71. $curl = curl_init();
  72. /**
  73.  * @see http://php.net/manual/ru/function.curl-setopt.php
  74.  */
  75. curl_setopt($curl, CURLOPT_URL, $url);
  76. curl_setopt($curl, CURLOPT_POST, true);
  77. curl_setopt($curl, CURLOPT_POSTFIELDS, $order);
  78. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  79. /**
  80.  * @see http://php.net/manual/ru/language.exceptions.php
  81.  */
  82. try {
  83.     $responseBody = curl_exec($curl);
  84.     // тело оказалось пустым
  85.     if (empty($responseBody)) {
  86.         throw new Exception('Error: Empty response for order. ' . var_export($order, true));
  87.     }
  88.     /**
  89.      * @var StdClass $response
  90.      */
  91.     $response = json_decode($responseBody, true);
  92.     // возможно пришел некорректный формат
  93.     if (empty($response)) {
  94.         throw new Exception('Error: Broken json format for order. ' . PHP_EOL . var_export($order, true));
  95.     }
  96.     // заказ не принят API
  97.     if ($response['status'] != 'ok') {
  98.         throw new Exception('Success: Order is accepted. '
  99.             . PHP_EOL . 'Order: ' . var_export($order, true)
  100.             . PHP_EOL . 'Response: ' . var_export($response, true)
  101.         );
  102.     }
  103.     /**
  104.      * логируем данные об обработке заказа
  105.      * @see http://php.net/manual/ru/function.file-put-contents.php
  106.      */
  107.     @file_put_contents(
  108.         __DIR__ . '/order.success.log',
  109.         date('Y.m.d H:i:s') . ' ' . $responseBody,
  110.         FILE_APPEND
  111.     );
  112.     curl_close($curl);
  113.  
  114.     if(!empty($successPage) && is_file(__DIR__ . '/' . $successPage)) {
  115.         include __DIR__ . '/' . $successPage;
  116.     }
  117. } catch (Exception $e) {
  118.     /**
  119.      * логируем ошибку
  120.      * @see http://php.net/manual/ru/function.file-put-contents.php
  121.      */
  122.     @file_put_contents(
  123.         __DIR__ . '/order.error.log',
  124.         date('Y.m.d H:i:s') . ' ' . $e->getMessage() . PHP_EOL . $e->getTraceAsString(),
  125.         FILE_APPEND
  126.     );
  127.  
  128.     if(!empty($errorPage) && is_file(__DIR__ . '/' . $errorPage)) {
  129.         include __DIR__ . '/' . $errorPage;
  130.     }
  131. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement