· 7 years ago · Aug 29, 2018, 12:40 AM
1<?php
2
3if (!isset($_REQUEST)) {
4 return;
5}
6
7$confirmationToken = '36c3fc12';
8$token = 'XXX';
9$secretKey = 'testifvk';
10
11$data = json_decode(file_get_contents('php://input'));
12if(strcmp($data->secret, $secretKey) !== 0 && strcmp($data->type, 'confirmation') !== 0) return;
13
14switch ($data->type)
15{
16 case 'confirmation':
17 echo $confirmationToken;
18 break;
19
20 case 'group_join':
21 $userId = $data->object->user_id;
22 $userInfo = json_decode(file_get_contents("https://api.vk.com/method/users.get?user_ids={$userId}&v=5.0"));
23 $user_name = $userInfo->response[0]->first_name;
24 $request_params = array(
25 'message' => "Привет {$user_name}, ÑпаÑибо за подпиÑочку",
26 'user_id' => $userId,
27 'access_token' => $token,
28 'v' => '5.0'
29 );
30 $get_params = http_build_query($request_params);
31 file_get_contents('https://api.vk.com/method/messages.send?' . $get_params);
32 echo('ok');
33 break;
34
35 case 'group_leave':
36 $userId = $data->object->user_id;
37 $userInfo = json_decode(file_get_contents("https://api.vk.com/method/users.get?user_ids={$userId}&v=5.0"));
38 $user_name = $userInfo->response[0]->first_name;
39 $request_params = array(
40 'message' => "{$user_name}, еххх наш Ñервер будет Ñкучать",
41 'user_id' => $userId,
42 'access_token' => $token,
43 'v' => '5.0'
44 );
45 $get_params = http_build_query($request_params);
46 file_get_contents('https://api.vk.com/method/messages.send?' . $get_params);
47 echo('ok');
48 break;
49}
50
51?>