-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVkCallback.php
More file actions
61 lines (53 loc) · 1.66 KB
/
Copy pathVkCallback.php
File metadata and controls
61 lines (53 loc) · 1.66 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
<?php
class VkCallback{
private string $secret;
private array $events;
private string $ccode;
public ?stdClass $data;
public function __construct(string $ccode, string $secret = '') {
$this->secret = $secret;
$this->ccode = $ccode;
$this->events = [];
$this->addEvent('confirmation',function() {
echo $this->ccode;
});
$this->data = json_decode(file_get_contents('php://input'));
}
public function addEvent(string $event, callable $callback) {
$this->events[$event] = $callback;
}
public function getAttachments(array $obj = null): array {
$obj = $this->getObject();
if(is_null($obj)) return [];
$a = $obj->attachments;
$r = [];
if(count($a) > 0) {
foreach($a as $f) {
$r[] = new Attach($f);
}
}
if(!empty($obj->geo)) $r[] = new Attach($obj->geo);
return $r;
}
public function init() {
if($this->data->secret == $this->secret) {
$f = $this->events[$this->data->type];
if(!empty($f)) $f();
}
}
public function getObject(): ?object {
if(empty($this->data)) return null;
$o = $this->data->object;
if(count($o->copy_history) > 0){
$c = $o->copy_history[0];
$t = "";
if(!empty($o->text)) $t = $o->text."\n\n";
$c->text = $t.$c->text;
return $c;
}
return $this->data->object;
}
public static function api(string $method, array $params, string $token = Config::VK_TOKEN): object {
return json_decode(Util::get('https://api.vk.com/method/'.$method.'?'.http_build_query($params).'&access_token='.$token.'&v='.Config::API_V, ['User-Agent: KateMobileAndroid/70-486 (Android 10; SDK 29; arm64-v8a; samsung SM-A715F; ru)']));
}
}