Advertisement
Guest User

Untitled

a guest
Sep 25th, 2019
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.53 KB | None | 0 0
  1. <?php
  2. if (!isset($_REQUEST)){
  3.     return;
  4. }
  5.  
  6. $confirmationToken = ''; // Токен подтверждения
  7. $token = ''; // Токен сообщества
  8. $secretKey = ''; // Секретная фраза
  9. $data = json_decode(file_get_contents('php://input'));
  10.  
  11. if (strcmp($data->secret, $secretKey) !== 0) {
  12.     return;
  13. }
  14.  
  15. function getBtn($label, $color, $payload = '')
  16. {
  17.     return [
  18.         'action' => [
  19.             'type' => 'text',
  20.             "payload" => json_encode($payload, JSON_UNESCAPED_UNICODE),
  21.             'label' => $label
  22.         ],
  23.         'color' => $color
  24.     ];
  25. }
  26.  
  27. switch ($data->type)
  28. {
  29.     case 'confirmation':
  30.         die($confirmationToken);
  31.         break;
  32.     case 'message_new':
  33.         $userID = $data->object->from_id;
  34.         $userMsg = $data->object->text;
  35.        
  36.         if ($userMessage == "Привет")
  37.         {
  38.             $keyboard = [
  39.                 'one_time' => false,
  40.                 'buttons' => [
  41.                     [
  42.                         getBtn("1", 'negative', '1'),
  43.                         getBtn("2", 'negative', '2'),
  44.                         getBtn("3", 'negative', '3'),
  45.  
  46.                     ],
  47.                     [
  48.                         getBtn("4", 'negative', '4'),
  49.                         getBtn("5", 'negative', '5'),
  50.                         getBtn("6", 'negative', '6'),
  51.                     ],
  52.                 ]
  53.             ];
  54.            
  55.             $request_params = array
  56.                 (
  57.                     'message' => "Привет",
  58.                     'user_id' => $userId,
  59.                     'access_token' => $token,
  60.                     'keyboard' => json_encode($keyboard),
  61.                     'v' => '5.50'
  62.                 );
  63.  
  64.             $get_params = http_build_query($request_params);
  65.             file_get_contents('https://api.vk.com/method/messages.send?' . $get_params);
  66.         }
  67.     echo('ok');
  68.     break;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement