Advertisement
Guest User

Mark Smetanka

a guest
Feb 23rd, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.87 KB | None | 0 0
  1. <?php
  2.  
  3.   ################
  4.  /*
  5.    * By Sat1een Team
  6.    * @club123
  7.   */
  8.   ###############
  9.  
  10.   class VK
  11.   {
  12.       /*
  13.        * @var string - $acccess_token
  14.        * @var string - $version
  15.       */
  16.       private $access_token;
  17.       private $version;
  18.      
  19.       /*
  20.        * @var string|null - $last_error_msg
  21.        * @var int|null - $last_error_code
  22.       */
  23.       private $last_error_msg = null;
  24.       private $last_error_code = null;
  25.      
  26.       public function __construct(string $access_token, string $version = "5.80")
  27.       {
  28.           $this->access_token = $access_token;
  29.           $this->version = $version;
  30.       }
  31.  
  32.      /*
  33.       * @return bool
  34.      */
  35.      public function isValidToken()
  36.      {
  37.        return !is_null($this->call("users.get"));
  38.      }
  39.      
  40.       /*
  41.        * @return array|null
  42.       */
  43.       public function call(string $method, array $params = [])
  44.       {
  45.           $params["access_token"] = $this->access_token;
  46.           $params["v"] = $this->version;
  47.          
  48.           $url = "https://api.vk.com/method/";
  49.           $url .= $method . "?";
  50.           $url .= http_build_query($params);
  51.          
  52.           $ch = curl_init($url);
  53.          
  54.             curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  55.             curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  56.            
  57.           $response = curl_exec($ch);
  58.           $response = json_decode($response, true);
  59.          
  60.           if(isset($response["response"]))
  61.             return $response["response"];
  62.          
  63.           $error = $response["error"];
  64.          
  65.           $this->last_error_msg = $error["error_msg"];
  66.           $this->last_error_code = $error["error_code"];
  67.          
  68.           return null;
  69.       }
  70.      
  71.      
  72.       public function getErrorMsg()
  73.       {
  74.           return $this->last_error_msg;
  75.       }
  76.      
  77.       public function getErrorCode()
  78.       {
  79.           return $this->last_error_code;
  80.       }
  81.   }
  82.  
  83.  
  84. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement