Skip to content

Commit

Permalink
- Corrigido: #5, #6, #7 e #8.
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuel-Oliveira committed Oct 17, 2016
1 parent 5a071c1 commit 1809c8c
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 12 deletions.
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
Projeto Para implementação do Java-Nfe Utilizando JAXB.

Para Iniciar :
- Baixe o java-nfe-3.10.2.jar (https://github.com/Samuel-Oliveira/Java_NFe/raw/master/java-nfe-3.10.2.jar) e o adicione às bibliotecas de Seu Projeto.
- Baixe o java-nfe-3.10.3.jar (https://github.com/Samuel-Oliveira/Java_NFe/raw/master/java-nfe-3.10.3.jar) e o adicione às bibliotecas de Seu Projeto.
- Baixe o Schemas.rar (https://github.com/Samuel-Oliveira/Java_NFe/raw/master/Schemas.rar) e extraia na sua Máquina.

- Maven :
```
<repository>
<name>Repositorio Autocom SnapShot</name>
<id>Snapshot</id>
Expand All @@ -14,15 +15,23 @@ Para Iniciar :
<dependency>
<groupId>br.com.samuelweb</groupId>
<artifactId>java-nfe</artifactId>
<version>3.10.2</version>
<version>3.10.3</version>
</dependency>
```

Veja a Wiki https://github.com/Samuel-Oliveira/Java_NFe/wiki, para ter um Tutorial Completo.

________________________________________________________________________________________________

# Historico de Versões

## v3.10.3 - 17-10-2016
- Issues: #5, #6, #7 e #8.
- Corrigido erro especifico da Sefaz de PE, referente ao cabeçalho SOAP.
- Corrigido erro de QrCode Vazio.
- Corrigido erro que acontece ao tentar Manifestar a Nfe, sem fazer a validação.
- Adicionado função que remove Acentos no XML antes de assinar a Nota.

## v3.10.2 - 07-10-2016
- Adicionado Compatibilidade com NFC-e
- Adicionado Método de geração de qrCode : NFCeUtil.getCodeQRCode
Expand Down
Binary file renamed java-nfe-3.10.2.jar → java-nfe-3.10.3.jar
Binary file not shown.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
<dependency>
<groupId>br.com.autocom</groupId>
<artifactId>nfe-wsdl</artifactId>
<version>3.10</version>
<version>3.10a</version>
</dependency>

<!-- XSD Nfe -->
Expand Down Expand Up @@ -86,5 +86,5 @@
</plugin>
</plugins>
</build>
<version>3.10.2</version>
<version>3.10.3</version>
</project>
2 changes: 2 additions & 0 deletions src/main/java/br/com/samuelweb/nfe/Assinar.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@

import br.com.samuelweb.nfe.exception.NfeException;
import br.com.samuelweb.nfe.util.CertificadoUtil;
import br.com.samuelweb.nfe.util.XmlUtil;

/**
* Classe Responsavel Por Assinar O Xml.
Expand Down Expand Up @@ -83,6 +84,7 @@ public static String assinaNfe(String stringXml ,String tipo) throws NfeExceptio

configuracoesNfe = ConfiguracoesIniciaisNfe.getInstance();

stringXml = XmlUtil.removeAcentos(stringXml);
stringXml = assinaDocNFe(stringXml , tipo);

return stringXml;
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/br/com/samuelweb/nfe/Enviar.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ public static TRetEnviNFe enviaNfe(TEnviNFe enviNFe) throws NfeException {
}

String xml = XmlUtil.objectToXml(enviNFe);

if (enviNFe.getNFe().get(0).getInfNFe().getIde().getMod().equals("65")) {
enviNFe.getNFe().get(0).getInfNFeSupl().setQrCode(qrCode);
}

xml = xml.replaceAll("ns2:", "");
xml = xml.replaceAll("<Signature>", "<Signature xmlns=\"http://www.w3.org/2000/09/xmldsig#\">");

Expand Down
4 changes: 4 additions & 0 deletions src/main/java/br/com/samuelweb/nfe/Evento.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ private static String evento(String xml, String tipo , boolean valida) throws Nf
if(!ObjetoUtil.isEmpty(erros)){
throw new NfeException("Erro Na Validação do Xml: "+erros);
}
}else{
if(tipo.equals("manifestar")){
estado = "91";
}
}

System.out.println(xml);
Expand Down
23 changes: 15 additions & 8 deletions src/main/java/br/com/samuelweb/nfe/util/CertificadoUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.PrivateKey;
import java.security.Security;
import java.security.UnrecoverableEntryException;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.Date;
Expand Down Expand Up @@ -91,9 +91,18 @@ public static List<Certificado> listaCertificadosWindows() throws NfeException {
cert.setNome(aliasKey);
cert.setTipo(Certificado.WINDOWS);
cert.setSenha("");
cert.setVencimento(DataValidade(cert).toInstant().atZone(ZoneId.systemDefault()).toLocalDate());
cert.setDiasRestantes(diasRestantes(cert));
cert.setValido(valido(cert));
Date dataValidade = DataValidade(cert);
if(dataValidade == null){
cert.setNome("(INVÁLIDO)"+aliasKey);
cert.setVencimento(LocalDate.of(2000, 1, 1));
cert.setDiasRestantes(0L);
cert.setValido(false);
}else{
cert.setVencimento(dataValidade.toInstant().atZone(ZoneId.systemDefault()).toLocalDate());
cert.setDiasRestantes(diasRestantes(cert));
cert.setValido(valido(cert));
}

listaCert.add(cert);
}

Expand All @@ -117,8 +126,6 @@ private static Date DataValidade(Certificado certificado) throws NfeException {
try {
X509Certificate cert = null;
KeyStore.PrivateKeyEntry pkEntry = null;
@SuppressWarnings("unused")
PrivateKey privateKey;
KeyStore ks = null;
if(certificado.getTipo().equals(Certificado.WINDOWS)){
ks = KeyStore.getInstance("Windows-MY", "SunMSCAPI");
Expand All @@ -129,8 +136,8 @@ private static Date DataValidade(Certificado certificado) throws NfeException {
ks.load(null, null);
if (ks.isKeyEntry(certificado.getNome())) {
pkEntry = (KeyStore.PrivateKeyEntry) ks.getEntry(certificado.getNome(), new KeyStore.PasswordProtection(certificado.getSenha().toCharArray()));
privateKey = pkEntry.getPrivateKey();

}else{
return null;
}

cert = (X509Certificate) pkEntry.getCertificate();
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/br/com/samuelweb/nfe/util/XmlUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.io.InputStreamReader;
import java.io.StringReader;
import java.io.StringWriter;
import java.text.Normalizer;
import java.util.zip.GZIPInputStream;

import javax.xml.bind.JAXBContext;
Expand Down Expand Up @@ -205,4 +206,15 @@ public static String criaNfeProc(TEnviNFe enviNfe,Object retorno) throws JAXBExc
return xmlFinal;
}

public static String removeAcentos(String str){

str = str.replaceAll("\r", "");
str = str.replaceAll("\t", "");
str = str.replaceAll("\n", "");
str = str.replaceAll(">\\s+<", "><");
CharSequence cs = new StringBuilder(str == null ? "" : str);
return Normalizer.normalize(cs, Normalizer.Form.NFKD).replaceAll("\\p{InCombiningDiacriticalMarks}+", "");

}

}

0 comments on commit 1809c8c

Please sign in to comment.