Advertisement
alexx876

Untitled

Jul 17th, 2019
294
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.35 KB | None | 0 0
  1. <?php
  2.  
  3. if (is_file('config.php')) {
  4. require_once 'config.php';
  5. } else {
  6. exit('Для начала работы необходимо сконфигурировать приложение');
  7. }
  8.  
  9. $token = defined('KMA_ACCESS_TOKEN') ? KMA_ACCESS_TOKEN : 'access token';
  10. $channel = defined('KMA_CHANNEL') ? KMA_CHANNEL : 'channel';
  11. $debug = defined('KMA_DEBUG') ? KMA_DEBUG : false;
  12.  
  13. if ($debug) {
  14. error_reporting(E_ALL);
  15. ini_set('display_errors', 1);
  16. }
  17.  
  18. require_once 'KmaLead.php';
  19.  
  20. /** @var KmaLead $kma */
  21. $kma = new KmaLead($token);
  22.  
  23. if (isset($_SERVER['HTTP_X_KMA_API']) && $_SERVER['HTTP_X_KMA_API'] === 'click') {
  24. echo $kma->getClick($channel);
  25. exit();
  26. }
  27.  
  28. if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
  29. exit();
  30. }
  31.  
  32. $data = [
  33. 'channel' => $channel,
  34. 'ip' => $_SERVER['REMOTE_ADDR'],
  35. ];
  36.  
  37. foreach (['name', 'phone', 'data1', 'data2', 'data3', 'data4', 'data5', 'click', 'referer', 'return_page', 'client_data'] as $item) {
  38. if (isset($_POST[$item]) && !empty($_POST[$item])) {
  39. $data[$item] = $_POST[$item];
  40. }
  41. }
  42.  
  43. $kma->debug = $debug;
  44.  
  45. if (isset($_POST['return_page']) && !empty($_POST['return_page'])) {
  46. echo $kma->addLeadAndReturnPage($data);
  47. exit();
  48. } else {
  49. $order = $kma->addLead($data);
  50. $name = $data['name'];
  51. $phone = $data['phone'];
  52. }
  53.  
  54. //TELEGRAM NOTIFICTION
  55. //НАСТРОЙКИ
  56. $chatsId = [572821502,464067220]; //id пользователя кому отправлять сообщение
  57. $content = "Имя: ".$data['name']."\nТелефон: ".$data['phone']."\nОффер: ".'MaxiSize'."\nСайт: ".'hhsell.ru'; //Уведомление
  58.  
  59. foreach ($chatsId as $chatId) {
  60. //не трогать далее
  61. $urlChat = 'https://api.telegram.org/bot871266550:AAGgFIZJ8sgQV8vrp8DPOgqqA451gPVFx3E/sendMessage?' . http_build_query(
  62. [
  63. 'chat_id' => $chatId,
  64. 'text' => $content,
  65. ]);
  66.  
  67. $options = array(
  68. 'http' => array(
  69. 'header' => "Content-type: application/x-www-form-urlencoded\r\n",
  70. 'method' => 'GET'
  71. )
  72. );
  73. $context = stream_context_create($options);
  74. file_get_contents($urlChat, false, $context);
  75. }
  76. //TELEGRAM NOTIFICTION
  77.  
  78. if (empty($order)) {
  79. include_once 'template/error.php';
  80. } else {
  81. include_once 'template/success.php';
  82. }
  83.  
  84. exit();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement