· 5 years ago · Jun 15, 2020, 08:06 AM
1<?php
2
3const TOKEN = "0ba3fb3dd0738527bbded8a15dff1db607e610b4d1ac36b278e90e7ffb8a698c83b5a723828dcd5562729";
4const API = 5.107;
5const KEY = "4d781a00";
6
7$data = json_decode(file_get_contents('php://input'), true);
8
9if($data['type'] == "confirmation") echo KEY; else {
10 switch ($data['type']){
11 case 'message_new':
12 $data = $data['object']['message'];
13 $peer_id = $data['peer_id'];
14 $user_id = $data['from_id'];
15 $msg = $data['text'];
16 switch(mb_strtolower($msg)){
17 case "start":
18 msgSend("Олла, друк! \n меня ещё пишут", $peer_id);
19 break;
20 case "города":
21 msgSend("Список городов: \n -Denver \n - Futurama", $peer_id);
22 break;
23 }
24 if($msg == "Start")
25 break;
26 }
27}
28
29function call($method, $params = [])
30{
31 $curl = curl_init('https://api.vk.com/method/' . $method . '?access_token=' . TOKEN . '&v=' . API);
32 curl_setopt_array($curl, [
33 CURLOPT_POST => true,
34 CURLOPT_POSTFIELDS => $params,
35 CURLOPT_RETURNTRANSFER => true
36 ]);
37 $response = json_decode(curl_exec($curl), true);
38 curl_close($curl);
39 return $response['response'];
40}
41
42function msgSend($text, $peer_id){
43 return call('messages.send',
44 [
45 'random_id' => 0,
46 'peer_id' => $peer_id,
47 'message' => mb_substr($text, 0, 4096),
48 'disable_mentions' => 1,
49 ]);
50}