ch = curl_init(); } public function setToken($token) { $this->token = $token; return $this; } public function setCaptcha($sid, $code) { $this->captcha = true; $this->captcha_sid = $sid; $this->captcha_code = $code; return $this; } public function query($method, $params = false) { curl_setopt_array($this->ch, [ CURLOPT_URL => 'https://api.vk.com/method/' . $method . (!$params && $this->captcha ? '&captcha_sid=' . $this->captcha_sid . '&captcha_key=' . $this->captcha_code : '') . (!$params && $this->token ? '?access_token=' . $this->token : ''), CURLOPT_RETURNTRANSFER => true ]); if($params) { curl_setopt($this->ch, CURLOPT_POST, true); curl_setopt($this->ch, CURLOPT_POSTFIELDS, http_build_query($params) . ($this->captcha ? '&captcha_sid=' . $this->captcha_sid . '&captcha_key=' . $this->captcha_code : '') . ($this->token ? '&access_token=' . $this->token : '')); $res = curl_exec($this->ch); curl_setopt($this->ch, CURLOPT_POST, false); }else $res = curl_exec($this->ch); $this->captcha = false; return json_decode($res, true); } public function __destruct() { curl_close($this->ch); } } $vk = new VK; $vk -> setToken('xuj'); if($_SERVER['REQUEST_METHOD'] == 'POST') $vk -> setCaptcha($_POST['sid'], $_POST['captcha']); $resp = $vk -> query('wall.post', [ 'owner_id' => '275786934', 'message' => 'API test', 'attachments' => 'https://vovka.pw' ]); print_r($resp); if(isset($resp['error']['captcha_img'])) { $captcha = file_get_contents($resp['error']['captcha_img']); echo '


'; }