· 7 years ago · Jul 29, 2018, 02:14 PM
1<?php
2 if (!isset ($_REQUEST)) {
3 return;
4 }
5
6 $confirmationToken = '';
7 $token = '';
8 $secretKey = '';
9
10 $data = json_decode (file_get_contents ('php://input'));
11
12 switch ($data->type) {
13 case 'confirmation':
14 echo $confirmationToken;
15 break;
16 case 'message_new':
17 $user_id = $data->object->from_id;
18 $user_info = json_decode (file_get_contents("https://api.vk.com/method/users.get?user_ids={$user_id}&access_token={$token}&v=5.8"));
19 $user_name = $user_info->response[0]->first_name;
20 $text = $data->object->text;
21 if (strlen ($text) >= 5) {
22 $check_cmd = $text[0] + $text[1] + $text[2] + $text[3];
23 if ($check_cmd === '/cmd') {
24 $request_params = array (
25 'message' => "Я заметил комманду Ñ:",
26 'user_ids' => $user_id,
27 'access_token' => $token,
28 'v' => '5.8'
29 );
30 $get_params = http_build_query ($request_params);
31 file_get_contents ("https://api.vk.com/method/messages.send?". $get_params);
32 }
33 }
34 if ($user_id == 279338513 || $user_id == 167429300) {
35 $request_params = array (
36 'message' => "Привет, $user_name!<br>".
37 "Твой id --> $user_id<br>".
38 "Твой ÑÑ‚Ð°Ñ‚ÑƒÑ - admin",
39 'user_ids' => $user_id,
40 'access_token' => $token,
41 'v' => '5.8'
42 );
43 } else {
44 $request_params = array (
45 'message' => "Привет, $user_name!<br>".
46 "Твой id --> $user_id<br>".
47 "Твой ÑÑ‚Ð°Ñ‚ÑƒÑ - user",
48 'user_ids' => $user_id,
49 'access_token' => $token,
50 'v' => '5.8'
51 );
52 }
53 $get_params = http_build_query ($request_params);
54 file_get_contents ("https://api.vk.com/method/messages.send?". $get_params);
55 echo ('ok');
56 break;
57 }
58?>