/
mikopbx
/
ModuleBeelinePbx
Обзор
Документация
Войти
/
mikopbx
/
ModuleBeelinePbx
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
master
Lib/RestAPI/EventController.php
67 строк
3 KB
boffart
Инициализация модуля ModuleBeelinePbx
08 июл 2026, 17:11
08 июл 2026, 17:11
1cc4e1a
Код
Авторство
О чём код?
<?php /* * MikoPBX - free phone system for small business * Copyright © 2017-2024 Alexey Portnov and Nikolay Beketov * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. * If not, see <https://www.gnu.org/licenses/>. */ namespace Modules\ModuleBeelinePbx\Lib\RestAPI; use MikoPBX\PBXCoreREST\Controllers\BaseController; use Modules\ModuleBeelinePbx\Lib\EventLogFormatter; use Modules\ModuleBeelinePbx\Lib\Logger; /** * Приёмник событий Облачной АТС Билайн (Xsi-Events push). * * ВРЕМЕННАЯ ЗАГЛУШКА: любой входящий запрос целиком пишется в лог * ({CORE_LOGS_DIR}/ModuleBeelinePbx/EventController.log) и получает ответ 200. * По накопленным дампам определяется реальный формат событий Билайн, после чего * здесь появится разбор состояний вызова и трансляция в 1С (как в ModuleMtsPbx/ModuleMegafonPbx). */ class EventController extends BaseController { /** * Принять входящее событие: залогировать целиком и вернуть 200. */ public function processEvent(): void { $logger = new Logger('EventController', 'ModuleBeelinePbx'); try { $headers = $this->request->getHeaders(); $query = $this->request->getQuery(); unset($query['_url']); $payload = EventLogFormatter::build( (string)$this->request->getMethod(), is_array($headers) ? $headers : [], is_array($query) ? $query : [], (string)$this->request->getRawBody(), (string)$this->request->getClientAddress() ); $logger->writeInfo($payload, 'Incoming Beeline event'); } catch (\Throwable $e) { // Здесь НЕЛЬЗЯ снова писать через модульный Logger — если упал он сам, повторная // попытка тоже бросит исключение, оно уйдёт из воркера и MikoPBX авто-отключит модуль. // Пишем в системный лог php (error_log не бросает). error_log('ModuleBeelinePbx EventController log failure: ' . $e->getMessage()); } // Всегда отвечаем 200, чтобы Билайн не помечал интеграцию как неработающую и не ретраил. $this->response->setStatusCode(200, 'OK'); $this->response->setContentType('application/json', 'UTF-8'); $this->response->setContent(json_encode(['result' => true])); $this->response->sendRaw(); } }