|
|
|
|
<?php
|
|
|
|
|
require '/var/lib/asterisk/scripts/integracao/dbAbstract.php';
|
|
|
|
|
include '/var/lib/asterisk/scripts/integracao/custom/funcoesCustom.php';
|
|
|
|
|
include_once('funcoes/shared.php');
|
|
|
|
|
|
|
|
|
|
$scrpt = $argv[0];
|
|
|
|
|
$config = array('itgc_host', 'itgc_port', 'itgc_database', 'itgc_user', 'itgc_password');
|
|
|
|
|
$config = GetConfigIntegracao($connPG, 'abreChamado', $config);
|
|
|
|
|
|
|
|
|
|
$user = $config['itgc_user'];
|
|
|
|
|
$passWord = $config['itgc_password'];
|
|
|
|
|
$host = $config['itgc_host'];
|
|
|
|
|
$port = $config['itgc_port'];
|
|
|
|
|
$dataBase = $config['itgc_database'];
|
|
|
|
|
$tipoDb = DB__PGSQL;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* DIRETORIO DOS ARQUIVOS DE SOM.
|
|
|
|
|
*/
|
|
|
|
|
$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);
|
|
|
|
|
|
|
|
|
|
$codCli = $agi->get_variable('CODCLI',true);
|
|
|
|
|
$codSerCli = $agi->get_variable('CODSERCLI',true);
|
|
|
|
|
$codCar = $agi->get_variable('CODCAR',true);
|
|
|
|
|
$nome_ocop = $agi->get_variable('NOME_OCOP',true);
|
|
|
|
|
$cpf = $agi->get_variable('CPF_CNPJ',true);
|
|
|
|
|
$nomeCli = $agi->get_variable('NOME_CLIENTE',true);
|
|
|
|
|
|
|
|
|
|
$chamado = abreChamado($codCli, $codSerCli, $codCli, $codCar, 'ATENDIMENTO_URA', '');
|
|
|
|
|
__logStr("Abre Chamado", "Resultado: ". print_r($chamado,true),$script, true);
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
if ($chamado['numero_oco']){
|
|
|
|
|
GetProto($connPG, $uid, $chamado['numero_oco']);
|
|
|
|
|
|
|
|
|
|
$retorno_cliente = sprintf("%s|%s|%s|Nome:%s|Protocolo:%s|CPF_CNPJ:%s|Atendimento:%s",
|
|
|
|
|
$uid,$numero,'98',
|
|
|
|
|
str_replace("|", "", $nomeCli),
|
|
|
|
|
str_replace("|", "", $chamado['numero_oco']),
|
|
|
|
|
str_replace("|", "", $cpf),
|
|
|
|
|
str_replace("|", "", $nome_ocop));
|
|
|
|
|
|
|
|
|
|
$agi->exec_goto(GetFila('RELACIONAMENTO'));
|
|
|
|
|
}else{
|
|
|
|
|
$agi->exec_goto(GetFila('RELACIONAMENTO'));
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception $ex) {
|
|
|
|
|
$reg_msg = $ex->getMessage();
|
|
|
|
|
$reg_status_exec = 'Er';
|
|
|
|
|
__logStr("Abre Chamado", $reg_msg, $script, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@AtualizaIntegracao($uid, $reg_retorno, $reg_msg, $reg_status_exec, $retorno_cliente);
|
|
|
|
|
if (!$dadosIntegra)
|
|
|
|
|
@grava_dadosIntegra($reg_retorno);
|
|
|
|
|
|
|
|
|
|
function abreChamado($_codcli, $_codsercli, $_login, $_codcar, $_obs, $_chat) {
|
|
|
|
|
|
|
|
|
|
$url = 'http://177.74.128.21/server.php';
|
|
|
|
|
$_user = rawurlencode('254R0JIT4V');
|
|
|
|
|
$_passwd = rawurlencode('254R0JITNP');
|
|
|
|
|
|
|
|
|
|
$xml = '<?xml version="1.0" encoding="iso-8859-1"?>' . "\n";
|
|
|
|
|
$xml .= "<methodCall>\n";
|
|
|
|
|
$xml .= "<methodName>ati.criarAtendimento</methodName>\n";
|
|
|
|
|
$xml .= "<params>\n";
|
|
|
|
|
|
|
|
|
|
$xml .= '<param name="_user">' . "\n";
|
|
|
|
|
$xml .= "<value>\n";
|
|
|
|
|
$xml .= "<string><![CDATA[$_user]]></string>\n";
|
|
|
|
|
$xml .= "</value>\n";
|
|
|
|
|
$xml .= "</param>\n";
|
|
|
|
|
|
|
|
|
|
$xml .= '<param name="_passwd">' . "\n";
|
|
|
|
|
$xml .= "<value>\n";
|
|
|
|
|
$xml .= "<string><![CDATA[$_passwd]]></string>\n";
|
|
|
|
|
$xml .= "</value>\n";
|
|
|
|
|
$xml .= "</param>\n";
|
|
|
|
|
|
|
|
|
|
$xml .= '<param name="codcli">' . "\n";
|
|
|
|
|
$xml .= "<value>\n";
|
|
|
|
|
$xml .= "<string><![CDATA[$_codcli]]></string>\n";
|
|
|
|
|
$xml .= "</value>\n";
|
|
|
|
|
$xml .= "</param>\n";
|
|
|
|
|
|
|
|
|
|
$xml .= '<param name="codsercli">' . "\n";
|
|
|
|
|
$xml .= "<value>\n";
|
|
|
|
|
$xml .= "<string><![CDATA[$_codsercli]]></string>\n";
|
|
|
|
|
$xml .= "</value>\n";
|
|
|
|
|
$xml .= "</param>\n";
|
|
|
|
|
|
|
|
|
|
$xml .= '<param name="login">' . "\n";
|
|
|
|
|
$xml .= "<value>\n";
|
|
|
|
|
$xml .= "<string><![CDATA[$_login]]></string>\n";
|
|
|
|
|
$xml .= "</value>\n";
|
|
|
|
|
$xml .= "</param>\n";
|
|
|
|
|
|
|
|
|
|
$xml .= '<param name="codcar">' . "\n";
|
|
|
|
|
$xml .= "<value>\n";
|
|
|
|
|
$xml .= "<string><![CDATA[$_codcar]]></string>\n";
|
|
|
|
|
$xml .= "</value>\n";
|
|
|
|
|
$xml .= "</param>\n";
|
|
|
|
|
|
|
|
|
|
$xml .= '<param name="obs">' . "\n";
|
|
|
|
|
$xml .= "<value>\n";
|
|
|
|
|
$xml .= "<string><![CDATA[$_obs]]></string>\n";
|
|
|
|
|
$xml .= "</value>\n";
|
|
|
|
|
$xml .= "</param>\n";
|
|
|
|
|
|
|
|
|
|
$xml .= '<param name="chat">' . "\n";
|
|
|
|
|
$xml .= "<value>\n";
|
|
|
|
|
$xml .= "<string><![CDATA[$_chat]]></string>\n";
|
|
|
|
|
$xml .= "</value>\n";
|
|
|
|
|
$xml .= "</param>\n";
|
|
|
|
|
|
|
|
|
|
$xml .= "</params>\n";
|
|
|
|
|
$xml .= "</methodCall>";
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
$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, $xml);
|
|
|
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml; charset=utf-8', 'Content-Length: ' . strlen($xml)));
|
|
|
|
|
$result = curl_exec($ch);
|
|
|
|
|
|
|
|
|
|
$curlError = curl_error($ch);
|
|
|
|
|
if ($curlError == '') {
|
|
|
|
|
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
|
|
|
|
curl_close($ch);
|
|
|
|
|
if ($httpCode == 200) {
|
|
|
|
|
if ($result == '') {
|
|
|
|
|
throw new Exception("Retorno Vazio");
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
$xml = simplexml_load_string($result);
|
|
|
|
|
$return = array();
|
|
|
|
|
$return['numero_oco'] = (string) $xml->params->param[1]->value->string;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
throw new Exception("HTTP error ocurred, number: $httpCode");
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
curl_close($ch);
|
|
|
|
|
throw new Exception("HTTP error ocurred: $curlError");
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception $ex) {
|
|
|
|
|
|
|
|
|
|
$msg = $ex->getMessage();
|
|
|
|
|
return $msg;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
?>
|