Пример #1
0
def _autenticar(request,
                crt,
                key,
                service="wsfe",
                ttl=60 * 60 * 10,
                cuit=None):
    "Obtener el TA"

    from pyafipws import wsaa

    CUIT = cuit
    CERTIFICATE = crt
    PRIVATE_KEY = key

    empresa = empresa_actual(request)
    H**O = empresa.homologacion

    if H**O:
        WSDL = "https://wswhomo.afip.gov.ar/wsfev1/service.asmx?WSDL"
        WSAA_URL = "https://wsaahomo.afip.gov.ar/ws/services/LoginCms"
    else:
        WSDL = "https://servicios1.afip.gov.ar/wsfev1/service.asmx?WSDL"
        WSAA_URL = "https://wsaa.afip.gov.ar/ws/services/LoginCms"

    if service not in ("wsfe", "wsfev1", "wsmtxca", "wsfex", "wsbfe"):
        raise HTTP(500, "Servicio %s incorrecto" % service)

    # verifico archivo temporal con el ticket de acceso
    TA = os.path.join(CERTIFICADOS_PATH, "TA-%s-%s.xml" % (cuit, service))
    ttl = 60 * 60 * 5
    if not os.path.exists(TA) or os.path.getmtime(TA) + (ttl) < time.time():
        # solicito una nueva autenticación
        # wsaa = pyafipws.wsaa
        cert = os.path.join(CERTIFICADOS_PATH, CERTIFICATE)
        privatekey = os.path.join(CERTIFICADOS_PATH, PRIVATE_KEY)
        # creo un ticket de requerimiento de acceso
        # cambiando a wsfe si es wsfe(v_)
        if "wsfev" in service: service = "wsfe"
        tra = wsaa.create_tra(service=service, ttl=ttl)

        # firmo el ticket de requerimiento de acceso
        cms = wsaa.sign_tra(str(tra), str(cert), str(privatekey))

        # llamo al webservice para obtener el ticket de acceso
        ta_string = wsaa.call_wsaa(cms, WSAA_URL, trace=False)
        # guardo el ticket de acceso obtenido:
        open(TA, "w").write(ta_string)

    # procesar el ticket de acceso y extraer TOKEN y SIGN:
    # from gluon.contrib.pysimplesoap.simplexml import SimpleXMLElement

    # agregar librería modificada para aceptar etiquetas vacías
    from pysimplesoap.simplexml import SimpleXMLElement

    ta_string = open(TA).read()
    ta = SimpleXMLElement(ta_string)
    token = str(ta.credentials.token)
    sign = str(ta.credentials.sign)
    return token, sign
Пример #2
0
def _autenticar(service="wsfe", ttl=60*60*5):
    "Obtener el TA"

    from pyafipws import wsaa    
    PRIVATE_PATH = os.path.join(request.env.web2py_path,'applications',request.application,'private')
    CUIT = 20267565393
    CERTIFICATE = "reingart.crt"
    PRIVATE_KEY = "reingart.key"
    WSAA_URL = "https://wsaahomo.afip.gov.ar/ws/services/LoginCms"
    
    # wsfev1 => wsfe!
    # service = {'wsfev1': 'wsfe'}.get(service, service)
    
    if service not in ("wsfe","wsfev1","wsmtxca","wsfex","wsbfe"):
        raise HTTP(500,"Servicio %s incorrecto" % service)
    
    # verifico archivo temporal con el ticket de acceso
    TA = os.path.join(PRIVATE_PATH, "TA-%s.xml" % service)
    ttl = 60*60*5
    if not os.path.exists(TA) or os.path.getmtime(TA)+(ttl)<time.time():
        # solicito una nueva autenticación
        # wsaa = pyafipws.wsaa
        cert = os.path.join(PRIVATE_PATH, CERTIFICATE)
        privatekey = os.path.join(PRIVATE_PATH, PRIVATE_KEY)
        # creo un ticket de requerimiento de acceso
        # cambiando a wsfe si es wsfe(v_)
        if "wsfev" in service: service = "wsfe"
        tra = wsaa.create_tra(service=service,ttl=ttl)

        # firmo el ticket de requerimiento de acceso
        cms = wsaa.sign_tra(str(tra),str(cert),str(privatekey))


        # llamo al webservice para obtener el ticket de acceso
        ta_string = wsaa.call_wsaa(cms,WSAA_URL,trace=False)
        # guardo el ticket de acceso obtenido:
        open(TA,"w").write(ta_string)


    # procesar el ticket de acceso y extraer TOKEN y SIGN:
    # from gluon.contrib.pysimplesoap.simplexml import SimpleXMLElement
    
    # agregar librería modificada para aceptar etiquetas vacías
    from pysimplesoap.simplexml import SimpleXMLElement
        
    ta_string=open(TA).read()
    ta = SimpleXMLElement(ta_string)
    token = str(ta.credentials.token)
    sign = str(ta.credentials.sign)
    return token, sign
Пример #3
0
def _autenticar(service="wsfe", ttl=60 * 60 * 5):
    "Obtener el TA"

    from pyafipws import wsaa
    PRIVATE_PATH = os.path.join(request.env.web2py_path, 'applications',
                                request.application, 'private')
    CUIT = 20267565393
    CERTIFICATE = "reingart.crt"
    PRIVATE_KEY = "reingart.key"
    WSAA_URL = "https://wsaahomo.afip.gov.ar/ws/services/LoginCms"

    # wsfev1 => wsfe!
    # service = {'wsfev1': 'wsfe'}.get(service, service)

    if service not in ("wsfe", "wsfev1", "wsmtxca", "wsfex", "wsbfe"):
        raise HTTP(500, "Servicio %s incorrecto" % service)

    # verifico archivo temporal con el ticket de acceso
    TA = os.path.join(PRIVATE_PATH, "TA-%s.xml" % service)
    ttl = 60 * 60 * 5
    if not os.path.exists(TA) or os.path.getmtime(TA) + (ttl) < time.time():
        # solicito una nueva autenticación
        # wsaa = pyafipws.wsaa
        cert = os.path.join(PRIVATE_PATH, CERTIFICATE)
        privatekey = os.path.join(PRIVATE_PATH, PRIVATE_KEY)
        # creo un ticket de requerimiento de acceso
        # cambiando a wsfe si es wsfe(v_)
        if "wsfev" in service: service = "wsfe"
        tra = wsaa.create_tra(service=service, ttl=ttl)

        # firmo el ticket de requerimiento de acceso
        cms = wsaa.sign_tra(str(tra), str(cert), str(privatekey))

        # llamo al webservice para obtener el ticket de acceso
        ta_string = wsaa.call_wsaa(cms, WSAA_URL, trace=False)
        # guardo el ticket de acceso obtenido:
        open(TA, "w").write(ta_string)

    # procesar el ticket de acceso y extraer TOKEN y SIGN:
    # from gluon.contrib.pysimplesoap.simplexml import SimpleXMLElement

    # agregar librería modificada para aceptar etiquetas vacías
    from pysimplesoap.simplexml import SimpleXMLElement

    ta_string = open(TA).read()
    ta = SimpleXMLElement(ta_string)
    token = str(ta.credentials.token)
    sign = str(ta.credentials.sign)
    return token, sign
Пример #4
0
def test_call_wsaa(key_and_cert):
    wsaa = WSAA()
    tra = wsaa.CreateTRA(service="wsfe", ttl=DEFAULT_TTL)
    cms = wsaa.SignTRA(tra, key_and_cert[1], key_and_cert[0])
    assert call_wsaa(cms, WSDL)