Files
ledstar_laravel/app/Library/VK/VkApiClient.php
T
amikhaylov e90314f18b Added VKBot
2026-05-28 02:16:26 +03:00

39 lines
942 B
PHP

<?php
namespace App\Library\VK;
use Exception;
use GuzzleHttp\ClientInterface;
use GuzzleHttp\Exception\GuzzleException;
final class VkApiClient
{
public function __construct(
protected ClientInterface $http,
protected string $token,
protected string $url,
protected string $version = '5.131'
) {}
/**
* @throws GuzzleException
*/
public function call(
string $method,
array $params = []
): array {
$response = $this->http->request('POST', "{$this->url}/{$method}", [
'form_params' => array_merge($params, [
'access_token' => $this->token,
'v' => $this->version,
]),
]);
if (isset($result['error'])) {
throw new Exception("VK API Error: " . $result['error']['error_msg']);
}
return json_decode($response->getBody()->getContents(), true);
}
}