Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- ################
- /*
- * By Sat1een Team
- * @club123
- */
- ###############
- class VK
- {
- /*
- * @var string - $acccess_token
- * @var string - $version
- */
- private $access_token;
- private $version;
- /*
- * @var string|null - $last_error_msg
- * @var int|null - $last_error_code
- */
- private $last_error_msg = null;
- private $last_error_code = null;
- public function __construct(string $access_token, string $version = "5.80")
- {
- $this->access_token = $access_token;
- $this->version = $version;
- }
- /*
- * @return bool
- */
- public function isValidToken()
- {
- return !is_null($this->call("users.get"));
- }
- /*
- * @return array|null
- */
- public function call(string $method, array $params = [])
- {
- $params["access_token"] = $this->access_token;
- $params["v"] = $this->version;
- $url = "https://api.vk.com/method/";
- $url .= $method . "?";
- $url .= http_build_query($params);
- $ch = curl_init($url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- $response = curl_exec($ch);
- $response = json_decode($response, true);
- if(isset($response["response"]))
- return $response["response"];
- $error = $response["error"];
- $this->last_error_msg = $error["error_msg"];
- $this->last_error_code = $error["error_code"];
- return null;
- }
- public function getErrorMsg()
- {
- return $this->last_error_msg;
- }
- public function getErrorCode()
- {
- return $this->last_error_code;
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement