This repository was archived by the owner on Oct 25, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathexample-bot.php
More file actions
80 lines (62 loc) · 2.08 KB
/
Copy pathexample-bot.php
File metadata and controls
80 lines (62 loc) · 2.08 KB
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
71
72
73
74
75
76
77
78
79
80
<?php
/**
* Пример использования lib.php в боте
* Мне было лень расписывать все функции, здесь показан минимальный пример использования
*
* Не забудьте поменять ACCESS_TOKEN, CONFIRMATION_TOKEN и SECRET_KEY (если нужно)!
*/
include './lib.php';
define("API_VERSION", "5.95");
define("ACCESS_TOKEN", "z69wphsbj9ngxc37v7rkdnshwp8hkta58hpxsa8yrr6vptggd494kawv9q76vdt6h9x5z4vkeeryr9yunhze8");
define("CONFIRMATION_TOKEN", "qHmX3KvW");
// define("SECRET_KEY", "");
function vkapi($m, $p = []) {
if(!isset($p['lang'])) $p['lang'] = 'ru';
if(!isset($p['access_token'])) $p['access_token'] = ACCESS_TOKEN;
if(!isset($p['v'])) $p['v'] = API_VERSION;
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => "https://api.vk.com/method/{$m}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $p
]);
$json = curl_exec($ch);
curl_close($ch);
return json_decode($json, true);
}
function send($peer_id, $message) {
$p['peer_id'] = $peer_id;
$p['message'] = $message;
$p['random_id'] = 0;
$r = vkapi('messages.send', $p);
if(isset($response['error'])) return $response['error'];
return true;
}
$data = json_decode(file_get_contents('php://input'), true);
if(!$data) { // if(!$data || $data['secret'] != SECRET_KEY)
return;
}
switch($data['type']) {
case 'confirmation':
echo CONFIRMATION_TOKEN;
break;
case 'message_new':
echo 'ok';
$vkcoin = new VKCoinClient(305360617, 'cNwFTVP7Y33M5TxgZMhLQmdcNrb6qu72mNCTeRdX9PVEqbJPpe');
$peer_id = $data['object']['peer_id'];
$user_id = $data['object']['from_id'];
$message = mb_strtolower($data['object']['text'], 'UTF-8');
$message_exp = explode(' ', $message);
switch($message_exp[0]) {
case 'баланс':
$balance = str_replace('.', ',', $vkcoin->getBalance([$user_id])['response'][$user_id] / 1000);
send($peer_id, "Твой баланс: {$balance}");
break;
default:
send($peer_id, "Шо? Такой команды нет!");
break;
}
break;
}
?>