85 lines
3.0 KiB
PHP
85 lines
3.0 KiB
PHP
<?php
|
|
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;
|
|
/*foreach($arrQuery as $val_query){
|
|
$arrVal = explode('=',$val_query);
|
|
$result[$arrVal[0]] = trim($arrVal[1]);
|
|
}*/
|
|
//var_dump($result);
|
|
|
|
require_once($_SERVER['DOCUMENT_ROOT']."/config.php");
|
|
//var_dump($result['cmd']);
|
|
/*if($_SESSION['id'] == 11868){
|
|
$content = file_get_contents('data.txt');
|
|
$arrQuery = json_decode($content);
|
|
$result = $arrQuery;
|
|
var_dump($result);
|
|
}*/
|
|
|
|
if($result->cmd == 'event'){
|
|
|
|
|
|
//echo 'dsfsf';
|
|
if($result->type != 'INCOMING'){
|
|
//Проверка на наличее звонка
|
|
$pdopg = new MysqlPdo(hstpg, ndbpg, userpg, passpg, false, '5432', true);
|
|
$sql = "SELECT id FROM call_events WHERE uuid_call_id = '$result->callid'";
|
|
//echo $sql;
|
|
$q = $pdopg->query($sql);
|
|
if($pdopg->num_rows($q) == 0) die();
|
|
}
|
|
$data = array();
|
|
$data['operator'] = 'MEGAFON';
|
|
$data['operator_rus'] = 'Мегафон';
|
|
$data['operator_call_id'] = $result->callid;
|
|
$data['internal_number'] = '+'.$result->telnum;
|
|
$data['external_number'] = '+'.$result->phone;
|
|
$data['transit_number'] = '+'.$result->diversion;
|
|
if(isset($result->telnum)) {
|
|
$data['vpbx_id'] = '+'.$result->telnum;
|
|
} else if (isset($result->user)) {
|
|
//Поиск части vpbx_id
|
|
$data['vpbx_id'] = $result->user;
|
|
$sqlagency = "SELECT * FROM agency_megafon";
|
|
$qagency = mysql_query($sqlagency);
|
|
while($ragency = mysql_fetch_assoc($qagency)){
|
|
if(str_replace('-','', $ragency['api_key']) == $result->crm_token){
|
|
$url = $ragency['url'];
|
|
$arrUrl = parse_url($url);
|
|
$data['vpbx_id'] .= '@'.$arrUrl['host'];
|
|
|
|
break;
|
|
}
|
|
}
|
|
//$data['vpbx_id'] = $result->user;
|
|
}
|
|
|
|
$data['user'] = $result->user;
|
|
$data['uuid'] = $result->callid;
|
|
//$data['call_api_id'] = $result['CallAPIID'];
|
|
if (empty($data['external_number'])) die();
|
|
$data['status'] = 1;
|
|
if($result->type == 'COMPLETED' || $result->type == 'CANCELLED') $data['status'] = 0;
|
|
|
|
if (isset($result->type) && $result->type == 'INCOMING') $data['start_time'] = time();
|
|
else $data['start_time'] = 0;
|
|
if (isset($result->type) && $result->type == 'ACCEPTED') $data['answer_time'] = time();
|
|
else $data['answer_time'] = 0;
|
|
if (isset($result->type) && ($result->type == 'COMPLETED' || $result->type == 'CANCELLED')) $data['release_time'] = time();
|
|
else $data['release_time'] = 0;
|
|
if(isset($callDetail['xsi:redirect'])){
|
|
$data['redirect'] = $callDetail['xsi:redirect'];
|
|
} else {
|
|
$data['redirect'] = false;
|
|
}
|
|
|
|
|
|
$CallEvents = new CallEvents();
|
|
$CallEvents->process($data);
|
|
}
|