-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvk.php
45 lines (40 loc) · 1.24 KB
/
vk.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
<?php
require_once('config.php');
/*
* Support: VK API v. 5.80
* Licence: MIT
* Author: Sherzod Mamadaliev
* Contact: mamadaliev@yahoo.com
*/
class VK
{
private $version = VERSION;
private $url = 'https://api.vk.com/method/';
private $token = TOKEN;
private $key = KEY;
public $data = '';
public function __construct() {
$this->data = json_decode(file_get_contents('php://input'), true);
if ($this->data['type'] == 'confirmation') exit($this->key);
else print('ok');
}
public function call($method, $params = []) {
$params['access_token'] = $this->token;
$params['v'] = $this->version;
$url = $this->url.$method.'?'.http_build_query($params);
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$json = curl_exec($curl);
curl_close($curl);
$response = json_decode($json, true);
return $response['response'];
}
public function send($peer_id, $message, $attachments = []) {
return $this->call('messages.send', [
'random_id' => rand(),
'peer_id' => $peer_id,
'message' => $message,
'attachment' => implode(',', $attachments),
]);
}
}