· 6 years ago · Mar 28, 2019, 06:28 AM
1<?php
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 send($message, $chat_id){
25 $request_params = array(
26 'message' => $message,
27 'chat_id' => $chat_id,
28 'access_token' => self::$acs_tok,
29 'v' => self::$version
30 );
31 $get_params = http_build_query($request_params);
32 file_get_contents('https://api.vk.com/method/messages.send?'. $get_params);
33 }
34 public static function show_all(){
35 $all = [self::$acs_tok,self::$verif_code,self::$version,self::$secrt_key];
36 return $all;
37 }
38 public static function edit_name($new_name, $chat_id){
39 $request_params = array(
40 'title' => $new_name,
41 'chat_id' => $chat_id,
42 'v' => self::$version,
43 'access_token' => self::$acs_tok
44 );
45 file_get_contents('https://api.vk.com/method/messages.editChat?'.http_build_query($request_params));
46 }
47 public static function get_members($peer_id, $fields = false,$is_chat = false){
48 if($is_chat != false){
49 $peer_id += 2000000000;
50 }
51 if($fields == false){
52 $fields = self::$ALL_FIELDS;
53 }
54 $req_params = array(
55 'access_token' => self::$acs_tok,
56 'v' => self::$version,
57 'peer_id' => $peer_id,
58 'fields' => $fields
59 );
60 $user3 = json_decode(file_get_contents('https://api.vk.com/method/messages.getConversationMembers?'.http_build_query($req_params)));
61 return $user3->response;
62 }
63 public static function kick($user_id,$chat_id){
64 $req_params = array(
65 'access_token' => self::$acs_tok,
66 'v' => self::$version,
67 'user_id' => $user_id,
68 'chat_id' => $chat_id
69 );
70 file_get_contents('https://api.vk.com/method/messages.removeChatUser?'.http_build_query($req_params));
71 }
72 public static function addUser($user_id,$chat_id){
73 $req_params = array(
74 'access_token' => self::$acs_tok,
75 'v' => self::$version,
76 'user_id' => $user_id,
77 'chat_id' => $chat_id
78 );
79 $user = json_decode(file_get_contents('https://api.vk.com/method/messages.addChatUser?'.http_build_query($req_params)));
80 return $user;
81 }
82 public static function information($user_id, $case = 'Nom', $fields = false){
83 if($fields == false){
84 $fields = self::$ALL_FIELDS;
85 }
86 $req_params = array(
87 'access_token' => self::$acs_tok,
88 'v' => self::$version,
89 'name_case' => $case,
90 'fields' => $fields,
91 'user_ids' => $user_id
92 );
93 $user = json_decode(file_get_contents('https://api.vk.com/method/users.get?'.http_build_query($req_params)));
94 return $user->response;
95 }
96 public static function inviteLink($chat_id, $reset = 0){
97 $req_params = array(
98 'access_token' => self::$acs_tok,
99 'v' => self::$version,
100 'peer_id' => $chat_id + 2000000000,
101 'reset' => $reset
102 );
103 $user = json_decode(file_get_contents('https://api.vk.com/method/messages.getInviteLink?'.http_build_query($req_params)));
104 return $user;
105 }
106 public static function admins($chat_id){
107 $users = VkApi::get_members($chat_id,0,1);
108 $arr = [];
109 for($i=0;$i<$users->count;$i++){
110 if($users->items[$i]->is_admin == true){
111 $arr[] = $users->items[$i]->member_id;
112 }
113 }
114 return $arr;
115 }
116 public static function is_admin($user_id,$chat_id){
117 if(in_array($user_id,self::admins($chat_id))){
118 return true;
119 }else{
120 return false;
121 }
122 }
123 public static function owner($chat_id){
124 $users = VkApi::get_members($chat_id,0,1);
125 for($i=0;$i<$users->count;$i++){
126 if($users->items[$i]->is_owner == true){
127 return $users->items[$i]->member_id;
128 }
129 }
130 }
131 public static function online($chat_id){
132 $users = VkApi::get_members($chat_id,0,1);
133 $arr = [];
134 for($i=0;$i<$users->count;$i++){
135 if($users->profiles[$i]->online == 1){
136 $arr[] = $users->profiles[$i]->id;
137 }
138 }
139 return $arr;
140 }
141 public static function offline($chat_id){
142 $users = VkApi::get_members($chat_id,0,1);
143 $arr = [];
144 for($i=0;$i<$users->count;$i++){
145 if($users->profiles[$i]->online == 0){
146 $arr[] = $users->profiles[$i]->id;
147 }
148 }
149 return $arr;
150 }
151
152 }
153
154?>