Добавил колбек

This commit is contained in:
Paradise 2020-09-13 11:47:34 +03:00
parent b3571bcecf
commit 3493000384
4 changed files with 67 additions and 2 deletions

View File

@ -54,3 +54,9 @@ USERAGENT = 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, lik
# ID приложения ВК по умолчанию # ID приложения ВК по умолчанию
APP_ID = '6660888' APP_ID = '6660888'
# Домен сервера для подключения CallBack API
SERVER_DOMAIN =
# Произвольный ключ для подключения к CallBack серверу
CALLBACK_SECRET_KEY =

48
system/API/CallBack.php Normal file
View File

@ -0,0 +1,48 @@
<?php
declare(strict_types=1);
namespace VK\API;
class CallBack extends CallBackAbstract
{
/**
* Адрес для создания колбек-сервера
*
* @var string
*/
private $url;
/**
* Пользовательский ключ колбек-сессии
*
* @var string
*/
private $secret_key;
/**
* Ключ подтверждения колбек сессии
*
* @var string
*/
private $confirmation_token;
/**
* @var int
*/
private $group_id;
public function __construct(object $group, array $params = []){
$this->secret_key = $_ENV['CALLBACK_SECRET_KEY'];
$this->url = $_ENV['SERVER_DOMAIN'];
$this->group_id = $group->id;
$this->group_id->request('groups.addCallbackServer', [
'group_id' => $this->group_id,
'url' => $this->url,
'title' => $this->group_id . 'CallBackServer',
'secret_key' => $this->secret_key
]);
$this->confirmation_token = request('groups.getCallbackConfirmationCode', [$this->group_id]);
Curl::post($vk, [$this->confirmation_token]);
}
}

View File

@ -0,0 +1,10 @@
<?php
declare(strict_types=1);
namespace VK\API;
abstract class CallBackAbstract
{
abstract public function __construct(object $group, array $params = []);
}

View File

@ -76,11 +76,12 @@ class Group extends RobotAbstract
public function longpoll(...$params): LongPoll public function longpoll(...$params): LongPoll
{ {
return new LongPoll($this, $params); return new LongPoll($this, $params);
} }
public function callback() public function callback()
{ {
return new CallBack($this, $params);
} }
protected function genToken(): string protected function genToken(): string