php быдлокод error_reporting E_ALL class VK protected token ch secret

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
//быдлокод
error_reporting(E_ALL);
class VK {
protected $token, $ch, $secret, $captcha = false, $captcha_sid, $captcha_code;
function __construct() {
$this->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 '<form action="?" method="POST"><img src="data:image/png;base64,' . base64_encode($captcha) . '"><br/><input type="text" name="captcha"><input type="hidden" name="sid" value="' .$resp['error']['captcha_sid'] .'"><br/><input type="submit" value="okay"></form>';
}