Initial clean portal_sat
This commit is contained in:
parent
61109d3665
commit
c20d979e10
|
@ -160,3 +160,4 @@ cython_debug/
|
||||||
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||||
#.idea/
|
#.idea/
|
||||||
|
|
||||||
|
portal_sat.bk.py
|
||||||
|
|
|
@ -2,26 +2,20 @@
|
||||||
|
|
||||||
import falcon
|
import falcon
|
||||||
import json
|
import json
|
||||||
|
from sat.util import get_uuid
|
||||||
|
|
||||||
XML = """<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<cfdi:Comprobante xmlns:cfdi="http://www.sat.gob.mx/cfd/4">
|
|
||||||
<cfdi:Emisor Rfc="SPE11071516A"/>
|
|
||||||
</cfdi:Comprobante>
|
|
||||||
"""
|
|
||||||
|
|
||||||
|
|
||||||
class JSONTranslator():
|
class JSONTranslator():
|
||||||
def process_response(self, req, resp, resource, req_succeeded):
|
def process_response(self, req, resp, resource, req_succeeded):
|
||||||
if not hasattr(resp.context, 'result'):
|
if not hasattr(resp.context, 'result'):
|
||||||
return
|
return
|
||||||
resp.body = json.dumps(resp.context.result)
|
resp.text = json.dumps(resp.context.result)
|
||||||
|
|
||||||
|
|
||||||
class AppApi(object):
|
class AppApi(object):
|
||||||
|
|
||||||
def on_get(self, req, resp, rfc, cfdi):
|
def on_get(self, req, resp, rfc, cfdi):
|
||||||
resp.context['result'] = {'error': '', 'xml': XML}
|
resp.context['result'] = get_uuid(rfc, cfdi)
|
||||||
resp.status = falcon.HTTP_200
|
resp.status = falcon.HTTP_200
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
|
||||||
|
import requests
|
||||||
|
from requests import Session, exceptions, adapters
|
||||||
|
requests.packages.urllib3.util.ssl_.DEFAULT_CIPHERS += 'HIGH:!DH:!aNULL'
|
||||||
|
|
||||||
|
|
||||||
|
class PortalSAT(object):
|
||||||
|
URL_MAIN = 'https://portalcfdi.facturaelectronica.sat.gob.mx/'
|
||||||
|
HOST = 'cfdiau.sat.gob.mx'
|
||||||
|
BROWSER = 'Mozilla/5.0 (X11; Linux x86_64; rv:55.0) Gecko/20100101 Firefox/55.0'
|
||||||
|
REFERER = 'https://cfdiau.sat.gob.mx/nidp/app/login?id=SATUPCFDiCon&sid=0&option=credential&sid=0'
|
||||||
|
|
||||||
|
PORTAL = 'portalcfdi.facturaelectronica.sat.gob.mx'
|
||||||
|
URL_LOGIN = 'https://{}/nidp/app/login'.format(HOST)
|
||||||
|
URL_FORM = 'https://{}/nidp/app/login?sid=0&sid=0'.format(HOST)
|
||||||
|
URL_PORTAL = 'https://portalcfdi.facturaelectronica.sat.gob.mx/'
|
||||||
|
URL_CONTROL = 'https://cfdicontribuyentes.accesscontrol.windows.net/v2/wsfederation'
|
||||||
|
URL_CONSULTA = URL_PORTAL + 'Consulta.aspx'
|
||||||
|
URL_RECEPTOR = URL_PORTAL + 'ConsultaReceptor.aspx'
|
||||||
|
URL_EMISOR = URL_PORTAL + 'ConsultaEmisor.aspx'
|
||||||
|
URL_LOGOUT = URL_PORTAL + 'logout.aspx?salir=y'
|
||||||
|
|
||||||
|
def __init__(self, cert, cfdi_uuid):
|
||||||
|
self._cert = cert
|
||||||
|
self._uuid = cfdi_uuid
|
||||||
|
self.error = ''
|
||||||
|
self.is_connect = False
|
||||||
|
self._session = Session()
|
||||||
|
a = adapters.HTTPAdapter(pool_connections=512, pool_maxsize=512, max_retries=5)
|
||||||
|
self._session.mount('https://', a)
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
from uuid import UUID
|
||||||
|
from .portal_sat import PortalSAT
|
||||||
|
|
||||||
|
|
||||||
|
def validate_uuid(value):
|
||||||
|
try:
|
||||||
|
UUID(value)
|
||||||
|
return True
|
||||||
|
except ValueError:
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def get_uuid(rfc, cfdi):
|
||||||
|
data = {'error': '', 'xml': ''}
|
||||||
|
|
||||||
|
if not validate_uuid(cfdi):
|
||||||
|
data['error'] = 'UUID inválido'
|
||||||
|
return data
|
||||||
|
|
||||||
|
return data
|
Loading…
Reference in New Issue