83 lines
3.4 KiB
PHP
83 lines
3.4 KiB
PHP
<?php
|
|
$time_start = microtime(true);
|
|
header('Content-Type: application/json');
|
|
ini_set('display_errors',1);
|
|
error_reporting(E_ALL & ~E_DEPRECATED & ~E_STRICT & ~E_NOTICE);
|
|
//$content = file_get_contents('data.txt');
|
|
|
|
$arrQuery = json_decode($content);
|
|
$result = $arrQuery;
|
|
require_once($_SERVER['DOCUMENT_ROOT']."/config.php");
|
|
/*var_dump($_SESSION['id']);
|
|
if($_SESSION['id'] == 5238){
|
|
$content = file_get_contents('data.txt');
|
|
$arrQuery = json_decode($content);
|
|
$result = $arrQuery;
|
|
var_dump($result);
|
|
}*/
|
|
|
|
//var_dump($result);
|
|
|
|
//require_once($_SERVER['DOCUMENT_ROOT']."/config.php");
|
|
//Проверка подключенности агенства
|
|
if(isset($result->json) && !empty($result->json)){
|
|
$api_key = $result->vpbx_api_key;
|
|
$mango = new MangoApiClass($api_key, '');
|
|
if($agency_id = $mango->validate_agency_apikey()){
|
|
$data['operator'] = 'MANGO';
|
|
$data['operator_rus'] = 'Mango';
|
|
$data['agency_id'] = $agency_id;
|
|
if(isset($result->json)){
|
|
$json = json_decode($result->json);
|
|
|
|
if(isset($json->call_state)){
|
|
|
|
$data['operator_call_id'] = $json->call_id;
|
|
$data['uuid'] = $json->entry_id;
|
|
if(isset($json->to->extension)){
|
|
$data['internal_number'] = $mango->ver_phone($json->to->line_number);
|
|
$data['external_number'] = $mango->ver_phone($json->from->number);
|
|
$data['transit_number'] = $mango->ver_phone($json->to->line_number);
|
|
$data['vpbx_id'] = str_replace("sip:", "", $json->to->number);
|
|
} else if ($json->call_state == 'Disconnected'){
|
|
$pdopg = new MysqlPdo(hstpg, ndbpg, userpg, passpg, false, '5432', true);
|
|
$sql = "SELECT * FROM call_events WHERE operator_call_id = '{$json->call_id}'";
|
|
$q = $pdopg->query($sql);
|
|
$call = $pdopg->fetch_assoc($q);
|
|
if(isset($call['id'])){
|
|
$data['internal_number'] = $call['internal_number'];
|
|
$data['external_number'] = $call['external_number'];
|
|
$data['vpbx_id'] = str_replace("sip:", "", $json->to->number);
|
|
}
|
|
}
|
|
|
|
if (empty($data['external_number']) || empty($data['internal_number'])) die();
|
|
$data['status'] = 0;
|
|
if($json->call_state == 'Appeared' || $json->call_state == 'Connected' || $json->call_state == 'OnHold'){
|
|
$data['status'] = 1;
|
|
}
|
|
|
|
if($json->call_state == 'Appeared') $data['start_time'] = $json->timestamp;
|
|
else $data['start_time'] = 0;
|
|
if ($json->call_state == 'Connected' || $json->call_state == 'OnHold') $data['answer_time'] = $json->timestamp;
|
|
else $data['answer_time'] = 0;
|
|
if ($json->call_state == 'Disconnected') $data['release_time'] = $json->timestamp;
|
|
else $data['release_time'] = 0;
|
|
|
|
$data['redirect'] = false;
|
|
|
|
if($json->seq > 1) sleep(2);
|
|
$CallEvents = new CallEvents();
|
|
$CallEvents->process($data);
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
$time_end = microtime(true);
|
|
$execution_time = $time_end - $time_start;
|
|
|
|
echo 'Total Execution Time: ' . $execution_time . ' seconds';
|
|
|