forked from SimplesIP/pabx-app
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.
202 lines
6.1 KiB
202 lines
6.1 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, 'CONSULTA_CLIENTE_FONE', $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çã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 { |
|
//$numero = '43988040566'; |
|
$cliente = GetTelefoneCliente($numero); |
|
__logStr("Consulta de Documento", $reg_msg . "Cliente: " . print_r($cliente, true), $scrpt, true); |
|
|
|
if ($cliente == 'Cliente Nao Encontrado' || empty($cliente)) { |
|
$agi->exec_goto(GetUra('URA_SELECIONA_ATENDIMENTO')); |
|
} else { |
|
$agi->set_variable('CODCLI', $cliente['codcli']); |
|
$agi->set_variable('NOMECLIENTE', $cliente['nome_cli']); |
|
$agi->set_variable('CELULAR', $cliente['celular']); |
|
$agi->set_variable('EMAIL', $cliente['email']); |
|
$agi->set_variable('DOCUMENTO', $cliente['documento']); |
|
$agi->set_variable('ENDERECO', $cliente['endereco']); |
|
$agi->set_variable('BAIRRO', $cliente['bairro']); |
|
$agi->set_variable('CIDADE', $cliente['cidade']); |
|
|
|
$agi->exec_goto(GetAnuncio('REDIR_VER_PENDENCIA')); |
|
} |
|
} catch (Exception $ex) { |
|
$reg_msg = $ex->getMessage(); |
|
$reg_status_exec = 'Er'; |
|
__logStr("Consulta de Documento", $reg_msg . "Codigo do cliente: " . $cliente['codcli'], $scrpt, true); |
|
} |
|
|
|
@AtualizaIntegracao($uid, $reg_retorno, $reg_msg, $reg_status_exec, $retorno_cliente); |
|
if (!$dadosIntegra) |
|
@grava_dadosIntegra($reg_retorno); |
|
|
|
function GetTelefoneCliente($param) { |
|
|
|
$telefone = InputMask($param); |
|
|
|
$url = 'http://168.90.59.2/server.php'; |
|
$_user = rawurlencode('ZAAP'); |
|
$_passwd = rawurlencode('SIMPLESIP'); |
|
$_consulta = '011G0NP05B'; |
|
$_formato_padrao = 'X'; |
|
$_fone = $telefone['telefone']; |
|
|
|
$xml = '<?xml version="1.0" encoding="iso-8859-1"?>' . "\n"; |
|
$xml .= "<methodCall>\n"; |
|
$xml .= "<methodName>view.execute</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="_consulta">' . "\n"; |
|
$xml .= "<value>\n"; |
|
$xml .= "<string><![CDATA[$_consulta]]></string>\n"; |
|
$xml .= "</value>\n"; |
|
$xml .= "</param>\n"; |
|
|
|
$xml .= '<param name="formato_padrao">' . "\n"; |
|
$xml .= "<value>\n"; |
|
$xml .= "<string><![CDATA[$_formato_padrao]]></string>\n"; |
|
$xml .= "</value>\n"; |
|
$xml .= "</param>\n"; |
|
|
|
$xml .= sprintf('<param name="%s">' . "\n", $telefone['type']); |
|
$xml .= "<value>\n"; |
|
$xml .= "<string><![CDATA[$_fone]]></string>\n"; |
|
$xml .= "</value>\n"; |
|
$xml .= "</param>\n"; |
|
|
|
$xml .= "</params>\n"; |
|
$xml .= "</methodCall>"; |
|
|
|
$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 (!empty($curlError)) { |
|
curl_close($ch); |
|
throw new Exception("HTTP error ocurred: $curlError"); |
|
} |
|
|
|
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
|
curl_close($ch); |
|
|
|
if ($httpCode != 200) { |
|
throw new Exception("HTTP error ocurred, number: $httpCode"); |
|
} |
|
|
|
if ($result == '') { |
|
throw new Exception("Void Response"); |
|
} |
|
|
|
$xml = simplexml_load_string($result); |
|
$arDados = objectToArray($xml->params->param[1]->value->DOMElement->result->row); |
|
$dados = !empty($arDados) ? $arDados = array_filter($arDados) : null; |
|
|
|
if ($dados['codcli'] == '2' || empty($dados)) { |
|
return 'Cliente Nao Encontrado'; |
|
} else { |
|
$explodeCel = explode(',', $dados['celular']); |
|
$explodeEmail = explode(',', $dados['email']); |
|
$arFinal = array("celular" => trim(soNumero($explodeCel[0])), "email" => trim($explodeEmail[0])); |
|
$arSpliced = array_slice($dados, 0, 9); |
|
$result = array_merge($arSpliced, $arFinal); |
|
|
|
return $result; |
|
} |
|
} |
|
|
|
function InputMask($telefone) { |
|
$retorno = array('telefone' => '', 'type' => ''); |
|
|
|
if (strlen($telefone) == 11) { |
|
$numero = substr($telefone, 2,10); |
|
$telefone = "(43)" . $numero; |
|
$retorno['telefone'] = $telefone; |
|
$retorno['type'] = 'celular'; |
|
} else if (strlen($telefone) == 12) { |
|
$ddd = substr($telefone, 1, 2); |
|
$numero = substr($telefone, 3, 10); |
|
$telefone = sprintf("(%s)%s", $ddd, $numero); |
|
$retorno['telefone'] = $telefone; |
|
$retorno['type'] = 'telefone'; |
|
} else if (strlen($telefone) == 13) { |
|
$ddd = substr($telefone,2,2); |
|
$numero = substr($telefone,4,10); |
|
$telefone = "(".$ddd.")" . $numero; |
|
$retorno['telefone'] = $telefone; |
|
$retorno['type'] = 'celular'; |
|
}else{ |
|
return null; |
|
} |
|
|
|
return $retorno; |
|
} |
|
|
|
function objectToArray($d) { |
|
if (is_object($d)) { |
|
$d = get_object_vars($d); |
|
} |
|
if (is_array($d)) { |
|
return array_map(__FUNCTION__, $d); |
|
} else { |
|
return $d; |
|
} |
|
} |