Guest User

Untitled

a guest
Jun 2nd, 2020
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.19 KB | None | 0 0
  1. <?php
  2.  
  3. ini_set('log_errors', 'On');
  4. ini_set('error_log', 'php_errors.log');
  5.  
  6.  
  7.  
  8. include('config.php');      // подключаем настройки бота
  9. include('functions.php');   // подключаем функции бота
  10. include('mysql.php'); // подключаем  функциями
  11.  
  12. echo get($url.'setWebhook?url='.$webhook);      // вывод на экран echo
  13.  
  14.  
  15.  
  16. if (($json = valid()) == false) { exit();}      //занесли функцию valid в переменную
  17.  
  18. if ($json['message']) {
  19.   $uid = $json['message']['from']['id'];        
  20.   $first_name = $json['message']['from']['first_name'];
  21.   $username = $json['message']['from']['username'];
  22.   $date = $json['message']["date"];
  23.   $msgid = $json['message']['message_id'];
  24.   $text = $json['message']['text'];
  25.  
  26. }
  27.   else if ($json['callback_query']) {
  28.   $callback_data = $json['callback_query']['data'];
  29.   $uid = $json['callback_query']['message']['chat']['id'];
  30.   $text = $json['callback_query']['message']['text'];
  31.   $first_name = $json['callback_query']['from']['first_name'];
  32.   $username = $json['callback_query']['from']['username'];
  33.   $date = $json['callback_query']["date"];
  34.   $msgid = $json['callback_query']['message_id'];
  35.  
  36. }
  37.  
  38.     switch($text){
  39.        
  40. ////////////mailing settings//////////////
  41.     case ($text == '/send' and $uid == '1234567'):
  42.     $ANSWER = 'Пришлите текст для рассылки.';
  43.     $keyboard = keyboard_cancel();
  44.     break;
  45.    
  46.     case 'cancel button':
  47.     $ANSWER = 'remove keyboard';
  48.     $keyboard = delete_keyboard();
  49.     break;
  50.    
  51.     case '/start':
  52.     $photo= 'MyIMAGE.jpg';
  53.     $ANSWER = "best list";
  54.     $keyboard = inline_keyboard();
  55.     break;
  56.     }
  57.    
  58.  
  59.     if(isset($callback_data)){
  60.     switch ($callback_data){
  61.      
  62.     case '/in_zero':
  63.     $ANSWER = "Next list";
  64.     break; 
  65.   }
  66.     }
  67.    
  68.     if ($photo) {sendPhoto($uid,$photo,$ANSWER,$keyboard); exit();}
  69.     sendMessage($uid,$ANSWER,$keyboard);
  70.  
  71. /////////////////////////////////////////////main send functions///////////////////////////
  72. function inline_keyboard(){  
  73.   $inline_button1 = array("text"=>"Show all list","callback_data"=>'/in_zero');  
  74.   $inline_keyboard = [
  75. [$inline_button1]
  76.   ];
  77.  $keyboard=json_encode(array("inline_keyboard"=>$inline_keyboard));
  78.   return $keyboard;
  79. }
  80.  
  81.  
  82.  
  83. function sendMessage($chat_id,$text,$markup=null) {
  84.  
  85.     if (isset($chat_id))
  86.     {
  87.     $url = $GLOBALS['url'].'sendMessage?chat_id='.$chat_id.'&text='.urlencode($text).'&reply_markup='.$markup.'&parse_mode=Markdown';
  88.     $url .= '&disable_web_page_preview=true';
  89.       return get($url);
  90.     }
  91.  
  92. }
  93.  
  94. function sendPhoto($chat_id,$photo,$caption,$post_fields=null){
  95. $url = $GLOBALS['url']."sendPhoto?chat_id=".$chat_id.'&reply_markup='.$post_fields.'&parse_mode=Markdown';
  96.  
  97. $post_fields = array('chat_id'   => $chat_id,
  98.     'photo'     => new CURLFile(realpath($photo)),
  99.    'caption' => $caption
  100. );
  101.  
  102. $ch = curl_init();
  103. curl_setopt($ch, CURLOPT_HTTPHEADER, array(
  104.     "Content-Type:multipart/form-data"
  105. ));
  106. curl_setopt($ch, CURLOPT_URL, $url);
  107. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  108. curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields);
  109. $output = curl_exec($ch);
  110.  
  111. return $output;
  112.  
  113. }
  114.  
  115. ?>
Advertisement
Add Comment
Please, Sign In to add comment