• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

wmixvideo / nfe / #6682

02 Jun 2016 11:49PM UTC coverage: 79.364% (+0.04%) from 79.328%
#6682

push

travis-ci

fincatto
Atualizado xsd de validacao de envio de lote, que valida as notas com assinatura.
Atualizado para versão 2.0.0-SNAPSHOT, pois o codigo quebrou a compatibilidade.

0 of 1 new or added line in 1 file covered. (0.0%)

142 existing lines in 55 files now uncovered.

4742 of 5975 relevant lines covered (79.36%)

50.29 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

90.63
/src/main/java/com/fincatto/nfe310/utils/NFGeraQRCode.java
1
package com.fincatto.nfe310.utils;
2

3
import java.math.BigInteger;
4
import java.nio.charset.Charset;
5
import java.security.MessageDigest;
6
import java.security.NoSuchAlgorithmException;
7

8
import org.apache.commons.lang3.StringUtils;
9
import org.joda.time.DateTime;
10

11
import com.fincatto.nfe310.NFeConfig;
12
import com.fincatto.nfe310.classes.NFAmbiente;
13
import com.fincatto.nfe310.classes.nota.NFNota;
14

15
public class NFGeraQRCode {
16

17
    private final NFNota nota;
18
    private final NFeConfig config;
19

20
    public NFGeraQRCode(final NFNota nota, final NFeConfig config) {
1✔
21
        this.nota = nota;
1✔
22
        this.config = config;
1✔
23
    }
1✔
24

25
    public String getQRCode() throws NoSuchAlgorithmException {
26
        final String url = this.config.getAmbiente().equals(NFAmbiente.PRODUCAO) ? this.nota.getInfo().getIdentificacao().getUf().getQrCodeProducao() : this.nota.getInfo().getIdentificacao().getUf().getQrCodeHomologacao();
1✔
27
        if (StringUtils.isBlank(url)) {
1✔
UNCOV
28
            throw new IllegalArgumentException("URL para consulta do QRCode nao informada para uf " + this.nota.getInfo().getIdentificacao().getUf() + "!");
×
29
        }
30
        if (StringUtils.isBlank(this.config.getCodigoSegurancaContribuinte())) {
1✔
UNCOV
31
            throw new IllegalArgumentException("CSC nao informado nas configuracoes!");
×
32
        }
33
        if ((this.config.getCodigoSegurancaContribuinteID() == null) || (this.config.getCodigoSegurancaContribuinteID() == 0)) {
1✔
UNCOV
34
            throw new IllegalArgumentException("IdCSC nao informado nas configuracoes!");
×
35
        }
36

37
        final DateTime dt = this.nota.getInfo().getIdentificacao().getDataHoraEmissao();
1✔
38
        final String dtf = dt.toString("yyyy-MM-dd") + "T" + dt.toString("HH:mm:ssZZ");
1✔
39

40
        final String cpfj = this.nota.getInfo().getDestinatario() == null ? null : this.nota.getInfo().getDestinatario().getCpfj();
1✔
41

42
        //Monta os parametros do qrcode: https://www.sefaz.rs.gov.br/NFCE/NFCE-COM.aspx?chNFe=43160493062776000117650010000012891000012891&nVersao=100&tpAmb=1&cDest=00400437031&dhEmi=323031362d30342d31355431363a32313a35312d30333a3030&vNF=88.00&vICMS=0.00&digVal=787971704e2f7771446134687070486e6b6b6c34705a39536a36633d&cIdToken=000001&cHashQRCode=852E4B5BC4EB9BF65484AEEBB06BE4A65F0E8E13
43
        final StringBuilder parametros = new StringBuilder();
1✔
44
        parametros.append("chNFe=").append(this.nota.getInfo().getChaveAcesso()).append("&"); //Chave de Acesso da NFC-e
1✔
45
        parametros.append("nVersao=100").append("&"); //Versao do QRCode
1✔
46
        parametros.append("tpAmb=").append(this.config.getAmbiente().getCodigo()).append("&");
1✔
47

48
        if (StringUtils.isNotBlank(cpfj)) {
1✔
49
            parametros.append("cDest=").append(cpfj).append("&");//Documento de Identificacao do Consumidor (CNPJ/CPF/ID Estrangeiro)
1✔
50
        }
51

52
        parametros.append("dhEmi=").append(NFGeraQRCode.toHex(dtf)).append("&");//Data e Hora de Emissão da NFC-e
1✔
53
        parametros.append("vNF=").append(this.nota.getInfo().getTotal().getIcmsTotal().getValorTotalNFe()).append("&"); //Valor Total da NFC-e
1✔
54
        parametros.append("vICMS=").append(this.nota.getInfo().getTotal().getIcmsTotal().getValorTotalICMS()).append("&");//NFC-e Valor Total ICMS na NFC-e
1✔
55
        parametros.append("digVal=").append(NFGeraQRCode.toHex(this.nota.getAssinatura().getSignedInfo().getReference().getDigestValue())).append("&");//Digest Value da NFC-e
1✔
56
        parametros.append("cIdToken=").append(String.format("%06d", this.config.getCodigoSegurancaContribuinteID()));//Identificador do CSC – Codigo de Seguranca do Contribuinte no Banco de Dados da SEFAZ
1✔
57

58
        //retorna a url do qrcode
59
        return url + "?" + parametros.toString() + "&cHashQRCode=" + NFGeraQRCode.createHash(parametros.toString(), this.config.getCodigoSegurancaContribuinte());
1✔
60
    }
61

62
    public static String createHash(final String campos, final String csc) throws NoSuchAlgorithmException {
63
        return NFGeraQRCode.sha1(campos + csc);
1✔
64
    }
65

66
    public static String toHex(final String arg) {
67
        return String.format("%040x", new BigInteger(1, arg.getBytes(Charset.forName("UTF-8"))));
2✔
68
    }
69

70
    public static String sha1(final String input) throws NoSuchAlgorithmException {
71
        final StringBuilder sb = new StringBuilder();
2✔
72
        for (final byte element : MessageDigest.getInstance("SHA1").digest(input.getBytes(Charset.forName("UTF-8")))) {
42✔
73
            sb.append(Integer.toString((element & 0xff) + 0x100, 16).substring(1));
40✔
74
        }
75
        return sb.toString();
2✔
76
    }
77
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc