$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => 'https://api.vk.com/method/wall.post',
CURLOPT_POST => true,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => [
'owner_id' => '',
'message' => '',
'access_token' => '',
'v' => '5.85'
]
]);
$response = curl_exec($curl);
if ($response === false) {
die('Во время запроса произошла ошибка!'.PHP_EOL.curl_errno($curl).' - '.curl_error($curl));
}
$response = json_decode($response, true);
if (isset($response['error'])) {
die('Ошибка VK API!'.PHP_EOL.$response['error']['error_code'].' - '.$response['error']['error_msg']);
}
curl_close($curl);
$response = $response['response'];
var_dump($response);
$router = new AltoRouter();
$router->map( 'GET', '/form', function() {
# Вывод формы
});
$router->map( 'POST', '/form', function() {
# Обработка формы и вывод результата или редирект на /form в случае неудачи
});
function vk_fans_count($group_id) {
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => 'https://api.vk.com/method/groups.getMembers',
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_POSTFIELDS => [
'group_id' => $group_id,
'count' => 0,
'v' => 5.73
]
]);
$response = json_decode(curl_exec($curl))->response;
curl_close($curl);
return $response->count;
}