SHARE
TWEET

Untitled

a guest Mar 20th, 2019 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. const API = '5.92'; //версия апи
  3. const TOKEN = ''; //токен
  4. const KEY = ''; //ключ каллбэка
  5.  
  6.  
  7.     $data = json_decode(file_get_contents("php://input"));
  8.  
  9.     switch ($data->type){
  10.         case 'confirmation':
  11.             echo KEY;
  12.             break;
  13.         case 'message_new':
  14.             $data = $data->object;
  15.             $user_id = $data->from_id;
  16.             $peer_id = $data->peer_id;
  17.             $message = $data->text;
  18.             switch ($message){
  19.                 case '/debug':
  20.                     MsgSend("[Debug]\npeer_id=".$peer_id."\n[".date('H:i:s')." || ".date('Y-m-d')."]", $peer_id);
  21.                     echo 'ok';
  22.                     break;
  23.             }
  24.             break;
  25.         default:
  26.             echo 'ok';
  27.             exit;
  28. }
  29. function call($method, $params = [])
  30.     {
  31.       $methods = 'https://api.vk.com/method/';
  32.       $params['access_token'] = TOKEN;
  33.       $params['v'] = API;
  34.       $url = $methods . $method . '?' . http_build_query($params);
  35.       $curl = curl_init($url);
  36.       curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  37.       $json = curl_exec($curl);
  38.       curl_close($curl);
  39.       $response = json_decode($json, true);
  40.      return $response['response'];
  41.     }
  42.  
  43. function MsgSend($message, $peer_id, $attachments = [])
  44.     {
  45.        return call('messages.send', [
  46.          'random_id' => rand(),
  47.          'peer_id' => $peer_id,
  48.          'message' => $message,
  49.          'payload' => 1000,
  50.          'attachment' => implode(',', $attachments)
  51.      ]);
  52.     }
  53. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top