Cambios en el SAT

This commit is contained in:
El Mau 2022-03-10 15:25:40 -06:00
parent 1e2cac87e9
commit d6d6877c74
7 changed files with 43 additions and 13 deletions

View File

@ -1,5 +1,9 @@
# Lista de cambios
## v 0.6.0 [10-Mar-22]
---
* Fix - Cambios del SAT
## v 0.5.1 [09-Feb-22]
---

View File

@ -1 +1 @@
0.5.1
0.6.0

Binary file not shown.

Binary file not shown.

BIN
doc/URLs.pdf Normal file

Binary file not shown.

View File

@ -29,12 +29,14 @@ class SATWebService():
'Content-type': 'text/xml;charset="utf-8"',
'Accept': 'text/xml',
'Cache-Control': 'no-cache',
'Expect': '100-continue',
'Accept-Encoding': 'gzip, deflate',
}
NS = {
's': 'http://schemas.xmlsoap.org/soap/envelope/',
'u': 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd',
'o': 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd',
'des': 'http://DescargaMasivaTerceros.sat.gob.mx',
# ~ 'des': 'http://DescargaMasivaTerceros.sat.gob.mx',
'xd': 'http://www.w3.org/2000/09/xmldsig#',
}
NS_RESULT = {'s': NS['s'], None: XMLNS}
@ -148,12 +150,14 @@ class SATWebService():
nsmap = {'s': self.NS['s'], None: self.XMLNS}
node_name = 's:Body/AutenticaResponse/AutenticaResult'
token = result.find(node_name, namespaces=nsmap).text
print(f'Token: {token}')
# ~ print(f'Token: {token}')
return token
def _get_data_req(self, args):
NSMAP = {'s': self.NS['s'], 'des': self.NS['des'], 'xd': self.NS['xd']}
# ~ NSMAP = {'s': self.NS['s'], 'des': self.NS['des'], 'xd': self.NS['xd']}
# ~ NSMAP = {'s': self.NS['s'], 'xd': self.NS['xd']}
NSMAP = {'s': self.NS['s']}
FORMAT = '%Y-%m-%dT%H:%M:%S'
date_start = args['date_start']
@ -165,28 +169,46 @@ class SATWebService():
root = ET.Element(node_name, nsmap=NSMAP)
node_name = f"{{{self.NS['s']}}}Header"
body = ET.SubElement(root, node_name)
header = ET.SubElement(root, node_name)
node_name = 'ActivityId'
attr = {'CorrelationId': '806aad0d-ef46-443b-9741-040c8e8e8c7d'}
nsmap = {None: 'http://schemas.microsoft.com/2004/09/ServiceModel/Diagnostics'}
activity = ET.SubElement(header, node_name, attr, nsmap=nsmap)
activity.text = 'e906cfb4-f706-43de-94d0-5cc935be1aaa'
node_name = f"{{{self.NS['s']}}}Body"
body = ET.SubElement(root, node_name)
nsmap = {
'xsi': 'http://www.w3.org/2001/XMLSchema-instance',
'xsd': 'http://www.w3.org/2001/XMLSchema',
}
body = ET.SubElement(root, node_name, nsmap=nsmap)
node_name = f"{{{self.NS['des']}}}SolicitaDescarga"
request_down = ET.SubElement(body, node_name)
# ~ node_name = f"{{{self.NS['des']}}}SolicitaDescarga"
node_name = "SolicitaDescarga"
nsmap = {None: 'http://DescargaMasivaTerceros.sat.gob.mx'}
request_down = ET.SubElement(body, node_name, nsmap=nsmap)
node_name = f"{{{self.NS['des']}}}solicitud"
# ~ node_name = f"{{{self.NS['des']}}}solicitud"
node_name = "solicitud"
type_request = 'CFDI'
if args['metadata']:
type_request = 'Metadata'
attr = {
'RfcSolicitante': self._cert.rfc,
'FechaFinal': date_end.strftime(FORMAT),
'FechaInicial': date_start.strftime(FORMAT),
'TipoSolicitud': type_request,
'FechaFinal': date_end.strftime(FORMAT),
args['rfc']: self._cert.rfc,
'RfcSolicitante': self._cert.rfc,
'TipoSolicitud': type_request,
'RfcACuentaTerceros': '',
}
request = ET.SubElement(request_down, node_name, attr)
node_name = 'RfcReceptores'
node_receptores = ET.SubElement(request, node_name)
node_name = 'RfcReceptor'
ET.SubElement(node_receptores, node_name)
nsmap = {None: self.NS['xd']}
signature = ET.SubElement(request, 'Signature', nsmap=nsmap)
signed_info = ET.SubElement(signature, 'SignedInfo', nsmap=nsmap)
@ -199,7 +221,8 @@ class SATWebService():
attr = {'Algorithm': 'http://www.w3.org/2000/09/xmldsig#rsa-sha1'}
signature_method = ET.SubElement(signed_info, node_name, attr)
attr = {'URI': '#_0'}
# ~ attr = {'URI': '#_0'}
attr = {'URI': ''}
reference = ET.SubElement(signed_info, 'Reference', attr)
transforms = ET.SubElement(reference, 'Transforms')
ET.SubElement(transforms, 'Transform', attr1)
@ -235,9 +258,12 @@ class SATWebService():
def request_download(self, args):
headers = self.HEADERS.copy()
headers['SOAPAction'] = self.ACTIONS['REQ']
headers['Host'] = 'srvsolicituddescargamaster.cloudapp.net'
headers['Authorization'] = f'WRAP access_token="{self._token}"'
data = self._get_data_req(args)
print(data.decode())
response = httpx.post(self.URL['REQ'], data=data, headers=headers)
if response.status_code != httpx.codes.OK:
self._error = f'Status: {response.status_code} - {response.text}'