forked from SimplesIP/pabx-pesquisa
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
130 lines
3.8 KiB
130 lines
3.8 KiB
<?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ção. |
|
*/ |
|
$reg_retorno = $numero; |
|
$reg_msg = ''; |
|
$reg_status_exec = '1'; |
|
$retorno_cliente = ''; |
|
|
|
/* |
|
* Registra o inicio da integração. As variaveis passadas na funções sã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; |
|
} |
|
} |
|
|
|
?>
|