· 5 years ago · Jun 16, 2020, 04:10 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$user_info = json_decode(file_get_contents("https://api.vk.com/method/users.get?access_token=41c44d106b493a17f4c492116207c1d3d94b0c68ccd49c8f77d762f0fbad70b4bf2a2a312cf7dcb9e1aae"));
9$user_name = $user_info->response[0]->first_name;
10$statja = "https://vk.com/@insight_bot-spisok-komand";
11$poroh = rand(1, 20);
12$ap = rand(1, 10);
13if($data['type'] == "confirmation") echo KEY; else {
14 switch ($data['type']){
15 case 'message_new':
16 $data = $data['object']['message'];
17 $peer_id = $data['peer_id'];
18 $user_id = $data['from_id'];
19 $msg = $data['text'];
20 switch(mb_strtolower($msg)){ //зависимость от регистра кмд убрана
21 case "start":
22 msgSend("?♂ [id$peer_id|$user_name ?], команды, а также их подробные описания доступны по ссылке ? \n $statja" , $peer_id);
23 break;
24 case "города":
25 msgSend("Список городов: \n -Denver \n - Futurama", $peer_id);
26 break;
27 case "фото":
28 msgSend(" привет ", $peer_id, upload("Main.png", $peer_id));
29 break;
30 case "порох":
31 msgSend("?Победа?\n \n?Имя пользователя, вы выиграли: \n \n• ?порох— +$poroh стаков\n• ?АР— +$ap стаков", $peer_id);
32 break;
33 }
34 break;
35 }
36}
37
38function call($method, $params = [])
39{
40 $curl = curl_init('https://api.vk.com/method/' . $method . '?access_token=' . TOKEN . '&v=' . API);
41 curl_setopt_array($curl, [
42 CURLOPT_POST => true,
43 CURLOPT_POSTFIELDS => $params,
44 CURLOPT_RETURNTRANSFER => true
45 ]);
46 $response = json_decode(curl_exec($curl), true);
47 curl_close($curl);
48 return $response['response'];
49}
50
51function msgSend($text, $peer_id, $attachments = []){
52 if(!is_array($attachments)) $attachments = [$attachments];
53 return call('messages.send',
54 [
55 'random_id' => 0,
56 'peer_id' => $peer_id,
57 'message' => mb_substr($text, 0, 4096),
58 'attachment' => implode(',', $attachments),
59 'disable_mentions' => 1,
60 ]);
61}
62
63function upload($file, $peer_id)
64 {
65 $server = json_decode(file_get_contents('https://api.vk.com/method/photos.getMessagesUploadServer?v=' . API . '&access_token=' . TOKEN . '&peer_id=' . $peer_id), true)['response']['upload_url'];
66 $ch = curl_init($server);
67 curl_setopt_array($ch, [
68 CURLOPT_RETURNTRANSFER => true,
69 CURLOPT_POST => true,
70 CURLOPT_POSTFIELDS => [
71 'photo' => new CURLfile(realpath($file))
72 ]
73 ]);
74 $data = json_decode(curl_exec($ch), true);
75 curl_close($ch);
76 $d1 = json_decode(file_get_contents('https://api.vk.com/method/photos.saveMessagesPhoto?v=' . API . '&access_token=' . TOKEN . '&server=' . $data['server'] . '&hash=' . $data['hash'] . '&photo=' . $data['photo']), true);
77 return "photo" . $d1['response'][0]['owner_id'] . "_" . $d1['response'][0]['id'];
78 }