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çõ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 = "

 Atendimento AmigaLink

Prezado(a), {$nomeCliente}

Estamos encaminhando o titulo com vencimento em {$vencimento} no valor de R$ {$valorConta}

Clique aqui para visualizar sua conta

EVITE A REDUÇÃO DA VELOCIDADE CONTRATADA.

Caso seja necessário, entre em contato conosco pelo telefone: (27)3030-9201 - 99919-4996
<<<<< Nao Responda esse email >>>>>

Atenciosamente,
AmigaLink
Visite nosso site.



"; $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; } }