Added VKBot

This commit is contained in:
amikhaylov
2026-05-28 02:16:26 +03:00
parent 20450c4ede
commit e90314f18b
16 changed files with 464 additions and 5 deletions
+38
View File
@@ -0,0 +1,38 @@
<?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);
}
}