Обновил лонгполл, мелкие исправления
This commit is contained in:
parent
9d38d69445
commit
b3571bcecf
|
@ -27,8 +27,7 @@
|
|||
"psr/log": "1.*",
|
||||
"monolog/monolog": ">=1.6",
|
||||
"jasny/error-handler": "^0.2.0",
|
||||
"vlucas/phpdotenv": "5.*",
|
||||
"guzzlehttp/guzzle": "^7.0"
|
||||
"vlucas/phpdotenv": "5.*"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpdocumentor/phpdocumentor": ">=2.9",
|
||||
|
|
|
@ -6,24 +6,74 @@ namespace VK\API;
|
|||
|
||||
class LongPoll extends LongPollAbstract
|
||||
{
|
||||
/**
|
||||
* Объект взаимодействия лонгпола
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
private $robot;
|
||||
|
||||
/**
|
||||
* Тип объекта: пользователь или группа
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $auth_type;
|
||||
|
||||
/**
|
||||
* Ключ сессии
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $key;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $user_id;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $group_id;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $ts;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $server;
|
||||
|
||||
public function __construct(object $robot, array $params = [])
|
||||
{
|
||||
return;
|
||||
echo get_class($robot), PHP_EOL;
|
||||
die;
|
||||
$this->robot = $robot;
|
||||
if ($_ENV['ROBOT_TYPE']) {
|
||||
$this->vk->auth_type = 'user';
|
||||
$this->user_id = $data['id'];
|
||||
$this->robot->auth_type = 'user';
|
||||
$this->user_id = $this->robot->request('users.get', [])['id'];
|
||||
} else {
|
||||
$this->vk->auth_type = 'group';
|
||||
$this->group_id = $this->vk->request('groups.getById', [])[0]['id'];
|
||||
$this->vk->request('groups.setLongPollSettings', [
|
||||
$this->robot->auth_type = 'group';
|
||||
$this->group_id = $this->robot->request('groups.getById', [])['id'];
|
||||
$this->robot->request('groups.setLongPollSettings', [
|
||||
'group_id' => $this->group_id,
|
||||
'enabled' => 1,
|
||||
'api_version' => $this->vk->version,
|
||||
'api_version' => $this->robot->version,
|
||||
'message_new' => 1,
|
||||
]);
|
||||
}
|
||||
$this->getLongPollServer();
|
||||
}
|
||||
|
||||
public function getLongPollServer()
|
||||
{
|
||||
if ($this->robot->auth_type == 'user') {
|
||||
$data = $this->robot->request('messages.getLongPollServer', ['need_pts' => 1, 'lp_version' => 3]);
|
||||
} else {
|
||||
$data = $this->robot->request('groups.getLongPollServer', ['group_id' => $this->group_id]);
|
||||
}
|
||||
unset($this->key, $this->server, $this->ts);
|
||||
list($this->key, $this->server, $this->ts) = [$data['key'], $data['server'], $data['ts']];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,4 +7,5 @@ namespace VK\API;
|
|||
abstract class LongPollAbstract
|
||||
{
|
||||
abstract public function __construct(object $robot, array $params = []);
|
||||
abstract public function getRobotInfo();
|
||||
}
|
|
@ -34,14 +34,10 @@ class User extends RobotAbstract
|
|||
*/
|
||||
public function auth(string $token, float $version)
|
||||
{
|
||||
if ($token instanceof auth) {
|
||||
if ($token instanceof auth) {
|
||||
$this->auth = $token;
|
||||
$this->version = $version;
|
||||
$this->token = $this->auth->getAccessToken();
|
||||
} else if (isset($also_version)) {
|
||||
$this->auth = new Auth($token, $version);
|
||||
$this->token = $this->auth->getAccessToken();
|
||||
$this->version = $also_version;
|
||||
} else {
|
||||
$this->token = $token;
|
||||
$this->version = $version;
|
||||
|
|
Loading…
Reference in New Issue