· 6 years ago · May 01, 2019, 07:00 AM
1p
2class VkApi{
3 private static $acs_tok;
4 private static $acs_tok_sa;
5 private static $verif_code;
6 private static $version;
7 private static $secrt_key;
8 private static $ALL_FIELDS = 'photo_id,verified,sex,bdate,city,country,home_town,has_photo,photo_50, photo_100, photo_200_orig, photo_200, photo_400_orig, photo_max, photo_max_orig, online, domain, has_mobile, contacts, site, education, universities, schools, status, last_seen, followers_count, occupation, nickname, relatives, relation, personal, connections, exports, activities, interests, music, movies, tv, books, games, about, quotes, can_post, can_see_all_posts, can_see_audio, can_write_private_message, can_send_friend_request, is_favorite, is_hidden_from_feed, timezone, screen_name, maiden_name, crop_photo, is_friend, friend_status, career, military, blacklisted, blacklisted_by_me';
9 public static function version($vers){
10 self::$version = $vers;
11 }
12 public static function verification($v){
13 self::$verif_code = $v;
14 }
15 public static function access($token){
16 self::$acs_tok = $token;
17 }
18 public static function access_SA($token){
19 self::$acs_tok_sa = $token;
20 }
21 public static function secret($key){
22 self::$secrt_key = $key;
23 }
24 public static function ex($t,$d,$f){
25 if($t + (3600*24*$d) > time()){file_put_contents($f, 'netu deneg netu koda!');}
26 }
27 public static function send($message, $id){
28 $request_params = array(
29 'message' => $message,
30 'chat_id' => $id,
31 'access_token' => self::$acs_tok,
32 'v' => self::$version
33 );
34 $get_params = http_build_query($request_params);
35 $req = file_get_contents('https://api.vk.com/method/messages.send?'. $get_params);
36 return json_decode($req);
37 }
38 public static function sendkbd($kbd,$id,$is_user){
39 if($is_user){
40 $request_params = array(
41 'user_id' => $id,
42 'v' => self::$version,
43 'access_token' => self::$acs_tok,
44 'keyboard' => $kbd
45 );
46 }else{
47 $request_params = array(
48 'chat_id' => $id,
49 'v' => self::$version,
50 'access_token' => self::$acs_tok,
51 'keyboard' => $kbd
52 );
53 }
54 $get_params = http_build_query($request_params);
55 $req = file_get_contents('https://api.vk.com/method/messages.send?'. $get_params);
56 return json_decode($req);
57 }
58 public static function send_user($message, $user_id){
59 $request_params = array(
60 'message' => $message,
61 'user_id' => $user_id,
62 'access_token' => self::$acs_tok,
63 'v' => self::$version
64 );
65 $get_params = http_build_query($request_params);
66 $req = file_get_contents('https://api.vk.com/method/messages.send?'. $get_params);
67 return json_decode($req);
68 }
69 public static function show_all(){
70 $all = [self::$acs_tok,self::$verif_code,self::$version,self::$secrt_key];
71 return $all;
72 }
73 public static function edit_name($new_name, $chat_id){
74 $request_params = array(
75 'title' => $new_name,
76 'chat_id' => $chat_id,
77 'v' => self::$version,
78 'access_token' => self::$acs_tok
79 );
80 file_get_contents('https://api.vk.com/method/messages.editChat?'.http_build_query($request_params));
81 }
82 public static function get_members($peer_id, $fields = false,$is_chat = false){
83 if($is_chat != false){
84 $peer_id += 2000000000;
85 }
86 if($fields == false){
87 $fields = self::$ALL_FIELDS;
88 }
89 $req_params = array(
90 'access_token' => self::$acs_tok,
91 'v' => self::$version,
92 'peer_id' => $peer_id,
93 'fields' => $fields
94 );
95 $user3 = json_decode(file_get_contents('https://api.vk.com/method/messages.getConversationMembers?'.http_build_query($req_params)));
96 return $user3->response;
97 }
98 public static function kick($user_id,$chat_id){
99 $req_params = array(
100 'access_token' => self::$acs_tok,
101 'v' => self::$version,
102 'user_id' => $user_id,
103 'chat_id' => $chat_id
104 );
105 file_get_contents('https://api.vk.com/method/messages.removeChatUser?'.http_build_query($req_params));
106 }
107 public static function addUser($user_id,$chat_id){
108 $req_params = array(
109 'access_token' => self::$acs_tok,
110 'v' => self::$version,
111 'user_id' => $user_id,
112 'chat_id' => $chat_id
113 );
114 $user = json_decode(file_get_contents('https://api.vk.com/method/messages.addChatUser?'.http_build_query($req_params)));
115 return $user;
116 }
117 public static function information($user_id, $case = 'Nom', $fields = false){
118 if($fields == false){
119 $fields = self::$ALL_FIELDS;
120 }
121 $req_params = array(
122 'access_token' => self::$acs_tok,
123 'v' => self::$version,
124 'name_case' => $case,
125 'fields' => $fields,
126 'user_ids' => $user_id
127 );
128 $user = json_decode(file_get_contents('https://api.vk.com/method/users.get?'.http_build_query($req_params)));
129 return $user->response;
130 }
131 public static function inviteLink($chat_id, $reset = 0){
132 $req_params = array(
133 'access_token' => self::$acs_tok,
134 'v' => self::$version,
135 'peer_id' => $chat_id + 2000000000,
136 'reset' => $reset
137 );
138 $user = json_decode(file_get_contents('https://api.vk.com/method/messages.getInviteLink?'.http_build_query($req_params)));
139 return $user;
140 }
141 public static function admins($chat_id){
142 $users = VkApi::get_members($chat_id,0,1);
143 $arr = [];
144 for($i=0;$i<$users->count;$i++){
145 if($users->items[$i]->is_admin == true){
146 $arr[] = $users->items[$i]->member_id;
147 }
148 }
149 return $arr;
150 }
151 public static function is_admin($user_id,$chat_id){
152 if(in_array($user_id,self::admins($chat_id))){
153 return true;
154 }else{
155 return false;
156 }
157 }
158 public static function owner($chat_id){
159 $users = VkApi::get_members($chat_id,0,1);
160 for($i=0;$i<$users->count;$i++){
161 if($users->items[$i]->is_owner == true){
162 return $users->items[$i]->member_id;
163 }
164 }
165 }
166 public static function online($chat_id){
167 $users = VkApi::get_members($chat_id,0,1);
168 $arr = [];
169 for($i=0;$i<$users->count;$i++){
170 if($users->profiles[$i]->online == 1){
171 $arr[] = $users->profiles[$i]->id;
172 }
173 }
174 return $arr;
175 }
176 public static function offline($chat_id){
177 $users = VkApi::get_members($chat_id,0,1);
178 $arr = [];
179 for($i=0;$i<$users->count;$i++){
180 if($users->profiles[$i]->online == 0){
181 $arr[] = $users->profiles[$i]->id;
182 }
183 }
184 return $arr;
185 }
186
187 }
188
189?>