-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
sharoff
committed
Dec 24, 2015
0 parents
commit e32e851
Showing
12 changed files
with
778 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"name": "sharoff/mango-office-api", | ||
"type": "library", | ||
"autoload": { | ||
"psr-4": { | ||
"Sharoff\\Mango\\Api\\": "src/Section/" | ||
} | ||
}, | ||
"description": "Библиотека для работы с API mango-office", | ||
"keywords": [], | ||
"homepage": "https://sharoff.org", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Сергей Кокшаров", | ||
"email": "info@sharoff.org" | ||
} | ||
], | ||
"require": { | ||
"php": ">=5.5.9", | ||
"symfony/http-foundation": "^3.0" | ||
}, | ||
"minimum-stability": "dev" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
#Библиотека для работы с API mango-office.ru | ||
|
||
##Установка | ||
~~~ | ||
composer require sharoff/mango-office-api | ||
~~~ | ||
|
||
##Инициализация | ||
Для простой и быстрой инициализации создан Helper который хранить в себе инстанс класса работающий с API. | ||
Для первоначальной инициализации скрипта необходимо задать API ключ и ключ шифрования. | ||
~~~ | ||
// Подключаем автолоад | ||
require __DIR__ . '/../vendor/autoload.php'; | ||
// Просто для короткой записи | ||
use Sharoff\Mango\Api\MangoHelper; | ||
// Задание API ключа и ключа шифрования | ||
MangoHelper::setApiKey('*********************************') | ||
->setApiSalt('*********************************'); | ||
~~~ | ||
Для удобства использования создан PHP DOC, который позволяет работать автозаполнению в IDE | ||
|
||
##Получение входящих данных | ||
Mango-office обращается к определенному URL адресу. Каждый адрес прописан в документации (http://www.mango-office.ru/upload/api/MangoOffice_VPBX_API_v1.3.pdf) | ||
Данная библиотека поможет проверить подпись от манго и если что-то пойдет не так, сделает ответ в формате json, нужным кодом и заголовком. | ||
Для получения данных достаточно после инициализации выполнить строчку: | ||
~~~ | ||
$data = MangoHelper::getMethodData(); | ||
~~~ | ||
В переменную $data придет json_decode полученных данных от манго. | ||
|
||
##Совершение звонка | ||
Для совершения звонка достаточно знать внутренний номер сотрудника и кому вы хотите совершить вызов: | ||
~~~ | ||
$data = MangoHelper::sendCall('10', '7912*******'); | ||
~~~ | ||
|
||
##Завершение звонка | ||
Для завершения звонка необходимо выполнить команду: | ||
~~~ | ||
MangoHelper::sendCallHangup($command_id, $call_id) | ||
~~~ | ||
Где $command_id и $call_id придут при совершении звонка | ||
|
||
##Получение статистики | ||
В результате выполнения команды будет массив, с объектами MangoOfficeStat, с помощью которого можно получить с автокомплитом нужные параметры | ||
Данные объекта будут в формате как и $fields | ||
~~~ | ||
$stats = MangoHelper::getStat($date_from, $date_to, $from = 0, $from_number = null, $to = null, $to_number = null, $fields = null, $request_id = null); | ||
foreach ($stats as $stat) { | ||
/** @var \Sharoff\Mango\Api\MangoOfficeStat $stat */ | ||
echo $stat->start->format('d.m.Y H:i:s') . PHP_EOL; | ||
} | ||
~~~ | ||
###Параметры по умолчанию $fields | ||
~~~ | ||
$fields = [ | ||
'records', | ||
'start', | ||
'finish', | ||
'from_extension', | ||
'from_number', | ||
'to_extension', | ||
'to_number', | ||
'disconnect_reason' | ||
]; | ||
~~~ | ||
###Возможные поля $fields и формат полей | ||
~~~ | ||
$available_fields = [ | ||
// Массив с идентификаторами записей | ||
'records' => 'array', | ||
// Будет в объекте Carbon | ||
'start' => 'timestamp', | ||
// Будет в объекте Carbon | ||
'finish' => 'timestamp', | ||
// строка | ||
'from_extension' => 'string', | ||
// строка | ||
'from_number' => 'string', | ||
// строка | ||
'to_extension' => 'string', | ||
// строка | ||
'to_number' => 'string', | ||
// строка | ||
'disconnect_reason' => 'string', | ||
// строка | ||
'entry_id' => 'string', | ||
]; | ||
~~~ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
namespace Sharoff\Mango\Api\Base; | ||
|
||
use Sharoff\Mango\Api\MangoOffice; | ||
|
||
/** | ||
* | ||
* Class MangoHelper | ||
* | ||
* @method static MangoOffice setApiKey($key) | ||
* @method static MangoOffice setApiSalt($salt) | ||
* @method static MangoOffice checkSalt($json, $salt) | ||
* @method static MangoOffice getMethodData() | ||
* @method static MangoOffice sendCall($from, $to_number, $number = null, $command_id = null) | ||
* @method static MangoOffice sendCallHangup($command_id, $call_id) | ||
* @method static MangoOffice getStat($date_from, $date_to, $from = 0, $from_number = null, $to = null, $to_number = null, $fields = null, $request_id = null) | ||
* | ||
* @package Sharoff\Mango\Api\Base | ||
*/ | ||
Class MangoHelper { | ||
|
||
/** | ||
* @var null|MangoOffice | ||
*/ | ||
static protected $instance = null; | ||
|
||
|
||
static protected function factory() { | ||
if (is_null(self::$instance)) { | ||
self::$instance = new MangoOffice(); | ||
} | ||
return self::$instance; | ||
} | ||
|
||
|
||
/** | ||
* | ||
* @param $method | ||
* @param $args | ||
* | ||
* @return MangoOffice | ||
* @throws \Exception | ||
*/ | ||
static function __callStatic($method, $args) { | ||
return call_user_func_array( | ||
[ | ||
self::factory(), | ||
$method | ||
], | ||
$args | ||
); | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.