|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
require '/var/lib/asterisk/scripts/integracao/dbAbstract.php';
|
|
|
|
|
include '/var/lib/asterisk/scripts/integracao/custom/funcoesCustom.php';
|
|
|
|
|
require ("phpmailer/class.phpmailer.php");
|
|
|
|
|
|
|
|
|
|
$scrpt = $argv[0];
|
|
|
|
|
$config = array('itgc_host', 'itgc_port', 'itgc_database', 'itgc_user', 'itgc_password');
|
|
|
|
|
$config = GetConfigIntegracao($connPG, 'ENVIA_SEGUNDA_VIA', $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 {
|
|
|
|
|
$opcao = $agi->get_variable('URA', true);
|
|
|
|
|
$codCli = $agi->get_variable('CODCLI', true);
|
|
|
|
|
$nomeCliente = $agi->get_variable('NOMECLIENTE', true);
|
|
|
|
|
$email = $agi->get_variable('EMAIL', true);
|
|
|
|
|
$celular = $agi->get_variable('CELULAR', true);
|
|
|
|
|
$codFatUltima = $agi->get_variable('ULTIMAFATURA', true);
|
|
|
|
|
$codFatPenultima = $agi->get_variable('PENULTIMAFATURA', true);
|
|
|
|
|
$vencPenultima = $agi->get_variable('VENCPENULTIMA', true);
|
|
|
|
|
$vencUltima = $agi->get_variable('VENCULTIMA', true);
|
|
|
|
|
$nomeFantasia = $agi->get_variable('NOMEFANTASIA', true);
|
|
|
|
|
$valorUltima = $agi->get_variable('VALORULTIMA',true);
|
|
|
|
|
$valorPenultima = $agi->get_variable('VALORPENULTIMA',true);
|
|
|
|
|
|
|
|
|
|
$identCliente = !empty($nomeFantasia) ? $nomeFantasia : $nomeCliente;
|
|
|
|
|
|
|
|
|
|
$arDados = array("opcao" => $opcao,
|
|
|
|
|
"CodCli" => $codCli,
|
|
|
|
|
"nomeCliente" => $nomeCliente,
|
|
|
|
|
"nomeFantasia" => $nomeFantasia);
|
|
|
|
|
|
|
|
|
|
$destino = $arDados['opcao'] == 1 ? $email : $celular;
|
|
|
|
|
|
|
|
|
|
if (!empty($codFatUltima)) {
|
|
|
|
|
$arEnvio[] = array_merge($arDados, array("destino" => $destino,
|
|
|
|
|
"vencimento" => $vencUltima,
|
|
|
|
|
"emissao" => RetornaFatura($opcao, $codFatUltima),
|
|
|
|
|
"valor_fatura" => $valorUltima));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!empty($codFatPenultima)) {
|
|
|
|
|
$arEnvio[] = array_merge($arDados, array("destino" => $destino,
|
|
|
|
|
"vencimento" => $vencPenultima,
|
|
|
|
|
"emissao" => RetornaFatura($opcao, $codFatPenultima),
|
|
|
|
|
"valor_fatura" => $valorPenultima));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach ($arEnvio as $dados) {
|
|
|
|
|
$retEnvio = enviaMensagem($dados['opcao'],
|
|
|
|
|
$dados['destino'],
|
|
|
|
|
$dados['nomeCliente'],
|
|
|
|
|
$dados['emissao'],
|
|
|
|
|
$dados['valor_fatura'] ,
|
|
|
|
|
$dados['vencimento']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (substr(0, 4, $retEnvio) == 'ERRO') {
|
|
|
|
|
$agi->exec_goto(GetUra('ENVIO_FATURA_ERRO'));
|
|
|
|
|
} else {
|
|
|
|
|
$agi->exec_goto(GetUra('FATURA_ENVIADA'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} catch (Exception $ex) {
|
|
|
|
|
$reg_msg = $ex->getMessage();
|
|
|
|
|
$agi->exec_goto(GetUra('ENVIO_FATURA_ERRO'));
|
|
|
|
|
$reg_status_exec = 'Er';
|
|
|
|
|
__logStr("Envia Boleto ", $reg_msg . " Codigo do cliente: $codCli", $script, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@AtualizaIntegracao($uid, $reg_retorno, $reg_msg, $reg_status_exec, $retorno_cliente);
|
|
|
|
|
if (!$dadosIntegra) {
|
|
|
|
|
@grava_dadosIntegra($reg_retorno);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function retornaLinhaDigitavel($codFat) {
|
|
|
|
|
|
|
|
|
|
if (empty($codFat)) {
|
|
|
|
|
return "ERRO - Linha digitavel nao inserida!";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
$json = sprintf('{
|
|
|
|
|
"request":{
|
|
|
|
|
"sendRequest": "integrator.server",
|
|
|
|
|
"method": "execute",
|
|
|
|
|
"submethod": "datasource.linhaDigitavel",
|
|
|
|
|
"params": {
|
|
|
|
|
"_user":"AMIGALINK",
|
|
|
|
|
"_passwd":"SIMPLESIP",
|
|
|
|
|
"codfat": "%s"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}', $codFat);
|
|
|
|
|
|
|
|
|
|
$curl = curl_init();
|
|
|
|
|
curl_setopt_array($curl, array(
|
|
|
|
|
CURLOPT_URL => "http://45.236.204.25/integrator.server.php",
|
|
|
|
|
CURLOPT_RETURNTRANSFER => true,
|
|
|
|
|
CURLOPT_ENCODING => "",
|
|
|
|
|
CURLOPT_MAXREDIRS => 10,
|
|
|
|
|
CURLOPT_TIMEOUT => 30,
|
|
|
|
|
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
|
|
|
|
|
CURLOPT_CUSTOMREQUEST => "POST",
|
|
|
|
|
CURLOPT_POSTFIELDS => $json,
|
|
|
|
|
CURLOPT_HTTPHEADER => array(
|
|
|
|
|
"Cache-Control: no-cache",
|
|
|
|
|
"Content-Type: application/json"
|
|
|
|
|
),
|
|
|
|
|
));
|
|
|
|
|
$response = curl_exec($curl);
|
|
|
|
|
$err = curl_error($curl);
|
|
|
|
|
curl_close($curl);
|
|
|
|
|
|
|
|
|
|
if ($err) {
|
|
|
|
|
throw new Exception("cURL Error #:" . $err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$linhaDigitavel = json_decode($response);
|
|
|
|
|
foreach ($linhaDigitavel as $value) {
|
|
|
|
|
$linhaDigitavel = objectToArray($value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach ($linhaDigitavel as $valor) {
|
|
|
|
|
$retLinha = $valor;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $retLinha[0]['codigo_barras'];
|
|
|
|
|
} catch (Exception $ex) {
|
|
|
|
|
return $ex->getMessage();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function retornaBoleto($codFat) {
|
|
|
|
|
|
|
|
|
|
if (empty($codFat)) {
|
|
|
|
|
return "ERRO - Codigo da fatura nao informado!";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
$json = sprintf('{
|
|
|
|
|
"request":{
|
|
|
|
|
"sendRequest": "integrator.server",
|
|
|
|
|
"method": "execute",
|
|
|
|
|
"submethod": "datasource.verBoleto",
|
|
|
|
|
"params": {
|
|
|
|
|
"_user":"AMIGALINK",
|
|
|
|
|
"_passwd":"SIMPLESIP",
|
|
|
|
|
"codfat": "%s"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}', $codFat);
|
|
|
|
|
|
|
|
|
|
$curl = curl_init();
|
|
|
|
|
curl_setopt_array($curl, array(
|
|
|
|
|
CURLOPT_URL => "http://45.236.204.25/integrator.server.php",
|
|
|
|
|
CURLOPT_RETURNTRANSFER => true,
|
|
|
|
|
CURLOPT_ENCODING => "",
|
|
|
|
|
CURLOPT_MAXREDIRS => 10,
|
|
|
|
|
CURLOPT_TIMEOUT => 30,
|
|
|
|
|
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
|
|
|
|
|
CURLOPT_CUSTOMREQUEST => "POST",
|
|
|
|
|
CURLOPT_POSTFIELDS => $json,
|
|
|
|
|
CURLOPT_HTTPHEADER => array(
|
|
|
|
|
"Cache-Control: no-cache",
|
|
|
|
|
"Content-Type: application/json"
|
|
|
|
|
),
|
|
|
|
|
));
|
|
|
|
|
$response = curl_exec($curl);
|
|
|
|
|
$err = curl_error($curl);
|
|
|
|
|
curl_close($curl);
|
|
|
|
|
|
|
|
|
|
if ($err) {
|
|
|
|
|
throw new Exception("cURL Error #:" . $err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$boleto = json_decode($response);
|
|
|
|
|
foreach ($boleto as $value) {
|
|
|
|
|
$boleto = objectToArray($value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach ($boleto as $valor) {
|
|
|
|
|
$returnLink = $valor;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $returnLink[0]['linkBoleto'];
|
|
|
|
|
} catch (Exception $ex) {
|
|
|
|
|
return $ex->getMessage();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function enviaEmail($email, $conta, $nomeCliente, $vencimento, $valorConta) {
|
|
|
|
|
|
|
|
|
|
$mail = new PHPMailer(true);
|
|
|
|
|
try {
|
|
|
|
|
//Configura<EFBFBD><EFBFBD>es do Servidor
|
|
|
|
|
$mail->SMTPDebug = 0; // Enable verbose debug output
|
|
|
|
|
$mail->isSMTP(); // Set mailer to use SMTP
|
|
|
|
|
$mail->Host = 'smtp.amigalink.com.br'; // Specify main and backup SMTP servers
|
|
|
|
|
$mail->SMTPAuth = true; // Enable SMTP authentication
|
|
|
|
|
$mail->Username = 'no-reply@amigalink.com.br'; // SMTP username
|
|
|
|
|
$mail->Password = 'amiga@link'; // SMTP password
|
|
|
|
|
//$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
|
|
|
|
|
$mail->Port = 587; // TCP port to connect to
|
|
|
|
|
//Remetente
|
|
|
|
|
$mail->setFrom('no-reply@amigalink.com.br', 'No-Reply AmigaLink');
|
|
|
|
|
//Recebedores
|
|
|
|
|
//$mail->addAddress($email);
|
|
|
|
|
$mail->addAddress('desenvolvimento01@simplesip.com.br');
|
|
|
|
|
|
|
|
|
|
//Conteudo
|
|
|
|
|
$mail->isHTML(true); // Set email format to HTML
|
|
|
|
|
$mail->Subject = '(NO-REPLY) Segunda Via de Boleto AmigaLink';
|
|
|
|
|
$mail->CharSet = 'ISO-8859-1';
|
|
|
|
|
$mail->Body = "<div class='separator' style='clear: both; text-align: left;'>
|
|
|
|
|
<div class='separator' style='clear: both; text-align: left;'>
|
|
|
|
|
<br /></div>
|
|
|
|
|
<div class='separator' style='clear: both; text-align: center;'>
|
|
|
|
|
<span style='font-size: large;'><b> Atendimento AmigaLink</b></span></div>
|
|
|
|
|
<div class='separator' style='clear: both; text-align: left;'>
|
|
|
|
|
<br /></div>
|
|
|
|
|
<div class='separator' style='clear: both; text-align: left;'>
|
|
|
|
|
Prezado(a), <span style='background-color: white; color: #222222; display: inline; float: none; font-family: sans-serif; font-size: 14px; font-style: normal; font-weight: 400; letter-spacing: normal; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;'><b>{$nomeCliente}</b></div>
|
|
|
|
|
<br />
|
|
|
|
|
Estamos encaminhando o titulo com vencimento em <b>{$vencimento}</b> no valor de <b>R$ {$valorConta}</b><br /><br />
|
|
|
|
|
<a href=\"http://45.236.204.25/{$conta}\">Clique aqui para visualizar sua conta</a><br /><br />
|
|
|
|
|
EVITE A REDU<EFBFBD><EFBFBD>O DA VELOCIDADE CONTRATADA.<br /><br />
|
|
|
|
|
Caso seja necess<EFBFBD>rio, entre em contato conosco pelo telefone: <b>(27)3030-9201</b> - <b>99919-4996</b>
|
|
|
|
|
<br />
|
|
|
|
|
<div style='text-align: left;'>
|
|
|
|
|
<b><<<<< Nao Responda esse email >>>>></b></div>
|
|
|
|
|
<div style='text-align: left;'>
|
|
|
|
|
<br /></div>
|
|
|
|
|
<div style='text-align: left;'>
|
|
|
|
|
Atenciosamente,</div>
|
|
|
|
|
<div style='text-align: left;'>
|
|
|
|
|
AmigaLink</div>
|
|
|
|
|
<div style='text-align: left;'>
|
|
|
|
|
<a href=\"http://www.amigalink.com.br\">Visite nosso site.</div>
|
|
|
|
|
<br />
|
|
|
|
|
<br /><div style='text-align: left;'>
|
|
|
|
|
<br /></div>
|
|
|
|
|
</div>";
|
|
|
|
|
|
|
|
|
|
$mail->send();
|
|
|
|
|
$return = "OK - Email enviado com sucesso.";
|
|
|
|
|
} catch (Exception $e) {
|
|
|
|
|
$msg = $mail->ErrorInfo;
|
|
|
|
|
return $msg;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* AJUSTAR A API DE ENVIO DE SMS
|
|
|
|
|
*/
|
|
|
|
|
function enviaSMS($telefone, $nomeCliente, $codBarra) {
|
|
|
|
|
|
|
|
|
|
$telefone = 0;
|
|
|
|
|
//$numero = soNumero($telefone);
|
|
|
|
|
$numero = '65999797353';
|
|
|
|
|
|
|
|
|
|
$url = sprintf("http://10.254.254.49/integracao?method=EnviaSMS&TroncoSainte=b0c0-9&"
|
|
|
|
|
. "NumeroDestino=%s&Texto=%s&login=aplicativos&senha=1234&tipoRetorno=XML",
|
|
|
|
|
$numero, urlencode($nomeCliente . " Segue Codigo de barras para pagamento de sua fatura." . $codBarra));
|
|
|
|
|
|
|
|
|
|
$xml = simplexml_load_string(file_get_contents($url));
|
|
|
|
|
$result = array();
|
|
|
|
|
$result['result'] = strval($xml->result);
|
|
|
|
|
$result['status'] = strval($xml->status);
|
|
|
|
|
$result['message'] = 'OK - ' . strval($xml->message);
|
|
|
|
|
$result['SIPID'] = strval($xml->SIPID);
|
|
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function EnviaMensagem($opcao, $destino, $nomeCliente, $emissao, $valorFatura ,$dataFatura = null) {
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
if ($opcao == 1) {
|
|
|
|
|
$envio = enviaEmail($destino, $emissao, $nomeCliente, $dataFatura, $valorFatura);
|
|
|
|
|
} else {
|
|
|
|
|
$envio = enviaSMS($destino, $nomeCliente, $emissao);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (substr($envio, 0, 2) != 'OK' || empty($envio)) {
|
|
|
|
|
throw new Exception("ERRO - Nao foi possivel enviar a mensagem!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $envio;
|
|
|
|
|
} catch (Exception $ex) {
|
|
|
|
|
return $ex->getMessage();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function RetornaFatura($opcao, $codFatura) {
|
|
|
|
|
return $opcao == 1 ? retornaBoleto($codFatura) : retornaLinhaDigitavel($codFatura);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function objectToArray($d) {
|
|
|
|
|
if (is_object($d)) {
|
|
|
|
|
$d = get_object_vars($d);
|
|
|
|
|
}
|
|
|
|
|
if (is_array($d)) {
|
|
|
|
|
return array_map(__FUNCTION__, $d);
|
|
|
|
|
} else {
|
|
|
|
|
return $d;
|
|
|
|
|
}
|
|
|
|
|
}
|