|
|
|
|
<?php
|
|
|
|
|
require '/var/lib/asterisk/scripts/integracao/dbAbstract.php';
|
|
|
|
|
include '/var/lib/asterisk/scripts/integracao/custom/funcoesCustom.php';
|
|
|
|
|
|
|
|
|
|
$scrpt = $argv[0];
|
|
|
|
|
$config = array('itgc_host', 'itgc_port', 'itgc_database', 'itgc_user', 'itgc_password');
|
|
|
|
|
$config = GetConfigIntegracao($connPG, 'ABRE_PROTOCOLO_RBX_FORA', $config);
|
|
|
|
|
|
|
|
|
|
$user = $config['itgc_user'];
|
|
|
|
|
$passWord = $config['itgc_password'];
|
|
|
|
|
$host = $config['itgc_host'];
|
|
|
|
|
$port = $config['itgc_port'];
|
|
|
|
|
$dataBase = $config['itgc_database'];
|
|
|
|
|
$tipoDb = DB__PGSQL;
|
|
|
|
|
|
|
|
|
|
$pathSom = '/var/lib/asterisk/sounds/customizados/';
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Interage com o asterisk, por funcoes agi.
|
|
|
|
|
*/
|
|
|
|
|
$agi = GetAgi();
|
|
|
|
|
/*
|
|
|
|
|
* Variaveis para o status da integra<EFBFBD><EFBFBD>o.
|
|
|
|
|
*/
|
|
|
|
|
$reg_retorno = $numero;
|
|
|
|
|
$reg_msg = '';
|
|
|
|
|
$reg_status_exec = '1';
|
|
|
|
|
$retorno_cliente = '';
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Registra o inicio da integra<EFBFBD><EFBFBD>o. As variaveis passadas na fun<EFBFBD><EFBFBD>es s<EFBFBD>o iniciali-
|
|
|
|
|
* zadas em serverAgi.php.
|
|
|
|
|
*/
|
|
|
|
|
@RegistraIntegracao($idMetodo, $uid, $uidOld, $numero);
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
$opcUra = $agi->get_variable('URA',true);
|
|
|
|
|
$codCliente = $agi->get_variable('CODCLIENTE',true);
|
|
|
|
|
$cliente = abreProtocoloRBX($codCliente, $opcUra);
|
|
|
|
|
|
|
|
|
|
__logStr("Consulta de Cliente","Cliente: ". print_r($cliente,true), $script, true);
|
|
|
|
|
|
|
|
|
|
if ($cliente['status'] == 1) {
|
|
|
|
|
$agi->exec_goto(GetAnuncio('protocolo_sucesso'));
|
|
|
|
|
}else {
|
|
|
|
|
$agi->exec_goto(GetAnuncio('protocolo_falha'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} catch (Exception $ex) {
|
|
|
|
|
$reg_msg = $ex->getMessage();
|
|
|
|
|
$reg_status_exec = 'Er';
|
|
|
|
|
__logStr("Abre Protocolo Fora", $reg_msg . " ID do cliente: {$codCliente}", $script, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@AtualizaIntegracao($uid, $reg_retorno, $reg_msg, $reg_status_exec, $retorno_cliente);
|
|
|
|
|
if (!$dadosIntegra)
|
|
|
|
|
@grava_dadosIntegra($reg_retorno);
|
|
|
|
|
|
|
|
|
|
function abreProtocoloRBX($idCliente, $atendimento) {
|
|
|
|
|
|
|
|
|
|
$url = "https://central.openitgroup.com.br/routerbox/ws/rbx_server_json.php";
|
|
|
|
|
$dateTime = date('Y-m-d H:i:s');
|
|
|
|
|
$dataHora = explode(" ", $dateTime);
|
|
|
|
|
|
|
|
|
|
if ($atendimento == 3) {
|
|
|
|
|
//PROTOCOLO COMERCIAL
|
|
|
|
|
$assunto = 'Comercial';
|
|
|
|
|
$tipo = 'C';
|
|
|
|
|
$topico = '38';
|
|
|
|
|
} else if ($atendimento == 2) {
|
|
|
|
|
//PROTOCOLO FINANCEIRO
|
|
|
|
|
$assunto = 'Financeiro';
|
|
|
|
|
$tipo = 'A';
|
|
|
|
|
$topico = '40';
|
|
|
|
|
} else if ($atendimento == 1) {
|
|
|
|
|
//PROTOCOLO SUPORTE
|
|
|
|
|
$assunto = 'Suporte';
|
|
|
|
|
$tipo = 'T';
|
|
|
|
|
$topico = '39';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$json = "{
|
|
|
|
|
\"AtendimentoCadastro\": {
|
|
|
|
|
\"Autenticacao\": {
|
|
|
|
|
\"ChaveIntegracao\": \"MIZ78UZP7OZ4API5DK14Q0QYWBKFFN\"
|
|
|
|
|
},
|
|
|
|
|
\"DadosAtendimento\": {
|
|
|
|
|
\"Data_Abertura\": \"$dataHora[0]\",
|
|
|
|
|
\"Hora_Abertura\": \"$dataHora[1]\",
|
|
|
|
|
\"Iniciativa\": \"C\",
|
|
|
|
|
\"Modo\": \"A\",
|
|
|
|
|
\"TipoCliente\": \"C\",
|
|
|
|
|
\"Cliente\": \"$idCliente\",
|
|
|
|
|
\"Assunto\": \"$assunto\",
|
|
|
|
|
\"Tipo\":\"$tipo\",
|
|
|
|
|
\"Topico\":\"$topico\"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}";
|
|
|
|
|
|
|
|
|
|
$ch = curl_init();
|
|
|
|
|
curl_setopt($ch, CURLOPT_URL, $url);
|
|
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
|
|
|
|
curl_setopt($ch, CURLOPT_POST, 1);
|
|
|
|
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
|
|
|
|
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
|
|
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
|
|
|
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
|
|
|
|
|
'Content-Type: text/xml; charset=utf-8',
|
|
|
|
|
'Content-Length: ' . strlen($json)
|
|
|
|
|
));
|
|
|
|
|
$result = curl_exec($ch);
|
|
|
|
|
$retCliente = json_decode($result);
|
|
|
|
|
|
|
|
|
|
return objectToArray($retCliente);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function objectToArray($d) {
|
|
|
|
|
if (is_object($d)) {
|
|
|
|
|
$d = get_object_vars($d);
|
|
|
|
|
}
|
|
|
|
|
if (is_array($d)) {
|
|
|
|
|
return array_map(__FUNCTION__, $d);
|
|
|
|
|
} else {
|
|
|
|
|
return $d;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
?>
|