php error_reporting -1 set_time_limit function vk method data token ur

 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
<?php
error_reporting(-1);
set_time_limit(0);
function vk($method, $data, $token = "")
{
$url = "https://api.vk.com/method/" . $method;
if ($curl = curl_init()) {
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
$data['access_token'] = $token;
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
$out = curl_exec($curl);
curl_close($curl);
return $out;
}
return true;
}
function send($chat_id, $message, $attachment = 0)
{
vk("messages.send", array(
"chat_id" => $chat_id,
"message" => $message,
"attachment" => $attachment
));
return true;
}
$chat_id = ;
$bot_id = ;
$admin_id = array();
$start = time();
$last = 0;
$i = 0;
while (1) {
$res = json_decode(vk("messages.getHistory", array(
"chat_id" => $chat_id,
"count" => 1,
"start_msg_id" => 0
)), 1);
$i = 1;
$msg = $res["response"][$i]["body"];
if ($res["response"][$i]["mid"] > $last) {
$who_send = (int)$res["response"][$i]["uid"];
$args = explode(' ', $msg);
switch ($args[0]) {
case '!test':
send($chat_id, "test!");
break;
}
}
$last = $res["response"][1]["mid"];
}