Last active
April 5, 2021 19:24
-
-
Save adrianoxavier/7090181 to your computer and use it in GitHub Desktop.
Calculo de Frete, serviço dos correios
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var request = require('request'); | |
var xml2js = require('xml2js'); | |
/* | |
código do serviço. | |
40010 SEDEX | |
41106 PAC | |
http://www.correios.com.br/webServices/PDF/SCPP_manual_implementacao_calculo_remoto_de_precos_e_prazos.pdf | |
*/ | |
var params = { | |
'nCdEmpresa': '', | |
'sDsSenha': '', | |
'sCepOrigem': '74380150', | |
'sCepDestino': '43810040', | |
'nVlPeso': '5', | |
'nCdFormato': '1', | |
'nVlComprimento': '16', | |
'nVlAltura': '5', | |
'nVlLargura': '15', | |
'nVlDiametro': '0', | |
'sCdMaoPropria': 's', | |
'nVlValorDeclarado': '200', | |
'sCdAvisoRecebimento': 'n', | |
'StrRetorno': 'xml', | |
'nCdServico': '40010,41106' | |
}; | |
var url = 'http://ws.correios.com.br/calculador/CalcPrecoPrazo.aspx'; | |
var options = { | |
'uri': url, | |
'method': 'GET', | |
'qs': params | |
}; | |
request(options, function(error, response, body) { | |
if (error) { | |
return console.log('Erro ', error); | |
} | |
var parser = new xml2js.Parser({'async': true, 'attrkey': '@', 'explicitArray': false}); | |
parser.parseString(body, function (err, xml) { | |
if (err) { | |
return console.log('Erro ', err); | |
} | |
for (var i = 0; i < xml.Servicos.cServico.length; i++) { | |
var row = xml.Servicos.cServico[i]; | |
console.log(JSON.stringify(row, null, 2)); | |
}; | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment