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.
163 lines
6.8 KiB
163 lines
6.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, '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; |
|
|
|
/* |
|
* 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 { |
|
$opt = $agi->get_variable('URA',true); |
|
$nomeCliente = $agi->get_variable('NOMECLI',true); |
|
$valorFatura = $agi->get_variable('VALORFATURAS', true); |
|
$email = $agi->get_variable('EMAILCLI', true); |
|
$celular =$agi->get_variable('CELULARCLIENTE', true); |
|
$codBarra = mt_rand(1000000, 999999999); |
|
|
|
if($opt == 1){ |
|
$email = EnviaSegundaViaEmail($nomeCliente, $email, $valorFatura); |
|
|
|
if(substr($email, 0,2) == 'Ok'){ |
|
$agi->exec_goto(GetAnuncio('FATURA_ENVIADA')); |
|
}else{ |
|
$agi->exec_goto(GetAnuncio('REDIRECIONA_ATENDIMENTO')); |
|
} |
|
} |
|
|
|
if($opt == 2){ |
|
$sms = enviaSMS($celular, $nomeCliente, $codBarra, $valorFatura); |
|
} |
|
|
|
} catch (Exception $ex) { |
|
$reg_msg = $ex->getMessage(); |
|
$reg_status_exec = 'Er'; |
|
__logStr("Envia Segunda Via", $reg_msg , $scrpt, true); |
|
} |
|
|
|
@AtualizaIntegracao($uid, $reg_retorno, $reg_msg, $reg_status_exec, $retorno_cliente); |
|
if (!$dadosIntegra) |
|
@grava_dadosIntegra($reg_retorno); |
|
|
|
function EnviaSegundaViaEmail($nomeCliente, $destinatario, $valorFatura) |
|
{ |
|
$vencimento = date('d/m/Y'); |
|
if (empty($destinatario)) { |
|
throw new Exception("Erro - destinatário não pode estar vazio"); |
|
} |
|
|
|
try { |
|
$mail = new PHPMailer(true); // Passing `true` enables exceptions |
|
//Configurações do Servidor |
|
$mail->SMTPDebug = 2; // Enable verbose debug output |
|
$mail->isSMTP(); // Set mailer to use SMTP |
|
$mail->Host = 'mail.simplesip.com.br'; // Specify main and backup SMTP servers |
|
$mail->SMTPAuth = true; // Enable SMTP authentication |
|
$mail->Username = 'workflow@simplesip.com.br'; // SMTP username |
|
$mail->Password = '#w0rkFl0w@'; // SMTP password |
|
//$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted |
|
$mail->Port = 587; // TCP port to connect to |
|
//Remetente |
|
$mail->setFrom('desenvolvimento01@simplesip.com.br', 'Desenvolvimento01'); |
|
//Recebedores |
|
$mail->addAddress($destinatario, $nomeCliente); |
|
|
|
//Anexos |
|
$mail->addAttachment(); // Add attachments |
|
$mail->addAttachment("/var/lib/asterisk/scripts/workflow/logoPrincipal.jpg"); // Optional name |
|
//Conteudo |
|
$mail->isHTML(true); // Set email format to HTML |
|
$mail->Subject = '<b>NO-REPLY</b> Fatura por Email Simples IP'; |
|
$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 Simples IP</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$ {$valorFatura}</b><br /><br /> |
|
<a href=\"\">Clique aqui para visualizar sua conta</a><br /><br /> |
|
EVITE A REDUÇÃO DA VELOCIDADE CONTRATADA.<br /><br /> |
|
Caso seja necessário, entre em contato conosco pelo telefone: <b>(65)3616-8280</b></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;'> |
|
Simples IP</div> |
|
<div style='text-align: left;'> |
|
<a href=\"http://www.simplesip.com.br\">Visite nosso site.</div> |
|
<br /> |
|
<br /><div style='text-align: left;'> |
|
<br /></div> |
|
</div>"; |
|
|
|
$mail->send(); |
|
return "Ok - mensagem enviada com sucesso"; |
|
} catch (phpmailerException $e) { |
|
return $e->errorMessage(); |
|
} catch (Exception $ex) { |
|
return $ex->getMessage(); |
|
} |
|
} |
|
|
|
function enviaSMS($telefone, $nomeCliente, $codBarra, $valorFatura) { |
|
|
|
$numero = soNumero($telefone); |
|
|
|
$url = sprintf("http://179.188.2.57/integracao?method=EnviaSMS&TroncoSainte=TRONCO&" |
|
. "NumeroDestino=%s&Texto=%s&login=aplicativos&senha=1234&tipoRetorno=XML", |
|
$numero, urlencode($nomeCliente." Segue Codigo de barras para pagamento de sua fatura, " |
|
. "no valor de R$.".$valorFatura." Código: ". $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; |
|
} |
|
?>
|
|
|