· 6 years ago · Mar 27, 2019, 06:22 PM
1<?php
2class VkApi{
3 private static $acs_tok;
4 private static $verif_code;
5 private static $version;
6 private static $secrt_key;
7 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';
8 public function version($vers){
9 self::$version = $vers;
10 }
11 public function verification($v){
12 self::$verif_code = $v;
13 }
14 public function access($token){
15 self::$acs_tok = $token;
16 }
17 public function secret($key){
18 self::$secrt_key = $key;
19 }
20 public static function send($message, $chat_id){
21 $request_params = array(
22 'message' => $message,
23 'chat_id' => $chat_id,
24 'access_token' => self::$acs_tok,
25 'v' => self::$version
26 );
27 $get_params = http_build_query($request_params);
28 file_get_contents('https://api.vk.com/method/messages.send?'. $get_params);
29 }
30 public function show_all(){
31 $all = [self::$acs_tok,self::$verif_code,self::$version,self::$secrt_key];
32 return $all;
33 }
34 public function edit_name($new_name, $chat_id){
35 $request_params = array(
36 'title' => $new_name,
37 'chat_id' => $chat_id,
38 'v' => self::$version,
39 'access_token' => self::$acs_tok
40 );
41 file_get_contents('https://api.vk.com/method/messages.editChat?'.http_build_query($request_params));
42 }
43 public function get_members($peer_id, $fields = false,$is_chat = false){
44 if($is_chat != false){
45 $peer_id += 2000000000;
46 }
47 if($fields == false){
48 $fields = self::$ALL_FIELDS;
49 }
50 $req_params = array(
51 'access_token' => self::$acs_tok,
52 'v' => self::$version,
53 'peer_id' => $peer_id,
54 'fields' => $fields
55 );
56 $user3 = json_decode(file_get_contents('https://api.vk.com/method/messages.getConversationMembers?'.http_build_query($req_params)));
57 return $user3->response;
58 }
59 public function kick($user_id,$chat_id){
60 $req_params = array(
61 'access_token' => self::$acs_tok,
62 'v' => self::$version,
63 'user_id' => $user_id,
64 'chat_id' => $chat_id
65 );
66 file_get_contents('https://api.vk.com/method/messages.removeChatUser?'.http_build_query($req_params));
67 }
68 public function information($user_id, $case = 'Nom', $fields = false){
69 if($fields == false){
70 $fields = self::$ALL_FIELDS;
71 }
72 $req_params = array(
73 'access_token' => self::$acs_tok,
74 'v' => self::$version,
75 'name_case' => $case,
76 'fields' => $fields,
77 'user_ids' => $user_id
78 );
79 $user = json_decode(file_get_contents('https://api.vk.com/method/users.get?'.http_build_query($req_params)));
80 return $user->response;
81 }
82 }
83
84?>