Skip to content

Commit a011248

Browse files
committed
Initial commit
0 parents  commit a011248

File tree

88 files changed

+3555
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+3555
-0
lines changed

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Auto detect text files and perform LF normalization
2+
* text=auto

README.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Exemplos de uso
2+
A ideia desses exemplos é otimizar o tempo de código dos usuários auxiliando na integração com a plataforma.
3+
4+
## Canais de discussão
5+
[![WhatsApp Group](https://img.shields.io/badge/WhatsApp-Group-25D366?logo=whatsapp)](https://chat.whatsapp.com/EeAWALQb6Ga5oeTbG7DD2k)
6+
[![Telegram Group](https://img.shields.io/badge/Telegram-Group-32AFED?logo=telegram)](https://t.me/apigratisoficial)
7+
8+
# Obter as credenciais
9+
https://apibrasil.com.br
10+
11+
# Pacote Composer PHP
12+
```composer require jhowbhz/apigratis-sdk-php```
13+
14+
# Pacote Npm JS
15+
```npm i apigratis-sdk-nodejs --save```
16+
17+
# Pacote Pip Python
18+
```pip install apigratis-sdk-python```
19+
20+
Nós temos uma novidade para você desenvolvedor Python! 👨‍💻 Nós temos uma nova [SDK](https://pypi.org/project/api-brasil/) cheia de novas funcionalidades, recursos e um pouco mais fácil de usar para facilitar a sua vida.
21+
No futuro, queremos depreciar essa versão atual "apigratis-sdk-python" e substituir por essa que acaba de sair do forno, acesse o [repo oficial](https://github.com/ivanildobarauna-dev/apibrasil-py) e saiba mais sobre como instalar e usufruir do que desenvolvemos. Caso você já queira usar a nova versão, você já pode com o seguinte comando:
22+
23+
```bash
24+
pip install api-brasil
25+
```
26+
27+
Aproveite!
28+
29+
# Pacote Nuget C# and others
30+
```dotnet add package ApiBrasil --version 1.2.1```
31+
32+
https://package.apibrasil.com.br
33+
34+
# Exemplo Veículos
35+
- Exemplo de como utilizar a API Placa DADOS
36+
-
37+
Acessar exemplo:
38+
39+
https://github.com/APIBrasil/apigratis-exemplos/tree/main/veiculos
40+
41+
<img src="https://i.imgur.com/BEITa4B.png" alt="Placa Dados"/>
42+
43+
# Exemplo de CPF
44+
- Essa consulta exige cadastro prévio para utilização
45+
46+
Acessar exemplo:
47+
48+
https://github.com/APIBrasil/apigratis-exemplos/tree/main/cpf
49+
50+
<img src="https://github.com/user-attachments/assets/bcaad5a1-e15b-4f79-a070-ed0ba1be7861" />
51+
52+
# Exemplo de CNPJ
53+
- Exemplo de como utilizar a API CNPJ
54+
55+
Acessar exemplo:
56+
57+
https://github.com/APIBrasil/apigratis-exemplos/tree/main/cnpj
58+
59+
<img src="https://i.imgur.com/YCZRJsh.png" alt="CNPJ"/>

clima/ClimaExample.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

cnpj/cnpj.html

Lines changed: 216 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,216 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1">
6+
7+
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
8+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/select2@4.0.13/dist/css/select2.min.css" />
9+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/select2-bootstrap-5-theme@1.3.0/dist/select2-bootstrap-5-theme.min.css" />
10+
<title>Hello, world!</title>
11+
</head>
12+
<body>
13+
14+
<div class="container">
15+
16+
<div class="row">
17+
18+
<div class="col-12 text-center">
19+
<h1 class="mt-2 mb-4">Consulta CNPJ</h1>
20+
</div>
21+
22+
<div class="col-7">
23+
<label for="cnae">Buscar por CNAE</label>
24+
<select name="cnae" id="cnae" class="form-control" serachable="true">
25+
<option> Selecione </option>
26+
</select>
27+
</div>
28+
29+
<!-- by cep-->
30+
<div class="col-3">
31+
<label for="cep">Buscar por CEP</label>
32+
<input type="text" name="cep" id="cep" class="form-control">
33+
</div>
34+
35+
<div class="col-2">
36+
<label for="quantidade">Quantidade CNPJs</label>
37+
<input type="number" name="quantidade" id="quantidade" class="form-control" value="25">
38+
</div>
39+
</div>
40+
41+
<hr class="my-4">
42+
43+
<div class="">
44+
45+
<button onclick="exportTableToCSV('cnpjs.csv')" class="btn btn-primary mt-2 mb-2">Exportar CSV</button>
46+
47+
<table class="table">
48+
<thead>
49+
<tr>
50+
<th scope="col">CNPJ</th>
51+
<th scope="col">Capital Social</th>
52+
<th scope="col">Razao Social</th>
53+
<th scope="col">Bairro</th>
54+
<th scope="col">Cidade</th>
55+
<th scope="col">E-mail</th>
56+
<th scope="col">Telefone 1</th>
57+
<th scope="col">Telefone 2</th>
58+
</tr>
59+
</thead>
60+
</table>
61+
62+
</div>
63+
64+
</div>
65+
</div>
66+
67+
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
68+
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
69+
<script src="https://cdn.jsdelivr.net/npm/select2@4.0.13/dist/js/select2.full.min.js"></script>
70+
71+
<script>
72+
73+
let credenciais = {
74+
"Content-Type": "application/json",
75+
"DeviceToken": "SUAS_CREDENCIAIS_AQUI",
76+
"Authorization": "Bearer SUAS_CREDENCIAIS_AQUI"
77+
};
78+
79+
let settings = {
80+
"url": "https://cluster.apigratis.com/api/v2/dados/lista-cnaes",
81+
"method": "POST",
82+
"headers": credenciais,
83+
"data": JSON.stringify({
84+
"quantidade": "1300"
85+
}),
86+
};
87+
88+
function exportTableToCSV(filename) {
89+
let csv = [];
90+
let rows = document.querySelectorAll("table tr");
91+
92+
for (var i = 0; i < rows.length; i++) {
93+
let row = [], cols = rows[i].querySelectorAll("td, th");
94+
95+
for (var j = 0; j < cols.length; j++){
96+
row.push(cols[j].innerText);
97+
csv.push(row.join(","));
98+
}
99+
}
100+
downloadCSV(csv.join("\n"), filename);
101+
}
102+
103+
function downloadCSV(csv, filename) {
104+
let csvFile;
105+
let downloadLink;
106+
107+
csvFile = new Blob([csv], {type: "text/csv"});
108+
downloadLink = document.createElement("a");
109+
downloadLink.download = filename;
110+
downloadLink.href = window.URL.createObjectURL(csvFile);
111+
downloadLink.style.display = "none";
112+
document.body.appendChild(downloadLink);
113+
downloadLink.click();
114+
}
115+
116+
$(document).ready(function(){
117+
118+
$( '#cnae' ).select2( {
119+
theme: 'bootstrap-5'
120+
});
121+
122+
$.ajax(settings).done(function (response) {
123+
let cnaes = response?.response?.cnae || [];
124+
cnaes.forEach(cnae => {
125+
$('#cnae').append(`<option value="${cnae.codigo}">${cnae.codigo} - ${cnae.descricao}</option>`);
126+
});
127+
});
128+
129+
$('#cnae').on('change', function(){
130+
131+
let cnae = $(this).val();
132+
let quantidade = $('#quantidade').val();
133+
134+
settings.url = "https://cluster.apigratis.com/api/v2/dados/cnae";
135+
136+
settings.data = JSON.stringify({
137+
"cnae": cnae,
138+
"quantidade": quantidade
139+
});
140+
141+
$.ajax(settings).done(function (response) {
142+
143+
let cnae = response?.response?.cnae || [];
144+
145+
if(cnae.length > 1){
146+
$('table tbody').remove();
147+
}
148+
149+
cnae.forEach(cnae => {
150+
$('table').append(`
151+
<tbody>
152+
<tr>
153+
<td>${cnae?.cnpj ?? ''}</td>
154+
<td>${cnae?.capital_social ? parseInt(cnae.capital_social).toLocaleString('pt-BR', { style: 'currency', currency: 'BRL' }) : ''}</td>
155+
<td>${cnae?.razao_social ?? ''}</td>
156+
<td>${cnae?.bairro ?? ''}</td>
157+
<td>${cnae?.municipio_descricao ?? ''}</td>
158+
<td>${cnae?.correio_eletronico ?? ''}</td>
159+
<td><a href="https://wa.me/55${cnae?.ddd1}${cnae.telefone1}">${cnae?.ddd1}${cnae.telefone1}</a></td>
160+
<td><a href="https://wa.me/55${cnae?.ddd2}${cnae.telefone2}">${cnae?.ddd2}${cnae.telefone2}</a></td>
161+
</tr>
162+
</tbody>
163+
`);
164+
});
165+
166+
});
167+
168+
});
169+
170+
$('#cep').on('focusout', function(){
171+
172+
let cep = $(this).val();
173+
let cnae = $('#cnae').val();
174+
let quantidade = $('#quantidade').val();
175+
176+
settings.url = "https://cluster.apigratis.com/api/v2/dados/cep";
177+
178+
settings.data = JSON.stringify({
179+
"cep": cep,
180+
"quantidade": quantidade,
181+
"cnae": cnae
182+
});
183+
184+
$.ajax(settings).done(function (response) {
185+
186+
let cpnjs = response?.response?.cep || [];
187+
188+
if(cpnjs.length > 1){
189+
$('table tbody').remove();
190+
}
191+
192+
cpnjs.forEach(cnae => {
193+
$('table').append(`
194+
<tbody>
195+
<tr>
196+
<td>${cnae?.cnpj ?? ''}</td>
197+
<td>${cnae?.capital_social ? parseInt(cnae.capital_social).toLocaleString('pt-BR', { style: 'currency', currency: 'BRL' }) : ''}</td>
198+
<td>${cnae?.razao_social ?? ''}</td>
199+
<td>${cnae?.bairro ?? ''}</td>
200+
<td>${cnae?.municipio_descricao ?? ''}</td>
201+
<td>${cnae?.correio_eletronico ?? ''}</td>
202+
<td><a href="https://wa.me/55${cnae?.ddd1}${cnae.telefone1}">${cnae?.ddd1}${cnae.telefone1}</a></td>
203+
<td><a href="https://wa.me/55${cnae?.ddd2}${cnae.telefone2}">${cnae?.ddd2}${cnae.telefone2}</a></td>
204+
</tr>
205+
</tbody>
206+
`);
207+
});
208+
209+
});
210+
});
211+
212+
});
213+
214+
</script>
215+
</body>
216+
</html>

correios/CorreiosRastreio.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
$curl = curl_init();
4+
5+
curl_setopt_array($curl, array(
6+
CURLOPT_URL => 'https://cluster.apigratis.com/api/v2/dados/cnpj',
7+
CURLOPT_RETURNTRANSFER => true,
8+
CURLOPT_ENCODING => '',
9+
CURLOPT_MAXREDIRS => 10,
10+
CURLOPT_TIMEOUT => 0,
11+
CURLOPT_FOLLOWLOCATION => true,
12+
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
13+
CURLOPT_CUSTOMREQUEST => 'POST',
14+
CURLOPT_POSTFIELDS =>'{
15+
"cnpj": "44.959.669/0001-80"
16+
}',
17+
CURLOPT_HTTPHEADER => array(
18+
'Content-Type: application/json',
19+
'DeviceToken: 5f443ea7-2683-4730...',
20+
'Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9....'
21+
),
22+
));
23+
24+
$response = curl_exec($curl);
25+
26+
curl_close($curl);
27+
echo $response;

0 commit comments

Comments
 (0)