Added VKBot
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user