Cambios en el SAT
This commit is contained in:
parent
1e2cac87e9
commit
d6d6877c74
|
@ -1,5 +1,9 @@
|
||||||
# Lista de cambios
|
# Lista de cambios
|
||||||
|
|
||||||
|
## v 0.6.0 [10-Mar-22]
|
||||||
|
---
|
||||||
|
* Fix - Cambios del SAT
|
||||||
|
|
||||||
|
|
||||||
## v 0.5.1 [09-Feb-22]
|
## v 0.5.1 [09-Feb-22]
|
||||||
---
|
---
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -29,12 +29,14 @@ class SATWebService():
|
||||||
'Content-type': 'text/xml;charset="utf-8"',
|
'Content-type': 'text/xml;charset="utf-8"',
|
||||||
'Accept': 'text/xml',
|
'Accept': 'text/xml',
|
||||||
'Cache-Control': 'no-cache',
|
'Cache-Control': 'no-cache',
|
||||||
|
'Expect': '100-continue',
|
||||||
|
'Accept-Encoding': 'gzip, deflate',
|
||||||
}
|
}
|
||||||
NS = {
|
NS = {
|
||||||
's': 'http://schemas.xmlsoap.org/soap/envelope/',
|
's': 'http://schemas.xmlsoap.org/soap/envelope/',
|
||||||
'u': 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd',
|
'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',
|
'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#',
|
'xd': 'http://www.w3.org/2000/09/xmldsig#',
|
||||||
}
|
}
|
||||||
NS_RESULT = {'s': NS['s'], None: XMLNS}
|
NS_RESULT = {'s': NS['s'], None: XMLNS}
|
||||||
|
@ -148,12 +150,14 @@ class SATWebService():
|
||||||
nsmap = {'s': self.NS['s'], None: self.XMLNS}
|
nsmap = {'s': self.NS['s'], None: self.XMLNS}
|
||||||
node_name = 's:Body/AutenticaResponse/AutenticaResult'
|
node_name = 's:Body/AutenticaResponse/AutenticaResult'
|
||||||
token = result.find(node_name, namespaces=nsmap).text
|
token = result.find(node_name, namespaces=nsmap).text
|
||||||
print(f'Token: {token}')
|
# ~ print(f'Token: {token}')
|
||||||
|
|
||||||
return token
|
return token
|
||||||
|
|
||||||
def _get_data_req(self, args):
|
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'
|
FORMAT = '%Y-%m-%dT%H:%M:%S'
|
||||||
|
|
||||||
date_start = args['date_start']
|
date_start = args['date_start']
|
||||||
|
@ -165,28 +169,46 @@ class SATWebService():
|
||||||
root = ET.Element(node_name, nsmap=NSMAP)
|
root = ET.Element(node_name, nsmap=NSMAP)
|
||||||
|
|
||||||
node_name = f"{{{self.NS['s']}}}Header"
|
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"
|
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"
|
# ~ node_name = f"{{{self.NS['des']}}}SolicitaDescarga"
|
||||||
request_down = ET.SubElement(body, node_name)
|
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'
|
type_request = 'CFDI'
|
||||||
if args['metadata']:
|
if args['metadata']:
|
||||||
type_request = 'Metadata'
|
type_request = 'Metadata'
|
||||||
attr = {
|
attr = {
|
||||||
'RfcSolicitante': self._cert.rfc,
|
|
||||||
'FechaFinal': date_end.strftime(FORMAT),
|
|
||||||
'FechaInicial': date_start.strftime(FORMAT),
|
'FechaInicial': date_start.strftime(FORMAT),
|
||||||
'TipoSolicitud': type_request,
|
'FechaFinal': date_end.strftime(FORMAT),
|
||||||
args['rfc']: self._cert.rfc,
|
args['rfc']: self._cert.rfc,
|
||||||
|
'RfcSolicitante': self._cert.rfc,
|
||||||
|
'TipoSolicitud': type_request,
|
||||||
|
'RfcACuentaTerceros': '',
|
||||||
}
|
}
|
||||||
request = ET.SubElement(request_down, node_name, attr)
|
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']}
|
nsmap = {None: self.NS['xd']}
|
||||||
signature = ET.SubElement(request, 'Signature', nsmap=nsmap)
|
signature = ET.SubElement(request, 'Signature', nsmap=nsmap)
|
||||||
signed_info = ET.SubElement(signature, 'SignedInfo', 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'}
|
attr = {'Algorithm': 'http://www.w3.org/2000/09/xmldsig#rsa-sha1'}
|
||||||
signature_method = ET.SubElement(signed_info, node_name, attr)
|
signature_method = ET.SubElement(signed_info, node_name, attr)
|
||||||
|
|
||||||
attr = {'URI': '#_0'}
|
# ~ attr = {'URI': '#_0'}
|
||||||
|
attr = {'URI': ''}
|
||||||
reference = ET.SubElement(signed_info, 'Reference', attr)
|
reference = ET.SubElement(signed_info, 'Reference', attr)
|
||||||
transforms = ET.SubElement(reference, 'Transforms')
|
transforms = ET.SubElement(reference, 'Transforms')
|
||||||
ET.SubElement(transforms, 'Transform', attr1)
|
ET.SubElement(transforms, 'Transform', attr1)
|
||||||
|
@ -235,9 +258,12 @@ class SATWebService():
|
||||||
def request_download(self, args):
|
def request_download(self, args):
|
||||||
headers = self.HEADERS.copy()
|
headers = self.HEADERS.copy()
|
||||||
headers['SOAPAction'] = self.ACTIONS['REQ']
|
headers['SOAPAction'] = self.ACTIONS['REQ']
|
||||||
|
headers['Host'] = 'srvsolicituddescargamaster.cloudapp.net'
|
||||||
headers['Authorization'] = f'WRAP access_token="{self._token}"'
|
headers['Authorization'] = f'WRAP access_token="{self._token}"'
|
||||||
data = self._get_data_req(args)
|
data = self._get_data_req(args)
|
||||||
|
|
||||||
|
print(data.decode())
|
||||||
|
|
||||||
response = httpx.post(self.URL['REQ'], data=data, headers=headers)
|
response = httpx.post(self.URL['REQ'], data=data, headers=headers)
|
||||||
if response.status_code != httpx.codes.OK:
|
if response.status_code != httpx.codes.OK:
|
||||||
self._error = f'Status: {response.status_code} - {response.text}'
|
self._error = f'Status: {response.status_code} - {response.text}'
|
||||||
|
|
Loading…
Reference in New Issue