-
Notifications
You must be signed in to change notification settings - Fork 0
/
vk_app.php
141 lines (113 loc) · 3.46 KB
/
vk_app.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<?php
namespace sborislav\vk_app;
class vk_user
{
public $id;
public $auth_key;
public $group;
public $type;
public $install;
public $hash;
public $is_secure;
public function create_user($get)
{
$this->id = (int)$get['viewer_id']; // id пользователя
$this->group = (int)$get['group_id']; // id группы
$this->auth_key =(string)$get['auth_key']; //подлинности сессии на сервере
$this->type = (int)$get['viewer_type']; // 4 - admin , 3 - редактор, 2 модератор, 1 участник, 0 - никто
$this->install = (int)$get['is_app_user']; // приожение установлено в группу = 1, нет = 0
$this->hash = (string)$get['hash']; // данные после символа # в строке адреса
$this->is_secure = (int)$get['is_secure']; // данные после символа # в строке адреса
}
}
class vk_app extends vk_user
{
private $_id_app;
private $_secret_app;
public $nameGroup;
public $urlImg;
public $cover_enabled;
private $_isContinue = true;
public function __construct($id = false, $secret_app = false)
{
if ( $id && $secret_app)
{
$this->_id_app = $id;
$this->_secret_app = $secret_app;
}
else
{
$this->_isContinue = false;
}
}
public function isContinue()
{
return $this->_isContinue;
}
public function isInstall()
{
return $this->install;
}
public function isGroup()
{
return (bool)$this->group;
}
public function idGroup()
{
return $this->group;
}
public function apiGroup()
{
$request_params = array(
'group_id' => $this->group,
'fields' => 'cover',
'v' => '5.63'
);
$get_params = http_build_query($request_params);
$result = json_decode(file_get_contents('https://api.vk.com/method/groups.getById?'. $get_params));
if ($result && !isset( $result -> error ) )
{
$this->nameGroup = $result -> response[0] -> name;
$this->cover_enabled = $result -> response[0] -> cover -> enabled;
if ( $this->cover_enabled )
{
$this->urlImg = $result -> response[0] -> cover -> images[2] -> url;
}
else
{
$this->urlImg = $result -> response[0] -> photo_200;
}
}
else
{
$this->_isContinue = false;
}
}
public function hash($get)
{
if ( !isset($get['api_url']) )
{
$this->_isContinue = false;
}
else
{
$sign = "";
foreach ($get as $key => $param)
{
if ($key == 'hash' || $key == 'sign' || $key == 'api_result') continue;
$sign .=$param;
}
$x = false;
if ( isset($get['sign']) ) hash_hmac('sha256', $sign, $this->_secret_app) == $get['sign'] ? $x = true : $x = false;
if ($x) {
$this->create_user($get);
$this->apiGroup();
} else $this->_isContinue = false;
}
}
public function check_session()
{
return ( $this->auth_key == md5($this->_id_app + '_' + $this->id + '_' + $this->_secret_app) );
}
}
?>