-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
175 lines (171 loc) · 6.1 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
<!DOCTYPE html>
<html lang="pt-BR">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Consulta de CNPJ</title>
<style>
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background-color: #f4f7f6;
margin: 0;
padding: 20px;
}
.container {
max-width: 800px;
margin: 0 auto;
padding: 20px;
background-color: #fff;
border-radius: 10px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}
.container h1 {
font-size: 24px;
color: #333;
text-align: center;
}
.form-group {
margin-bottom: 15px;
}
label {
display: block;
margin-bottom: 5px;
color: #555;
}
input[type="text"] {
width: 100%;
padding: 10px;
font-size: 16px;
border: 1px solid #ddd;
border-radius: 5px;
box-sizing: border-box;
}
button {
width: 100%;
padding: 12px;
font-size: 16px;
background-color: #28a745;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.3s;
}
button:hover {
background-color: #218838;
}
.card {
margin-top: 20px;
padding: 20px;
border-radius: 10px;
background-color: #f9f9f9;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
.card h2 {
margin-top: 0;
color: #333;
font-size: 22px;
}
.card p {
margin: 5px 0;
color: #555;
}
.card .highlight {
font-weight: bold;
color: #333;
}
.card ul {
list-style-type: none;
padding: 0;
}
.card ul li {
margin: 5px 0;
color: #555;
}
.error {
color: red;
font-weight: bold;
}
.footer {
text-align: center;
margin-top: 20px;
color: #888;
font-size: 12px;
}
.footer .highlight {
font-weight: bold;
color: #333;
}
</style>
</head>
<body>
<div class="container">
<h1>Consulta de CNPJ</h1>
<form id="cnpj-form">
<div class="form-group">
<label for="cnpj">Digite o CNPJ:</label>
<input type="text" id="cnpj" name="cnpj" required>
</div>
<button type="submit">Consultar</button>
</form>
<div id="company-data" class="card"></div>
</div>
<script>
document.getElementById('cnpj-form').addEventListener('submit', async function(event) {
event.preventDefault();
const cnpj = document.getElementById('cnpj').value.replace(/[^\d]+/g, '');
if (cnpj.length !== 14) {
alert('Por favor, insira um CNPJ válido com 14 dígitos.');
return;
}
await fetchCompanyData(cnpj);
});
async function fetchCompanyData(cnpj) {
try {
const proxyUrl = 'https://api.allorigins.win/raw?url=';
const apiUrl = `https://www.receitaws.com.br/v1/cnpj/${cnpj}`;
const response = await fetch(proxyUrl + encodeURIComponent(apiUrl));
if (!response.ok) {
throw new Error(`Erro na resposta da API: ${response.status} ${response.statusText}`);
}
const data = await response.json();
if (data.status === "ERROR") {
throw new Error(data.message || 'Erro desconhecido');
}
displayCompanyData(data);
} catch (error) {
console.error('Erro ao buscar dados:', error);
displayError(error.message);
}
}
function displayCompanyData(data) {
const companyDataDiv = document.getElementById('company-data');
companyDataDiv.innerHTML = `
<h2>${data.nome}</h2>
<p><span class="highlight">CNPJ:</span> ${data.cnpj}</p>
<p><span class="highlight">Abertura:</span> ${data.abertura}</p>
<p><span class="highlight">Situação:</span> ${data.situacao}</p>
<p><span class="highlight">Tipo:</span> ${data.tipo}</p>
<p><span class="highlight">Porte:</span> ${data.porte}</p>
<p><span class="highlight">Natureza Jurídica:</span> ${data.natureza_juridica}</p>
<p><span class="highlight">Atividade Principal:</span> ${data.atividade_principal[0].text} (${data.atividade_principal[0].code})</p>
<p><span class="highlight">Endereço:</span> ${data.logradouro}, ${data.numero} ${data.complemento}, ${data.bairro}, ${data.municipio} - ${data.uf}, CEP: ${data.cep}</p>
<p><span class="highlight">Telefone:</span> ${data.telefone}</p>
<p><span class="highlight">Última Atualização:</span> ${new Date(data.ultima_atualizacao).toLocaleString()}</p>
<h3>Quadro de Sócios e Administradores:</h3>
<ul>
${data.qsa.map(person => `<li>${person.nome} - ${person.qual}</li>`).join('')}
</ul>
`;
const footer = document.createElement('div');
footer.classList.add('footer');
footer.innerHTML = `<span class="highlight">Consulta realizada em:</span> ${new Date().toLocaleString()} - <span class="highlight">by zBLACKHAT</span>`;
companyDataDiv.appendChild(footer);
}
function displayError(message) {
const companyDataDiv = document.getElementById('company-data');
companyDataDiv.innerHTML = `<p class="error">Erro: ${message}</p>`;
}
</script>
</body>
</html>