forked from Claudio/integracao
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.
266 lines
12 KiB
266 lines
12 KiB
<?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_BOLETO', $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çã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 { |
|
$emp = $agi->get_variable('EMP',true); |
|
$codBoleto = $agi->get_variable('CODBOLETO',true); |
|
$nomeCliente = $agi->get_variable('NOMECLI', true); |
|
//$emailCliente = $Agi->get_variable('EMAILCLI', true); |
|
|
|
$linkBoleto = RetornaLinkBoleto($codBoleto, $emp); |
|
|
|
if (substr($linkBoleto, 0, 4) == "Erro") { |
|
$agi->exec_goto(GetAnuncio('')); |
|
} else { |
|
__logStr("Envio de boletos", "Link do boleto: " . print_r($linkBoleto, true), $script, true); |
|
|
|
if ($emp == 'VMAIS') { |
|
$boleto = EnviaBoletoEmailVmais('desenvolvimento01@simplesip.com.br', $linkBoleto, $nomeCliente); |
|
if ($boleto == 'OK') { |
|
$agi->exec_goto(GetAnuncio('AGRADECIMENTO')); // Agradecimento |
|
} else { |
|
$agi->exec_goto(GetAnuncio('REDIR_VMAIS')); // Fila financeiro |
|
} |
|
} else { |
|
$boleto = EnviaBoletoEmailOptcom('desenvolvimento01@simplesip.com.br', $linkBoleto, $nomeCliente); |
|
if ($boleto == 'OK') { |
|
$agi->exec_goto(GetAnuncio('AGRADECIMENTO')); // Agradecimento |
|
} else { |
|
$agi->exec_goto(GetAnuncio('REDIR_OPTCOM')); // Fila financeiro |
|
} |
|
} |
|
} |
|
} catch (Exception $ex) { |
|
$reg_msg = $ex->getMessage(); |
|
$reg_status_exec = 'Er'; |
|
__logStr("Consulta de Cliente", $reg_msg . " Consulta de Cliente: $cpf", $script, true); |
|
} |
|
|
|
@AtualizaIntegracao($uid, $reg_retorno, $reg_msg, $reg_status_exec, $retorno_cliente); |
|
if (!$dadosIntegra){ |
|
@grava_dadosIntegra($reg_retorno); |
|
} |
|
|
|
function RetornaLinkBoleto($idBoleto, $emp) |
|
{ |
|
try { |
|
if ($emp == 'VMAIS') { |
|
$url = "https://srv.vmaisnet.com/routerbox/ws_json/ws_json.php"; |
|
$json = "{ |
|
\"get_banking_billet\": { |
|
\"document_id\": {$idBoleto} |
|
} |
|
}"; |
|
$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, $json); |
|
curl_setopt($ch, CURLOPT_HTTPHEADER, array( |
|
'Content-Type: text/xml; charset=utf-8', |
|
'Content-Length: ' . strlen($json), |
|
'authentication_key: YA2Y0ZAPF2G7TH60YURKTX6BXXKYDL' |
|
)); |
|
} else { |
|
$url = "https://srv.optcom.net.br/routerbox/ws_json/ws_json.php"; |
|
$json = "{ |
|
\"get_banking_billet\": { |
|
\"document_id\": {$idBoleto} |
|
} |
|
}"; |
|
$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, $json); |
|
curl_setopt($ch, CURLOPT_HTTPHEADER, array( |
|
'Content-Type: text/xml; charset=utf-8', |
|
'Content-Length: ' . strlen($json), |
|
'authentication_key: MOKCJEMITFNCK6GBRM92ORLOUWCG8B' |
|
)); |
|
} |
|
|
|
$result = curl_exec($ch); |
|
$response = objectToArray(json_decode($result)); |
|
|
|
if ($response['error_code'] != 0) { |
|
throw new Exception("Erro - ".$response['error_description']); |
|
} |
|
|
|
return $response['result']['banking_billet_link']; |
|
} catch (Exception $ex) { |
|
return $ex->getMessage(); |
|
} |
|
} |
|
|
|
function EnviaBoletoEmailVmais($emailCli, $linhaDigi, $nomeCli) |
|
{ |
|
|
|
try { |
|
|
|
if (empty($emailCli) || empty($linhaDigi) || empty($nomeCli)) { |
|
throw new Exception("ERRO - variaveis de entrada estao vazias!"); |
|
} |
|
|
|
$mail = new PHPMailer(true); // Passing `true` enables exceptions |
|
//Configurações do Servidor |
|
$mail->SMTPDebug = 0; // Enable verbose debug output |
|
$mail->isSMTP(); // Set mailer to use SMTP |
|
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers |
|
$mail->SMTPAuth = true; // Enable SMTP authentication |
|
$mail->Username = 'automatico@vmaisnet.com'; // SMTP username |
|
$mail->Password = 'Ki22br03@!'; // SMTP password |
|
$mail->SMTPSecure = 'ssl'; // Enable TLS encryption, `ssl` also accepted |
|
$mail->Port = 465; // TCP port to connect to |
|
//Remetente |
|
$mail->setFrom('automatico@vmaisnet.com', 'Financeiro V Mais Net'); |
|
//Recebedores |
|
$mail->addAddress($emailCli); |
|
//Conteudo |
|
$mail->isHTML(true); // Set email format to HTML |
|
$mail->Subject = 'Linha digitavel de fatura'; |
|
$mail->CharSet = 'ISO-8859-1'; |
|
$mail->AddEmbeddedImage(__DIR__ . '/login.png', 'imagem_login'); |
|
$mail->AddEmbeddedImage(__DIR__ . '/menu.png', 'imagem_menu'); |
|
$mail->AddEmbeddedImage(__DIR__ . '/logo.jpg', 'logo_vmaisnet'); |
|
$mail->Body = "Ola <b>{$nomeCli}</b><br/><br/>" |
|
. "<a href=\"{$linhaDigi}\">Clique aqui para baixar seu boleto</a><br/><br/>" |
|
. "Sabia que a V+ Net disponibiliza a central do assinante para a 2ª via de boletos online e outros serviços ?<br/><br/>" |
|
. "Siga as orientações abaixo: <br/>" |
|
. "<ul><li> Acesse nosso site <a href=\"https://srv.vmaisnet.com/\">Clicando aqui</a></li>" |
|
. "<li>Nos campos abaixo, utilize o CPF ou CNPJ do titular da conta, como login e senha. Feito isso, clique em \"Entrar\"</li>" |
|
. "<img src=\"cid:imagem_login\" alt=\"Imagem de login\" width=\"250\" heigth=\"158\"><br/>" |
|
. "<li>Acesse o menu localizado no canto superior esquerdo da tela.</li>" |
|
. "<li>Vá até a opção <b>\"Finanças\"</b> e depois em <b>\"Documentos em aberto\"</b></li>" |
|
. "<img src=\"cid:imagem_menu\" alt=\"Imagem do menu\"><br/>" |
|
. "<li>Clique em <b>\"Imprimir Boleto\"</b> no item desejado</li></ul>" |
|
. "Primeiro acesso a central do assinante ?<br/>" |
|
. "<ul><li>(Pessoa Física) Seu login e senha serão o CPF do titular da conta</li>" |
|
. "<li>(Pessoa Jurídica) Seu login e senha serão o CNPJ.</li></ul>" |
|
. "<h4>* Digite apenas os números de seu CPF ou CNPJ</h4>" |
|
. "<img src=\"cid:logo_vmaisnet\" alt=\"Logo V+ net\" width=\"180\" heigth=\"70\"><br/>" |
|
. "<h4>Este email é automático, caso haja necessidade, pedimos que entrem em contato pelo telefone <b>(48) 3626 - 4545</b></h4>"; |
|
|
|
$mail->send(); |
|
|
|
if ($mail->ErrorInfo) { |
|
throw new Exception($mail->ErrorInfo); |
|
} |
|
|
|
return 'OK'; |
|
} catch (Exception $ex) { |
|
return $ex->getMessage(); |
|
} |
|
} |
|
|
|
function EnviaBoletoEmailOptcom($emailCli, $linhaDigi, $nomeCli) |
|
{ |
|
|
|
try { |
|
|
|
if (empty($emailCli) || empty($linhaDigi) || empty($nomeCli)) { |
|
throw new Exception("ERRO - variaveis de entrada estao vazias!"); |
|
} |
|
|
|
$mail = new PHPMailer(true); // Passing `true` enables exceptions |
|
//Configurações do Servidor |
|
$mail->SMTPDebug = 0; // Enable verbose debug output |
|
$mail->isSMTP(); // Set mailer to use SMTP |
|
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers |
|
$mail->SMTPAuth = true; // Enable SMTP authentication |
|
$mail->Username = 'automatico@optcom.net.br'; // SMTP username |
|
$mail->Password = 'Ki22br03@!'; // SMTP password |
|
$mail->SMTPSecure = 'ssl'; // Enable TLS encryption, `ssl` also accepted |
|
$mail->Port = 465; // TCP port to connect to |
|
//Remetente |
|
$mail->setFrom('automatico@optcom.net.br', 'Financeiro Optcom'); |
|
//Recebedores |
|
$mail->addAddress($emailCli); |
|
//Conteudo |
|
$mail->isHTML(true); // Set email format to HTML |
|
$mail->Subject = 'Linha digitavel de fatura'; |
|
$mail->CharSet = 'ISO-8859-1'; |
|
$mail->AddEmbeddedImage(__DIR__ . '/login.png', 'imagem_login'); |
|
$mail->AddEmbeddedImage(__DIR__ . '/menu.png', 'imagem_menu'); |
|
$mail->AddEmbeddedImage(__DIR__ . '/logo.jpg', 'logo_vmaisnet'); // Modificar esta imagem. |
|
$mail->Body = "Ola <b>{$nomeCli}</b><br/><br/>" |
|
. "<a href=\"{$linhaDigi}\">Clique aqui para baixar seu boleto</a><br/><br/>" |
|
. "Sabia que a Optcom disponibiliza a central do assinante para a 2ª via de boletos online e outros serviços ?<br/><br/>" |
|
. "Siga as orientações abaixo: <br/>" |
|
. "<ul><li> Acesse nosso site <a href=\"https://srv.optcom.net.br/app_login/\">Clicando aqui</a></li>" |
|
. "<li>Nos campos abaixo, utilize o CPF ou CNPJ do titular da conta, como login e senha. Feito isso, clique em \"Entrar\"</li>" |
|
. "<img src=\"cid:imagem_login\" alt=\"Imagem de login\" width=\"250\" heigth=\"158\"><br/>" |
|
. "<li>Acesse o menu localizado no canto superior esquerdo da tela.</li>" |
|
. "<li>Vá até a opção <b>\"Finanças\"</b> e depois em <b>\"Documentos em aberto\"</b></li>" |
|
. "<img src=\"cid:imagem_menu\" alt=\"Imagem do menu\"><br/>" |
|
. "<li>Clique em <b>\"Imprimir Boleto\"</b> no item desejado</li></ul>" |
|
. "Primeiro acesso a central do assinante ?<br/>" |
|
. "<ul><li>(Pessoa Física) Seu login e senha serão o CPF do titular da conta</li>" |
|
. "<li>(Pessoa Jurídica) Seu login e senha serão o CNPJ.</li></ul>" |
|
. "<h4>* Digite apenas os números de seu CPF ou CNPJ</h4>" |
|
. "<img src=\"cid:logo_vmaisnet\" alt=\"Logo V+ net\" width=\"180\" heigth=\"70\"><br/>" |
|
. "<h4>Este email é automático, caso haja necessidade, pedimos que entrem em contato pelo telefone <b>(48) 3626 - 4545</b></h4>"; |
|
|
|
$mail->send(); |
|
|
|
if ($mail->ErrorInfo) { |
|
throw new Exception($mail->ErrorInfo); |
|
} |
|
|
|
return 'OK'; |
|
} catch (Exception $ex) { |
|
return $ex->getMessage(); |
|
} |
|
} |
|
|
|
function objectToArray($d) |
|
{ |
|
if (is_object($d)) { |
|
$d = get_object_vars($d); |
|
} |
|
if (is_array($d)) { |
|
return array_map(__FUNCTION__, $d); |
|
} else { |
|
return $d; |
|
} |
|
} |
|
|
|
?>
|