Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- const API = '5.92'; //версия апи
- const TOKEN = ''; //токен
- const KEY = ''; //ключ каллбэка
- $data = json_decode(file_get_contents("php://input"));
- switch ($data->type){
- case 'confirmation':
- echo KEY;
- break;
- case 'message_new':
- $data = $data->object;
- $user_id = $data->from_id;
- $peer_id = $data->peer_id;
- $message = $data->text;
- switch ($message){
- case '/debug':
- MsgSend("[Debug]\npeer_id=".$peer_id."\n[".date('H:i:s')." || ".date('Y-m-d')."]", $peer_id);
- echo 'ok';
- break;
- }
- break;
- default:
- echo 'ok';
- exit;
- }
- function call($method, $params = [])
- {
- $methods = 'https://api.vk.com/method/';
- $params['access_token'] = TOKEN;
- $params['v'] = API;
- $url = $methods . $method . '?' . http_build_query($params);
- $curl = curl_init($url);
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
- $json = curl_exec($curl);
- curl_close($curl);
- $response = json_decode($json, true);
- return $response['response'];
- }
- function MsgSend($message, $peer_id, $attachments = [])
- {
- return call('messages.send', [
- 'random_id' => rand(),
- 'peer_id' => $peer_id,
- 'message' => $message,
- 'payload' => 1000,
- 'attachment' => implode(',', $attachments)
- ]);
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement