-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
72 lines (54 loc) · 1.5 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
define('CALLBACK_API_EVENT_CONFIRMATION', 'confirmation');
define('CALLBACK_API_EVENT_MESSAGE_NEW', 'message_new');
require_once 'config.php';
require_once 'global.php';
require_once 'api/vk_api.php';
require_once 'bot/bot.php';
if (!isset($_REQUEST)) {
exit;
}
callback_handleEvent();
function callback_handleEvent() {
$event = _callback_getEvent();
try {
switch ($event['type']) {
//Подтверждение сервера
case CALLBACK_API_EVENT_CONFIRMATION:
_callback_handleConfirmation();
break;
//Получение нового сообщения
case CALLBACK_API_EVENT_MESSAGE_NEW:
_callback_handleMessageNew($event['object']);
break;
default:
_callback_response('Unsupported event');
break;
}
} catch (Exception $e) {
log_error($e);
}
_callback_okResponse();
}
function _callback_getEvent() {
return json_decode(file_get_contents('php://input'), true);
}
function _callback_handleConfirmation() {
_callback_response(CALLBACK_API_CONFIRMATION_TOKEN);
}
function _callback_handleMessageNew($data) {
$user_id = $data['user_id'];
file_put_contents('log.txt', strpos($data['body'], 'Хочу мем'), FILE_APPEND);
if(strpos(mb_strtolower($data['body']), 'хочу мем') === false){
} else {
bot_sendMessage($user_id);
_callback_okResponse();
}
}
function _callback_okResponse() {
_callback_response('ok');
}
function _callback_response($data) {
echo $data;
exit();
}