D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
var
/
www
/
html
/
idoso_ant
/
Filename :
boleto.php
back
Copy
<?php require('../public_html/idoso/adm/vendor/phpmailer/phpmailer/class.phpmailer.php'); require('../public_html/idoso/adm/vendor/phpmailer/phpmailer/class.smtp.php'); $types = array( 'pdf', 'jpg', 'jpeg', 'gif' ); //$path = 'fatura'; $path = "/home/storage/5/b8/c3/cminformatica3/public_html/idoso/adm/fatura/"; $mail = new \PHPMailer; $mail->isSMTP(); $mail->Host = "smtplw.com.br"; $mail->SMTPAuth = true; $mail->Username = "cminformatica"; $mail->Password = "GpcFIHvd5727"; $mail->SMTPSecure = "tls"; $mail->Port =587; // $mail->Port = 465; $mail->isHTML(true); $mail->CharSet = "UTF-8"; $mail->SMTPDebug = 1; $mail->From = "carlos@cminformatica.com.br"; $mail->FromName = "carlos@cminformatica.com.br"; $mail->addAddress("crmarques@uol.com.br"); $mail->Subject = "Cadastro - "; $mail->Body = "teste"; /* * Exemplo de cria��o de um boleto utilizando o m�todo HTTP POST. e exibe o conte�do PDF retornado no navegador. * Ap�s obter o PDF do boleto o arquivo � enviado como resposta para visualiza��o no navegador. * * cURL - http://php.net/manual/pt_BR/book.curl.php **/ #Dados do boleto $fields = array( "boleto.conta.banco"=> "237", "boleto.conta.agencia"=> "1234-5", "boleto.conta.numero"=> "123456-0", "boleto.conta.carteira"=> "12", "boleto.beneficiario.nome"=> "DevAware Solutions", "boleto.beneficiario.cprf"=> "15.719.277/0001-46", "boleto.beneficiario.endereco.cep"=> "59020-000", "boleto.beneficiario.endereco.uf"=> "RN", "boleto.beneficiario.endereco.localidade"=> "Natal", "boleto.beneficiario.endereco.bairro"=> "Petr�polis", "boleto.beneficiario.endereco.logradouro"=> "Avenida Hermes da Fonseca", "boleto.beneficiario.endereco.numero"=> "384", "boleto.beneficiario.endereco.complemento"=> "Sala 2A, segundo andar", "boleto.emissao"=> "2014-07-11", "boleto.vencimento"=> "2020-05-30", "boleto.documento"=> "EX1", "boleto.numero"=> "11317210903-P", "boleto.titulo"=> "DM", "boleto.valor"=> "1250.43", "boleto.pagador.nome"=> "Alberto Santos Dumont", "boleto.pagador.cprf"=> "111.111.111-11", "boleto.pagador.endereco.cep"=> "36240-000", "boleto.pagador.endereco.uf"=> "MG", "boleto.pagador.endereco.localidade"=> "Santos Dumont", "boleto.pagador.endereco.bairro"=> "Casa Natal", "boleto.pagador.endereco.logradouro"=> "BR-499", "boleto.pagador.endereco.numero"=> "s/n", "boleto.pagador.endereco.complemento"=> "S�tio - Subindo a serra da Mantiqueira", "boleto.instrucao"=> array( "Atencao! N�O RECEBER ESTE BOLETO.", "Este � apenas um teste utilizando a API Boleto Cloud", "Mais info em http://www.boletocloud.com/app/dev/api" ) ); #Aplicando formato de formul�rio $fields_string = ""; foreach($fields as $key=>$value) { if(is_array($value)){ foreach($value as $v){ $fields_string .= urlencode($key)."=".urlencode($v)."&"; } }else{ $fields_string .= urlencode($key)."=".urlencode($value)."&"; } } $data = rtrim($fields_string, "&"); #Definindo conte�do da requisi��o e tipos de respostas aceitas #Pode responder com o boleto ou mensagem de erro $accept_header = "Accept: application/pdf, application/json"; #Estou enviando esse formato de dados $content_type_header = "Content-Type: application/x-www-form-urlencoded; charset=utf-8"; $headers = array($accept_header, $content_type_header); #Configura��es do envio $url = "https://sandbox.boletocloud.com/api/v1/boletos"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_USERPWD, "api-key_cZEvgjnZUV4Jg826FSwLpHJCWwwYjEmjn9Gk6a7SCGE=:token"); #API TOKEN curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);# Basic Authorization curl_setopt($ch, CURLOPT_HEADER, true);#Define que os headers estar�o na resposta curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); #Para uso com https curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); #Para uso com https #Envio $response = curl_exec($ch); #Principais meta-dados da resposta $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE); #Fechar processo de comunica��o curl_close($ch); #Processando a resposta $created = 201; #Constante que indica recurso criado (Boleto Criado) #Separando header e body na resposta $header = substr($response, 0, $header_size); $body = substr($response, $header_size); $header_array = explode("\r\n", $header); #Principais headers $boleto_cloud_version = ""; $boleto_cloud_token = ""; $location = ""; foreach($header_array as $h) { if(preg_match("/X-BoletoCloud-Version:/i", $h)) { $boleto_cloud_version = $h; } if(preg_match("/X-BoletoCloud-Token:/i", $h)) { $boleto_cloud_token = $h; } if(preg_match("/Location:/i", $h)) { $location = $h; } } #Processando sucesso ou falha $arquivo = "arquivo-api-boleto-post-teste.pdf"; if($http_code == $created){ #Vers�o da plataforma: $boleto_cloud_version #Token do boleto disponibilizado: $boleto_cloud_token #Localiza��o do boleto na plataforma: $location #Enviando boleto como resposta: header("Content-Description: File Transfer"); header("Content-type: application/pdf"); // header("Content-Disposition: inline; filename=arquivo-api-boleto-post-teste.pdf"); header("Content-Disposition: attachment; filename={$arquivo}"); // header("Content-Length: ".filesize($body)); //echo $body; #Visualiza��o no navegador readfile("/home/storage/5/b8/c3/cminformatica3/public_html/idoso/adm/fatura/".$arquivo); $mail->addAttachment("/home/storage/5/b8/c3/cminformatica3/public_html/idoso/adm/fatura/".$arquivo, "boleto" ); if($mail->send()){ echo "Enviado"; }else{ echo "Erro". $mail->ErrorInfo; } }else{ #Vers�o da plataforma: $boleto_cloud_version #C�dgio de erro HTTP: $http_code #Enviando erro como resposta: header("Content-Type: application/json; charset=utf-8"); echo $body; #Visualiza��o no navegador } /* * Para saber mais sobre tratamento de erros veja a se��o Status & Erros **/ ?>