Advertisement
Guest User

Untitled

a guest
Feb 20th, 2020
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.35 KB | None | 0 0
  1. <?php
  2.  
  3. require('../vendor/autoload.php');
  4.  
  5. $app = new Silex\Application();
  6. $app['debug'] = true;
  7.  
  8. // Register the monolog logging service
  9. $app->register(new Silex\Provider\MonologServiceProvider(), array(
  10.   'monolog.logfile' => 'php://stderr',
  11. ));
  12.  
  13. // Register view rendering
  14. $app->register(new Silex\Provider\TwigServiceProvider(), array(
  15.     'twig.path' => __DIR__.'/views',
  16. ));
  17.  
  18. // Our web handlers
  19.  
  20. $app->get('/', function() use($app) {
  21.   return 'VK Bot';
  22. });
  23.  
  24. $app->post('/bot', function() use($app) {
  25.   $data = json_decode(file_get_contents('php://input'));
  26.   if (!$data)
  27.     return 'No data';
  28.  
  29.   $count = json_decode( file_get_contents('https://api.vk.com/method/messages.getConversations?offset=0&count=100&filter=unanswered&access_token=ACCESS_TOKEN&v=5.103'))->response->count;
  30.   if ($data->type == 'confirmation')
  31.     return 'CONFIRMATION_CODE';
  32.   if ($count != 0)
  33.   {
  34.       $request_params = array(
  35.         'peer_id' => $data->object->message->from_id,
  36.         'random_id' => rand(1, 2147483647),
  37.         'message' => 'Тестирование работы PHP VK бота на Heroku',
  38.         'access_token' => 'ACCESS_TOKEN',
  39.         'v' => '5.103'
  40.       );
  41.       file_get_contents('https://api.vk.com/method/messages.send?' . http_build_query($request_params));
  42.       echo 'ok';
  43.   }
  44.   return 'Error';
  45. });
  46.  
  47. $app->run();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement