@@ -17,17 +17,16 @@ import 'models/contrato.dart';
1717class Sigepweb {
1818 ///
1919 /// Endpoint para caso de ambiente de testes
20- final _homEndpoint =
21- 'https://apphom.correios.com.br/SigepMasterJPA/AtendeClienteService/AtendeCliente?wsdl' ;
20+ final _homEndpoint = 'https://apphom.correios.com.br/SigepMasterJPA/AtendeClienteService/AtendeCliente?wsdl' ;
2221
2322 ///
2423 /// Endpoint para caso de ambiente de producao.
2524 ///
2625 /// Este endpoint será usado quando [isDebug] for falso e nesse caso é necessário
2726 /// informar o [contrato]
28- final _prodEndpoint =
29- 'https://apps.correios.com.br/SigepMasterJPA/AtendeClienteService/AtendeCliente?wsdl' ;
27+ final _prodEndpoint = 'https://apps.correios.com.br/SigepMasterJPA/AtendeClienteService/AtendeCliente?wsdl' ;
3028
29+ final bool useSSL;
3130 final bool isDebug;
3231 final dio = Dio ();
3332
@@ -42,10 +41,10 @@ class Sigepweb {
4241 Sigepweb ({
4342 this .contrato,
4443 this .isDebug = false ,
44+ this .useSSL = false ,
4545 }) {
4646 if (contrato == null && ! isDebug) {
47- throw SigepwebRuntimeError (
48- 'Obrigatório informar o contrato ou estar em modo debug' );
47+ throw SigepwebRuntimeError ('Obrigatório informar o contrato ou estar em modo debug' );
4948 }
5049
5150 if (isDebug) {
@@ -80,11 +79,13 @@ class Sigepweb {
8079 // do you know a better way to do that? Tell us...
8180 final isWeb = ! Platform .isAndroid && ! Platform .isIOS;
8281
82+ // Vai definir se a base do endpoint deverá usar HTTPS ou apenas HTTP
83+ final baseEndpoint = 'http${useSSL ? 's' : '' }://ws.correios.com.br/calculador/CalcPrecoPrazo.asmx' ;
84+
8385 //
8486 // O Endpoint para calculo de preco e prazo eh o unico diferente
8587 // (ate agora)
86- final endpoint =
87- '${isWeb ? "https://cors-anywhere.herokuapp.com/" : "" }http://ws.correios.com.br/calculador/CalcPrecoPrazo.asmx' ;
88+ final endpoint = '${isWeb ? "https://cors-anywhere.herokuapp.com/" : "" }$baseEndpoint ' ;
8889
8990 var result = < CalcPrecoPrazoItemModel > [];
9091
@@ -95,8 +96,7 @@ class Sigepweb {
9596
9697 // Efetiva a consulta
9798 var resp = await dio.get ('$endpoint /CalcPrecoPrazo' , queryParameters: {
98- 'nCdEmpresa' :
99- contrato.codAdmin.isEmpty ? '08082650' : contrato.codAdmin,
99+ 'nCdEmpresa' : contrato.codAdmin.isEmpty ? '08082650' : contrato.codAdmin,
100100 'sDsSenha' : contrato.senha.isEmpty ? '564321' : contrato.senha,
101101 'nCdServico' : servicosList.join (',' ),
102102 'sCepOrigem' : SgUtils .formataCEP (cepOrigem),
@@ -131,17 +131,14 @@ class Sigepweb {
131131 if (apiResult['cResultado' ] == null ||
132132 apiResult['cResultado' ]['Servicos' ] == null ||
133133 apiResult['cResultado' ]['Servicos' ]['cServico' ] == null ) {
134- throw SigepwebRuntimeError (
135- 'Xml result format isn\' t with expected format' );
134+ throw SigepwebRuntimeError ('Xml result format isn\' t with expected format' );
136135 }
137136
138137 // Guarda o retorno em uma variavel para facilitar
139138 var cServico = apiResult['cResultado' ]['Servicos' ]['cServico' ];
140139
141140 // Verifica se houve retorno com erro
142- if (cServico is Map &&
143- cServico['Erro' ] != null &&
144- cServico['Erro' ] != '0' ) {
141+ if (cServico is Map && cServico['Erro' ] != null && cServico['Erro' ] != '0' ) {
145142 throw SigepwebRuntimeError (cServico['MsgErro' ]);
146143 }
147144
@@ -216,8 +213,7 @@ class Sigepweb {
216213 xml2json.parse (response.body);
217214 Map <String , dynamic > apiResult = json.decode (xml2json.toGData ());
218215
219- var soapBodyEnvelope =
220- apiResult['soap\$ Envelope' ]['soap\$ Body' ]['ns2\$ consultaCEPResponse' ];
216+ var soapBodyEnvelope = apiResult['soap\$ Envelope' ]['soap\$ Body' ]['ns2\$ consultaCEPResponse' ];
221217
222218 if (soapBodyEnvelope['return' ] == null ) {
223219 return ConsultaCepModel ();
0 commit comments