- Модуль: im
- Путь к файлу: ~/bitrix/modules/im/lib/bot/token.php
- Класс: BitrixImBotToken
- Вызов: Token::get
static function get($botId, $dialogId, $prolong = false)
{
if ($botId == $dialogId)
return false;
$result = self::getFromCache($botId);
$date = new BitrixMainTypeDateTime();
if (!($result[$dialogId] ?? null) || $result[$dialogId]['DATE_EXPIRE'] < $date->getTimestamp())
{
$cache = BitrixMainDataCache::createInstance();
$cache->clean('token_'.$botId, self::CACHE_TOKEN_PATH);
$orm = BitrixImModelBotTokenTable::add(Array(
'DATE_EXPIRE' => $date->add('10 MINUTES'),
'BOT_ID' => $botId,
'DIALOG_ID' => $dialogId
));
if ($orm->getId() <= 0)
{
return false;
}
$addResult = $orm->getData();
$result[$dialogId] = Array(
'ID' => $orm->getId(),
'TOKEN' => '',
'DIALOG_ID' => $addResult['DIALOG_ID'],
'DATE_EXPIRE' => $addResult['DATE_EXPIRE']->getTimestamp()
);
}
else if ($prolong)
{
$date = new BitrixMainTypeDateTime();
$orm = BitrixImModelBotTokenTable::update($result[$dialogId]['ID'], Array(
'DATE_EXPIRE' => $date->add('10 MINUTES')
));
if ($orm->isSuccess())
{
$addResult = $orm->getData();
$result[$dialogId]['DATE_EXPIRE'] = $addResult['DATE_EXPIRE']->getTimestamp();
$cache = BitrixMainDataCache::createInstance();
$cache->initCache(self::CACHE_TOKEN_TTL, 'token_'.$botId, self::CACHE_TOKEN_PATH);
$cache->startDataCache();
$cache->endDataCache($result);
}
}
return $result[$dialogId];
}