repositório com os arquivos utilizados para integração entre o sistema SimplesIP e diversos sistemas.
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.
 
 

157 lines
4.1 KiB

<?php
include_once '/var/lib/asterisk/scripts/integracao/custom/funcoesCustom.php';
$scrpt = $argv[0];
/*
* Variaveis para o status da integração.
*/
$reg_retorno = $numero;
$reg_msg = '';
$reg_status_exec = '1';
$retorno_cliente = '';
$ura = 'REALCONSIG';
$debug = 1;
/*
* 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 {
debug(array($numero, $matricula), "Asterisk: ");
/*
* INICIA CONEXAO COM O BANCO DE DADOS
*/
$conexao = ConnectPG();
/*
* CONSULTA OS DADOS REFERENTES A CAMPANHA NO BANCO DE DADOS
*/
$idCrm = ConsultaListaDiscador($conexao, $numero, $matricula);
/*
* CONSULTA OS DADOS RECEBIDOS NA API
*/
$callDiscador = ChamadaDiscador($idCrm, $numero, $ramalAgente, $uid);
/*
* ENCERRA A CONEXAO PASSANDO COMO PARAMETRO A PROPRIA CONEXAO ABERTA!
*/
ConnectPG($conexao);
} catch (Exception $ex) {
/*
* APRESENTA OS ERROS NAS FUNCOES DO SCRIPT
*/
debug(array($ex->getMessage()), "Exception: ");
} finally {
/*
* GRAVA AS INFORMACOES NA TABELA DE LOG DE INTEGRACAO
*/
$resp = AtualizaIntegracao($uid, $reg_retorno, $ex->getMessage(), 'Er', $retorno_cliente);
if (!$resp) {
grava_dadosIntegra($reg_retorno);
}
}
function ChamadaDiscador($contIdentificador, $telefone, $ramalAgente, $uniqueid) {
try {
$url = "https://api.finaz.com.br/telephony-proxy/atendimentodiscador?"
. "pid={$contIdentificador['cont_identificador']}&num={$telefone}&cid={$uniqueid}&ramal={$ramalAgente}&empresaId=3013";
/*
* DEBUG DE ERRO
*/
debug(array($url), __FUNCTION__);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$content = trim(curl_exec($ch));
curl_close($ch);
$retorno = json_decode($content);
if (!$retorno) {
throw new Exception("Erro ao consultar a api - " . $retorno);
}
$info = array(
"url" => $url,
"result" => $retorno
);
/*
* DEBUG DE ERRO
*/
debug($info, __FUNCTION__);
return $info;
} catch (Exception $ex) {
$msg = $ex->getMessage();
return $msg;
}
}
function ConsultaListaDiscador($connect, $telCliente, $matricula) {
try {
$query = "SELECT b.cmp_id, a.cmp_descricao, a.list_nome, a.cont_identificador, a.cont_param1, c.nome
FROM pbx_campanha_operacao a
INNER JOIN pbx_campanha b ON a.cmp_id = b.cmp_id
INNER JOIN pbx_dacs c ON c.id = b.id_dac
WHERE c.nome = 'REALCONSIG'
AND a.conf_fone = '{$telCliente}'
AND cmpo_id = (SELECT MAX(cmpo_id) from pbx_campanha_operacao WHERE matricula = '{$matricula}')";
$resultado = pg_query($connect, $query);
$resLista = pg_fetch_assoc($resultado);
/*
* DEBUG DE ERRO
*/
debug($resLista, __FUNCTION__);
if (!$resultado) {
throw new Exception("Erro ao realizar a criação da tabela de listas!");
}
return $resLista;
} catch (Exception $ex) {
return $ex->getMessage();
}
}
function ConnectPG($connection = null) {
$dbPort = "5432";
$dbHost = "127.0.0.1";
$dbName = "pbx";
$dbUser = "contacte";
$dbPassword = "ctepgSQL";
if (!$connection) {
$str = "host='$dbHost' port='$dbPort' dbname='$dbName' user='$dbUser' password='$dbPassword'";
debug("Connexao OK", __FUNCTION__);
return pg_connect($str);
} else {
pg_close($connection);
debug("Connexao OFF", __FUNCTION__);
}
return null;
}
function debug($array, $method = __FUNCTION__) {
global $scrpt, $debug;
if ($debug == 1) {
__logStr("Chamadas " . __FILE__, $method . " : " . print_r($array, true), $scrpt, true);
}
}
?>