Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
apmanager.php
1<?php
3
5
7{
8 public static function receive($userId, $connectionString)
9 {
10 if(static::checkState())
11 {
12 $connection = static::parseConnectionString($connectionString);
13
14 if($connection)
15 {
16 $uri = new Uri($connection['endpoint']);
17
18 if($uri->getHost())
19 {
20 $dbRes = ApTable::getList(array(
21 'filter' => array(
22 '=USER_ID' => $userId,
23 '=DOMAIN' => $uri->getHost()
24 ),
25 'select' => array('ID')
26 ));
27 $existingEntry = $dbRes->fetch();
28 if($existingEntry)
29 {
30 $result = ApTable::update($existingEntry['ID'], array(
31 'ENDPOINT' => $uri->getLocator(),
32 'LAST_AUTHORIZE' => '',
33 ));
34 }
35 else
36 {
37 $result = ApTable::add(array(
38 'USER_ID' => $userId,
39 'DOMAIN' => $uri->getHost(),
40 'ENDPOINT' => $uri->getLocator(),
41 ));
42 }
43
44 return $result->isSuccess();
45 }
46 }
47 }
48
49 return false;
50 }
51
52 protected static function checkState()
53 {
54 return \CSocServAuthManager::checkUniqueKey();
55 }
56
57 protected static function parseConnectionString($connectionString)
58 {
59 $client = \CBitrix24NetPortalTransport::init();
60 if($client)
61 {
62 $result = $client->call('client.authorize', array('apcode' => $connectionString));
63
64 if($result && $result['result'])
65 {
66 return array(
67 'endpoint' => $result['result']['ENDPOINT'],
68 );
69 }
70 }
71
72 return false;
73 }
74}
static parseConnectionString($connectionString)
Definition apmanager.php:57
static receive($userId, $connectionString)
Definition apmanager.php:8