Browse Source

teste assinando com xmlsec1

pull/1/head
Junior Tada 11 years ago
parent
commit
fe684c2aed
  1. 3
      pynfe/processamento/assinatura.py
  2. 10
      pynfe/processamento/comunicacao.py

3
pynfe/processamento/assinatura.py

@ -49,7 +49,8 @@ class AssinaturaA1(Assinatura):
with open('testes.xml', 'w') as arquivo:
arquivo.write(etree.tostring(xml, encoding="unicode", pretty_print=False))
subprocess.check_call('xmlsec1 --sign --pkcs12 '+self.certificado+' --pwd '+self.senha+' --crypto openssl --output funciona.xml --id-attr:Id infNFe testes.xml')
subprocess.call(['xmlsec1', '--sign', '--pkcs12', self.certificado, '--pwd', self.senha, '--crypto', 'openssl', '--output', 'funfa.xml', '--id-attr:Id', 'infNFe', 'testes.xml'])
xml = etree.parse('funfa.xml').getroot()
if retorna_string:
return etree.tostring(xml, encoding="unicode", pretty_print=False)

10
pynfe/processamento/comunicacao.py

@ -35,9 +35,9 @@ class ComunicacaoSefaz(Comunicacao):
url = self._get_url(modelo=modelo, consulta='AUTORIZACAO')
# Monta XML do corpo da requisição
raiz = etree.Element('enviNFe', versao=VERSAO_PADRAO, xmlns=NAMESPACE_NFE)
#etree.SubElement(raiz, 'versao').text = self._versao
etree.SubElement(raiz, 'versao').text = self._versao
etree.SubElement(raiz, 'idLote').text = str(1) # numero autoincremental gerado pelo sistema
etree.SubElement(raiz, 'indSinc').text = str(1) # 0 para assincrono, 1 para sincrono
etree.SubElement(raiz, 'indSinc').text = str(0) # 0 para assincrono, 1 para sincrono
#etree.SubElement(raiz, 'NFe').text = nota_fiscal # conjunto de nfe tramistidas (max 50)
raiz.append(nota_fiscal)
# Monta XML para envio da requisição
@ -189,8 +189,8 @@ class ComunicacaoSefaz(Comunicacao):
u"""Monta o XML do cabeçalho da requisição SOAP"""
raiz = etree.Element('nfeCabecMsg', xmlns=NAMESPACE_METODO+metodo)
etree.SubElement(raiz, 'cUF').text = CODIGOS_ESTADOS[self.uf.upper()]
etree.SubElement(raiz, 'versaoDados').text = VERSAO_PADRAO
etree.SubElement(raiz, 'cUF').text = CODIGOS_ESTADOS[self.uf.upper()]
return raiz
def _construir_xml_soap(self, cabecalho, metodo, dados):
@ -228,10 +228,10 @@ class ComunicacaoSefaz(Comunicacao):
try:
xml_declaration='<?xml version="1.0" encoding="utf-8"?>'
# Passa o lxml.etree para string
xml = etree.tostring(xml, encoding='unicode', pretty_print=False).replace('ds:','').replace(':ds','')
xml = etree.tostring(xml, encoding='unicode', pretty_print=False).replace('\n','')
xml = xml_declaration + xml
#print (xml)
# Faz o request com o servidor
print (xml)
result = requests.post(url, xml, headers=self._post_header(), cert=chave_cert, verify=False)
if result == 200:
result.encoding='utf-8'

Loading…
Cancel
Save