Commit inicial: fuentes MBS ERP (Genero 6) + .gitignore + docs/SETUP_PC_MBS.md
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
IMPORT os
|
||||
|
||||
DEFINE d_tipos, mensaje, f_tipos, filepath STRING
|
||||
DEFINE dir_file CHAR(60)
|
||||
|
||||
FUNCTION UploadDoc()
|
||||
|
||||
LET d_tipos = "XML"
|
||||
LET f_tipos = "*.xml"
|
||||
LET mensaje = %"Elige Documento"
|
||||
|
||||
CALL ui.Interface.frontCall(
|
||||
"standard",
|
||||
"openfile",
|
||||
[dir_file, d_tipos, f_tipos, mensaje],
|
||||
[filepath])
|
||||
|
||||
IF filepath IS NOT NULL THEN
|
||||
IF downshift(os.Path.extension(filepath)) = "xml" THEN
|
||||
RETURN filepath
|
||||
ELSE
|
||||
CALL fgl_winmessage(
|
||||
"ERROR", "EL FILE DEBE SER XML", "INFO")
|
||||
END IF
|
||||
|
||||
END IF
|
||||
|
||||
END FUNCTION
|
||||
|
||||
{FUNCTION OpenDoc(num_docc INT)
|
||||
|
||||
TRY
|
||||
|
||||
SELECT ruta_fisica INTO tmpdir_file FROM vetb00113 WHERE num_doc = num_docc
|
||||
AND nombreFile = documentos[arr_curr()].nombreFile
|
||||
|
||||
CALL ui.Interface.frontCall("standard", "getenv", ["TEMP"], [l_file])
|
||||
|
||||
LET l_file = l_file CLIPPED, "\\", documentos[arr_curr()].nombreFile
|
||||
CALL fgl_putfile(tmpdir_file, l_file)
|
||||
|
||||
CALL ui.Interface.frontCall("standard", "shellexec", [l_file], [p_res])
|
||||
|
||||
CATCH
|
||||
CALL fgl_winmessage("ERROR", err_get(STATUS), "INFO")
|
||||
END TRY
|
||||
|
||||
END FUNCTION}
|
||||
@@ -0,0 +1,546 @@
|
||||
IMPORT os
|
||||
IMPORT com
|
||||
IMPORT XML
|
||||
IMPORT UTIL
|
||||
|
||||
DEFINE url_semilla, url_validasemilla, url_autorizacion,
|
||||
url_recepcion,url_consulta,xambiente STRING
|
||||
DEFINE codigo,tokenxml,nombreFile,filexml,token,respuesta,ptipoRecepcion,xhash STRING
|
||||
DEFINE doc xml.DomDocument
|
||||
MAIN
|
||||
DEFINE elfile,trespuesta STRING
|
||||
CALL ARG_VAL(1) RETURNING elfile
|
||||
|
||||
LET trespuesta = '{"trackId":"41fa951c-20b0-40ee-a225-53110e750324","codigo":"3","estado":"En Proceso","rnc":"124027187","encf":"E310000000006","secuenciaUtilizada":false,"fechaRecepcion":"5/26/2025 4:20:31 PM","mensajes":[{"valor":"","codigo":0}]}'
|
||||
CALL procesoencf('.\\filesXML\\101521262E310000001480.xml','test','normal','consultatrackid',trespuesta)
|
||||
|
||||
|
||||
END MAIN
|
||||
FUNCTION procesoEncf(fileporfirmar,ambiente,tiporecepcion,xoperacion,krespuesta)
|
||||
DEFINE fileporfirmar,rtoken,ambiente,tiporecepcion,xoperacion,krespuesta,trrespuesta STRING
|
||||
|
||||
LET ptipoRecepcion = tiporecepcion
|
||||
|
||||
IF ambiente <> "produccion" THEN
|
||||
IF ambiente <> "test" THEN
|
||||
DISPLAY "no llego bien ",ambiente
|
||||
RETURN
|
||||
END IF
|
||||
END IF
|
||||
|
||||
LET xambiente = ambiente
|
||||
CALL urls()
|
||||
|
||||
CALL buscatoken() RETURNING codigo, tokenxml
|
||||
|
||||
IF codigo <> "200" THEN
|
||||
DISPLAY "respuesta buscatoken: ",tokenxml," ",codigo
|
||||
EXIT PROGRAM
|
||||
END IF
|
||||
|
||||
|
||||
# Create DomDocument object
|
||||
LET doc = xml.DomDocument.Create()
|
||||
# Notice that whitespaces are significant in cryptography,
|
||||
# therefore it is recommended to remove unnecessary ones
|
||||
CALL doc.setFeature("whitespace-in-element-content",FALSE)
|
||||
|
||||
CALL doc.loadFromString(tokenxml)
|
||||
CALL doc.save(".\\filesXML\\marmotech\\mtechTokenString.xml")
|
||||
|
||||
#FIRMA SEMILLA
|
||||
IF os.Path.exists(".\\filesXML\\marmotech\\mtechTokenString.xml") THEN
|
||||
CALL firmasemilla()
|
||||
ELSE
|
||||
DISPLAY "NO PUDE CREAR SEMILLA"
|
||||
RETURN
|
||||
END IF
|
||||
IF os.Path.exists(".\\filesXML\\marmotech\\mtechSignature.xml") THEN
|
||||
CALL validasemilla() RETURNING codigo,respuesta
|
||||
ELSE
|
||||
DISPLAY "NO ENCONTRE LA SEMILLA FIRMADA"
|
||||
RETURN
|
||||
END IF
|
||||
IF respuesta IS NOT NULL THEN
|
||||
LET doc = xml.DomDocument.Create()
|
||||
|
||||
CALL doc.loadFromString(respuesta)
|
||||
CALL doc.save(".\\filesXMl\\marmotech\\RespuestaValida.xml")
|
||||
|
||||
CALL gettoken() RETURNING rtoken
|
||||
LET token = rtoken
|
||||
ELSE
|
||||
DISPLAY "NO TENEMOS RESPUESTA DE VALIDA SEMILLA"
|
||||
RETURN
|
||||
END IF
|
||||
#FRIMA CON GENERO
|
||||
IF xoperacion <> 'consultatrackid' THEN
|
||||
LET filexml = fileporfirmar
|
||||
CALL firmadocumento(fileporfirmar)
|
||||
LET filexml = '.\\filesXML\\marmotech\\firmados\\',os.Path.baseName(filexml)
|
||||
CALL enviafiles(token,filexml) RETURNING codigo,respuesta
|
||||
ELSE
|
||||
LET token = " Bearer ",token
|
||||
CALL consultaResultado(token,krespuesta) RETURNING trrespuesta
|
||||
DISPLAY "consulta: ", trrespuesta
|
||||
END IF
|
||||
|
||||
END FUNCTION
|
||||
FUNCTION firmadocumento(fileafirmar)
|
||||
DEFINE doc xml.DomDocument
|
||||
DEFINE doc2 xml.DomDocument
|
||||
DEFINE root xml.DomNode
|
||||
DEFINE node xml.DomNode
|
||||
DEFINE signNode xml.DomNode
|
||||
|
||||
DEFINE sig xml.Signature
|
||||
DEFINE key xml.CryptoKey
|
||||
DEFINE cert xml.CryptoX509
|
||||
DEFINE index INTEGER,
|
||||
fileafirmar,filefirmado STRING
|
||||
|
||||
# Create DomDocument object
|
||||
LET doc = xml.DomDocument.Create()
|
||||
# Notice that whitespaces are significant in cryptography,
|
||||
# therefore it is recommended to remove unnecessary ones
|
||||
CALL doc.setFeature("whitespace-in-element-content",FALSE)
|
||||
#LET fileafirmar = '.\\filesXML\\marmotech\\originales\\',fileafirmar
|
||||
DISPLAY "file ",fileafirmar
|
||||
LET filexml = fileafirmar
|
||||
|
||||
CALL doc.load(fileafirmar)
|
||||
|
||||
TRY
|
||||
|
||||
|
||||
# Create rsa key
|
||||
LET key = xml.CryptoKey.Create("http://www.w3.org/2001/04/xmldsig-more#rsa-sha256")
|
||||
CALL key.loadPEM(".\\cert\\marmotech\\onlyRSA.pem")
|
||||
|
||||
# Create an X509 certificate with the constructor of the CryptoX509 class.
|
||||
LET cert = xml.CryptoX509.Create()
|
||||
CALL cert.setFeature("X509Certificate",TRUE)
|
||||
|
||||
# Load the X509 certificate associated to the RSA or DSA private key into the CryptoKey object.
|
||||
# CALL cert.loadPEM("cert509.crt")
|
||||
CALL cert.loadPEM(".\\cert\\marmotech\\onlyCert.pem")
|
||||
# Create signature object with the key to use
|
||||
LET sig = xml.Signature.Create()
|
||||
# Assign the CryptoKey object to the Signature object.
|
||||
CALL sig.setKey(KEY)
|
||||
|
||||
# Assign the CryptoX509 object to the Signature object.
|
||||
CALL sig.setCertificate(cert)
|
||||
|
||||
# Set XML node to be signed. In our case, the entire document
|
||||
# LET index = sig.createReference("",
|
||||
# "http://www.w3.org/2001/04/xmlenc#sha256")
|
||||
LET index = sig.createReference('""',
|
||||
"http://www.w3.org/2001/04/xmlenc#sha256")
|
||||
|
||||
# Add enveloped method to not take the XML signature node into account
|
||||
# when computing the entire document.
|
||||
CALL sig.appendReferenceTransformation(index,
|
||||
"http://www.w3.org/2000/09/xmldsig#enveloped-signature",doc.getDocumentElement())
|
||||
# Set canonicalization method on the XML fragment to be signed.
|
||||
# CALL sig.appendReferenceTransformation(index,
|
||||
# "http://www.w3.org/2001/10/xml-exc-c14n#")
|
||||
# Compute enveloped signature
|
||||
CALL sig.compute(doc)
|
||||
# Retrieve signature document
|
||||
LET doc2=sig.getDocument()
|
||||
# Append the signature node to the original document to get
|
||||
# a valid enveloped signature
|
||||
# Notice that the enveloped signature can be added anywhere in the
|
||||
# original document
|
||||
LET signNode = doc2.getDocumentElement() # Get Signature node
|
||||
# Import it into the original document
|
||||
LET node = doc.importNode(signNode,true)
|
||||
# Retrieve the original document root node
|
||||
LET root = doc.getDocumentElement()
|
||||
|
||||
# Append the signature node as last child of the original document
|
||||
CALL root.appendChild(node)
|
||||
# Save document with enveloped signature back to disk
|
||||
CALL doc.setFeature("format-pretty-print",TRUE)
|
||||
LET filefirmado = '.\\filesXML\\marmotech\\firmados\\',os.Path.baseName(fileafirmar)
|
||||
CALL doc.save(filefirmado)
|
||||
|
||||
|
||||
CATCH
|
||||
DISPLAY "Unable to create an enveloped signature :",status," ",sqlca.sqlerrm
|
||||
END TRY
|
||||
|
||||
END FUNCTION
|
||||
FUNCTION firmasemilla()
|
||||
DEFINE doc xml.DomDocument
|
||||
DEFINE doc2 xml.DomDocument
|
||||
DEFINE root xml.DomNode
|
||||
DEFINE node xml.DomNode
|
||||
DEFINE signNode xml.DomNode
|
||||
|
||||
DEFINE sig xml.Signature
|
||||
DEFINE key xml.CryptoKey
|
||||
DEFINE cert xml.CryptoX509
|
||||
DEFINE index INTEGER
|
||||
|
||||
# Create DomDocument object
|
||||
LET doc = xml.DomDocument.Create()
|
||||
# Notice that whitespaces are significant in cryptography,
|
||||
# therefore it is recommended to remove unnecessary ones
|
||||
CALL doc.setFeature("whitespace-in-element-content",FALSE)
|
||||
|
||||
LET filexml = ".\\filesXML\\marmotech\\mtechTokenString.xml"
|
||||
|
||||
IF os.Path.exists(filexml) THEN
|
||||
CALL doc.load(filexml)
|
||||
ELSE
|
||||
DISPLAY "NO LO ENCONTRE"
|
||||
RETURN
|
||||
END IF
|
||||
TRY
|
||||
|
||||
# Create rsa key
|
||||
LET key = xml.CryptoKey.Create("http://www.w3.org/2001/04/xmldsig-more#rsa-sha256")
|
||||
CALL key.loadPEM(".\\cert\\marmotech\\onlyRSA.pem")
|
||||
|
||||
# Create an X509 certificate with the constructor of the CryptoX509 class.
|
||||
LET cert = xml.CryptoX509.Create()
|
||||
CALL cert.setFeature("X509Certificate",TRUE)
|
||||
|
||||
# Load the X509 certificate associated to the RSA or DSA private key into the CryptoKey object.
|
||||
# CALL cert.loadPEM("cert509.crt")
|
||||
CALL cert.loadPEM(".\\cert\\marmotech\\onlyCert.pem")
|
||||
# Create signature object with the key to use
|
||||
LET sig = xml.Signature.Create()
|
||||
# Assign the CryptoKey object to the Signature object.
|
||||
CALL sig.setKey(KEY)
|
||||
|
||||
# Assign the CryptoX509 object to the Signature object.
|
||||
CALL sig.setCertificate(cert)
|
||||
|
||||
# Set XML node to be signed. In our case, the entire document
|
||||
# LET index = sig.createReference("",
|
||||
# "http://www.w3.org/2001/04/xmlenc#sha256")
|
||||
LET index = sig.createReference('""',
|
||||
"http://www.w3.org/2001/04/xmlenc#sha256")
|
||||
|
||||
# Add enveloped method to not take the XML signature node into account
|
||||
# when computing the entire document.
|
||||
CALL sig.appendReferenceTransformation(index,
|
||||
"http://www.w3.org/2000/09/xmldsig#enveloped-signature",doc.getDocumentElement())
|
||||
# Set canonicalization method on the XML fragment to be signed.
|
||||
# CALL sig.appendReferenceTransformation(index,
|
||||
# "http://www.w3.org/2001/10/xml-exc-c14n#")
|
||||
# Compute enveloped signature
|
||||
CALL sig.compute(doc)
|
||||
# Retrieve signature document
|
||||
LET doc2=sig.getDocument()
|
||||
# Append the signature node to the original document to get
|
||||
# a valid enveloped signature
|
||||
# Notice that the enveloped signature can be added anywhere in the
|
||||
# original document
|
||||
LET signNode = doc2.getDocumentElement() # Get Signature node
|
||||
# Import it into the original document
|
||||
LET node = doc.importNode(signNode,true)
|
||||
# Retrieve the original document root node
|
||||
LET root = doc.getDocumentElement()
|
||||
|
||||
# Append the signature node as last child of the original document
|
||||
CALL root.appendChild(node)
|
||||
# Save document with enveloped signature back to disk
|
||||
CALL doc.setFeature("format-pretty-print",TRUE)
|
||||
CALL doc.save(".\\filesXML\\marmotech\\mtechSignature.xml")
|
||||
|
||||
|
||||
CATCH
|
||||
DISPLAY "Unable to create an enveloped signature :",status," ",sqlca.sqlerrm
|
||||
END TRY
|
||||
|
||||
END FUNCTION
|
||||
|
||||
FUNCTION validasemilla()
|
||||
DEFINE respuesta,codigo STRING,
|
||||
http_req com.HttpRequest,
|
||||
http_resp com.HTTPResponse
|
||||
|
||||
|
||||
LET http_req = com.HTTPRequest.Create(url_validasemilla)
|
||||
|
||||
CALL http_req.setMethod("POST")
|
||||
CALL http_req.setCharset("UTF-8")
|
||||
CALL http_req.setHeader("accept","application/xml")
|
||||
CALL http_req.setMultipartType("form-data",NULL,NULL)
|
||||
|
||||
IF os.Path.exists(".\\filesXML\\marmotech\\mtechSignature.xml") THEN
|
||||
|
||||
CALL http_req.setHeader("Content-Disposition", "form-data; name=\"xml\"; filename=\".\\filesXML\\marmotech\\mtechSignature.xml\"")
|
||||
|
||||
CALL http_req.doFileRequest(".\\filesXML\\marmotech\\mtechSignature.xml")
|
||||
ELSE
|
||||
DISPLAY "NO LO ENCUENTRO"
|
||||
RETURN 0,"FILE NO EXISTE"
|
||||
END IF
|
||||
# CALL http_req.setHeader("Content-Disposition", "form-data; name=\"xml\"; filename=\"naceSignature.xml\"")
|
||||
|
||||
# CALL http_req.doFileRequest("naceSignature.xml")
|
||||
|
||||
|
||||
LET http_resp= http_req.getResponse()
|
||||
LET codigo = http_resp.getStatusCode()
|
||||
LET respuesta = http_resp.getTextResponse()
|
||||
|
||||
IF http_resp.getStatusCode() != 200 THEN
|
||||
DISPLAY "error: ",codigo," ", respuesta
|
||||
RETURN codigo, respuesta
|
||||
END IF
|
||||
|
||||
DISPLAY "valida semilla: ",codigo," ", respuesta
|
||||
RETURN codigo, respuesta
|
||||
|
||||
|
||||
END FUNCTION
|
||||
FUNCTION enviafiles(btoken,archivo)
|
||||
DEFINE respuesta,btoken,codigo,archivo,contenido,consultaResp STRING,
|
||||
http_req com.HttpRequest,
|
||||
http_resp com.HTTPResponse
|
||||
|
||||
|
||||
|
||||
LET btoken =" Bearer ",btoken
|
||||
DISPLAY "url ",url_recepcion
|
||||
LET http_req = com.HTTPRequest.Create(url_recepcion)
|
||||
|
||||
CALL http_req.setMethod("POST")
|
||||
CALL http_req.setCharset("UTF-8")
|
||||
CALL http_req.setHeader("accept","application/json")
|
||||
CALL http_req.setHeader("Authorization",btoken)
|
||||
|
||||
CALL http_req.setMultipartType("form-data",NULL,NULL)
|
||||
|
||||
# "form-data; name=\"xml\"; filename=\"naceSignature.xml\""
|
||||
# LET archivo = "101521262E310000000001.xml"
|
||||
|
||||
IF os.Path.exists(archivo) THEN
|
||||
DISPLAY "archivo: ",archivo
|
||||
LET contenido = "form-data; name=\"xml\"; filename=",os.path.basename(archivo)
|
||||
#CALL http_req.setHeader("Content-Disposition", "form-data; name=\"xml\"; filename=\"130337391E310000000005.XML\"")
|
||||
|
||||
CALL http_req.setHeader("Content-Disposition", contenido)
|
||||
# CALL http_req.setHeader("Content-Disposition", "form-data; name=\"xml\"; filename=\"130337391E310000000016.xml\"")
|
||||
CALL http_req.doFileRequest(archivo)
|
||||
|
||||
LET http_resp= http_req.getResponse()
|
||||
LET codigo = http_resp.getStatusCode()
|
||||
LET respuesta= http_resp.getTextResponse()
|
||||
|
||||
IF http_resp.getStatusCode() != 200 THEN
|
||||
DISPLAY "error: ",codigo," ", respuesta
|
||||
RETURN codigo, respuesta
|
||||
END IF
|
||||
|
||||
ELSE
|
||||
|
||||
RETURN 0,"FILE NO EXISTE"
|
||||
END IF
|
||||
# CALL http_req.setHeader("Content-Disposition", "form-data; name=\"xml\"; filename=\"naceSignature.xml\"")
|
||||
|
||||
# CALL http_req.doFileRequest("naceSignature.xml")
|
||||
|
||||
DISPLAY "enviafile: ",codigo," ", respuesta
|
||||
IF ptipoRecepcion <> "aprobacion" THEN
|
||||
CALL consultaResultado(btoken,respuesta) RETURNING consultaResp
|
||||
DISPLAY "responde consulta: ",consultaResp
|
||||
END IF
|
||||
RETURN codigo, respuesta
|
||||
|
||||
|
||||
END FUNCTION
|
||||
|
||||
FUNCTION gettoken()
|
||||
DEFINE i, l INTEGER
|
||||
DEFINE r om.XmlReader
|
||||
DEFINE e,tok String
|
||||
DEFINE a om.SaxAttributes
|
||||
DISPLAY "filexml: ",filexml
|
||||
LET r = om.XmlReader.createFileReader(".\\filesXML\\marmotech\\RespuestaValida.xml")
|
||||
LET l = 0
|
||||
LET e = r.read()
|
||||
|
||||
WHILE e IS NOT NULL
|
||||
CASE e
|
||||
WHEN "StartDocument"
|
||||
# DISPLAY "StartDocument:"
|
||||
WHEN "StartElement"
|
||||
LET l=l+1
|
||||
#DISPLAY l SPACES, "StartElement:", r.getTagName()
|
||||
LET a = r.getAttributes()
|
||||
FOR i=1 to a.getLength()
|
||||
IF a.getName(i) = "token" THEN
|
||||
# DISPLAY l SPACES," ",
|
||||
# a.getName(i)," = ",
|
||||
# a.getValueByIndex(i)
|
||||
END IF
|
||||
END FOR
|
||||
WHEN "Characters"
|
||||
|
||||
|
||||
IF r.getTagName() = "token" THEN
|
||||
LET tok = r.getCharacters()
|
||||
# DISPLAY "token dentro de gettoken: ",tok
|
||||
EXIT CASE
|
||||
END IF
|
||||
WHEN "SkippedEntity"
|
||||
# DISPLAY "Entity:'",r.skippedEntity(),"'"
|
||||
WHEN "EndElement"
|
||||
# DISPLAY l SPACES, "EndElement:", r.getTagName()
|
||||
LET l=l-1
|
||||
WHEN "EndDocument"
|
||||
# DISPLAY "EndDocument:"
|
||||
OTHERWISE
|
||||
# DISPLAY "Invalid event: ",e
|
||||
END CASE
|
||||
LET e=r.read()
|
||||
END WHILE
|
||||
RETURN tok
|
||||
END FUNCTION
|
||||
|
||||
FUNCTION buscatoken()
|
||||
|
||||
DEFINE respuesta STRING,
|
||||
http_req com.HttpRequest,
|
||||
http_resp com.HTTPResponse
|
||||
|
||||
#SELECT a.urltoken INTO url FROM companias a
|
||||
#"https://ecf.dgii.gov.do/testecf/autenticacion/api/autenticacion/semilla"
|
||||
#"https://ecf.dgii.gov.do/CerteCF/Autenticacion/api/Autenticacion/Semilla"
|
||||
|
||||
|
||||
LET http_req = com.HTTPRequest.Create(url_semilla)
|
||||
|
||||
CALL http_req.setMethod("GET")
|
||||
CALL http_req.setCharset("UTF-8")
|
||||
CALL http_req.setHeader("accept","application/xml")
|
||||
CALL http_req.doRequest()
|
||||
#CALL http_req.doTextRequest(url)
|
||||
|
||||
LET http_resp= http_req.getResponse()
|
||||
|
||||
IF http_resp.getStatusCode() != 200 THEN
|
||||
RETURN http_resp.getStatusCode(), http_resp.getTextResponse()
|
||||
END IF
|
||||
|
||||
LET respuesta = http_resp.getTextResponse()
|
||||
|
||||
|
||||
RETURN http_resp.getStatusCode(),respuesta
|
||||
END FUNCTION
|
||||
FUNCTION urls()
|
||||
IF xambiente = "produccion" THEN
|
||||
|
||||
IF ptipoRecepcion = "normal" THEN
|
||||
LET url_recepcion ="https://ecf.dgii.gov.do/ecf/Recepcion/api/FacturasElectronicas"
|
||||
ELSE
|
||||
IF ptipoRecepcion = 'consumo' THEN
|
||||
LET url_recepcion ="https://fc.dgii.gov.do/ecf/RecepcionFC/api/Recepcion/ecf"
|
||||
END IF
|
||||
END IF
|
||||
|
||||
IF ptipoRecepcion = 'normal32' THEN
|
||||
LET url_recepcion ="https://fc.dgii.gov.do/ecf/RecepcionFC/api/Recepcion/ecf"
|
||||
END IF
|
||||
|
||||
LET url_semilla ="https://ecf.dgii.gov.do/ecf/autenticacion/api/autenticacion/semilla"
|
||||
LET url_validasemilla ="https://ecf.dgii.gov.do/ecf/Autenticacion/api/Autenticacion/ValidarSemilla"
|
||||
LET url_consulta = "https://ecf.dgii.gov.do/ecf/ConsultaResultado/api/consultas/estado"
|
||||
|
||||
|
||||
END IF
|
||||
|
||||
|
||||
IF xambiente = "certificacion" THEN
|
||||
|
||||
IF ptipoRecepcion = 'aprobacion' THEN
|
||||
LET url_recepcion ="https://ecf.dgii.gov.do/CerteCF/aprobacioncomercial/api/aprobacioncomercial"
|
||||
END IF
|
||||
IF ptipoRecepcion = "normal" THEN
|
||||
|
||||
LET url_recepcion ="https://ecf.dgii.gov.do/CerteCF/Recepcion/api/FacturasElectronicas"
|
||||
ELSE
|
||||
IF ptipoRecepcion = 'consumo' THEN
|
||||
LET url_recepcion ="https://fc.dgii.gov.do/CerteCF/RecepcionFC/api/Recepcion/ecf"
|
||||
END IF
|
||||
END IF
|
||||
|
||||
IF ptipoRecepcion = 'normal32' THEN
|
||||
LET url_recepcion ="https://fc.dgii.gov.do/CerteCF/RecepcionFC/api/Recepcion/ecf"
|
||||
END IF
|
||||
|
||||
LET url_semilla ="https://ecf.dgii.gov.do/CerteCF/autenticacion/api/autenticacion/semilla"
|
||||
LET url_validasemilla ="https://ecf.dgii.gov.do/CerteCF/Autenticacion/api/Autenticacion/ValidarSemilla"
|
||||
LET url_consulta = "https://ecf.dgii.gov.do/CerteCF/ConsultaResultado/api/consultas/estado"
|
||||
|
||||
END IF
|
||||
|
||||
IF xambiente = "test" THEN
|
||||
|
||||
IF ptipoRecepcion = "normal" THEN
|
||||
LET url_recepcion ="https://ecf.dgii.gov.do/TesteCF/Recepcion/api/FacturasElectronicas"
|
||||
ELSE
|
||||
IF ptipoRecepcion = 'consumo' THEN
|
||||
LET url_recepcion ="https://fc.dgii.gov.do/TesteCF/RecepcionFC/api/Recepcion/ecf"
|
||||
END IF
|
||||
END IF
|
||||
|
||||
IF ptipoRecepcion = 'normal32' THEN
|
||||
LET url_recepcion ="https://fc.dgii.gov.do/TesteCF/RecepcionFC/api/Recepcion/ecf"
|
||||
END IF
|
||||
|
||||
LET url_semilla ="https://ecf.dgii.gov.do/TesteCF/autenticacion/api/autenticacion/semilla"
|
||||
LET url_validasemilla ="https://ecf.dgii.gov.do/TesteCF/Autenticacion/api/Autenticacion/ValidarSemilla"
|
||||
LET url_consulta = "https://ecf.dgii.gov.do/TesteCF/ConsultaResultado/api/consultas/estado"
|
||||
|
||||
END IF
|
||||
|
||||
END FUNCTION
|
||||
FUNCTION consultaResultado(ctoken,data)
|
||||
DEFINE data,ctoken STRING
|
||||
|
||||
DEFINE crespuesta STRING,
|
||||
http_req com.HttpRequest,
|
||||
http_resp com.HTTPResponse
|
||||
|
||||
DEFINE dtrackid RECORD
|
||||
trackid,ERROR,mensaje STRING
|
||||
END RECORD
|
||||
|
||||
CALL util.JSON.parse(data,dtrackid)
|
||||
|
||||
DISPLAY "TRACK: ",dtrackid.trackid
|
||||
|
||||
|
||||
#SELECT a.urltoken INTO url FROM companias a
|
||||
#"https://ecf.dgii.gov.do/testecf/autenticacion/api/autenticacion/semilla"
|
||||
#"https://ecf.dgii.gov.do/CerteCF/Autenticacion/api/Autenticacion/Semilla"
|
||||
|
||||
LET url_consulta = url_consulta CLIPPED,"?TrackId=",dtrackid.trackid CLIPPED
|
||||
LET http_req = com.HTTPRequest.Create(url_consulta)
|
||||
|
||||
CALL http_req.setMethod("GET")
|
||||
CALL http_req.setCharset("UTF-8")
|
||||
CALL http_req.setHeader("accept","application/json")
|
||||
CALL http_req.setHeader("Authorization",ctoken)
|
||||
CALL http_req.doRequest()
|
||||
|
||||
|
||||
LET http_resp= http_req.getResponse()
|
||||
LET crespuesta = http_resp.getTextResponse()
|
||||
|
||||
IF http_resp.getStatusCode() != 200 THEN
|
||||
RETURN crespuesta
|
||||
END IF
|
||||
|
||||
|
||||
RETURN crespuesta
|
||||
|
||||
END FUNCTION
|
||||
@@ -0,0 +1,555 @@
|
||||
IMPORT os
|
||||
IMPORT com
|
||||
IMPORT XML
|
||||
IMPORT UTIL
|
||||
|
||||
DEFINE url_semilla, url_validasemilla, url_autorizacion,
|
||||
url_recepcion,url_consulta,xambiente STRING
|
||||
DEFINE codigo,tokenxml,nombreFile,filexml,token,respuesta,ptipoRecepcion,xhash STRING
|
||||
DEFINE doc xml.DomDocument
|
||||
MAIN
|
||||
DEFINE elfile,trespuesta STRING
|
||||
CALL ARG_VAL(1) RETURNING elfile
|
||||
|
||||
LET trespuesta = '{"trackId":"d7168f2a-3137-4ef6-976d-1ee29efb857a","mensajes":[]}'
|
||||
CALL procesoencf('.\\filesXML\\101521262E340000003185.xml','produccion','normal','consultatrackid',trespuesta)
|
||||
|
||||
|
||||
END MAIN
|
||||
FUNCTION procesoEncf(fileporfirmar,ambiente,tiporecepcion,xoperacion,krespuesta)
|
||||
DEFINE fileporfirmar,rtoken,ambiente,tiporecepcion,xoperacion,krespuesta,trrespuesta STRING
|
||||
|
||||
LET ptipoRecepcion = tiporecepcion
|
||||
|
||||
IF ambiente <> "produccion" THEN
|
||||
IF ambiente <> "test" THEN
|
||||
DISPLAY "no llego bien ",ambiente
|
||||
RETURN
|
||||
END IF
|
||||
END IF
|
||||
|
||||
LET xambiente = ambiente
|
||||
CALL urls()
|
||||
|
||||
CALL buscatoken() RETURNING codigo, tokenxml
|
||||
|
||||
IF codigo <> "200" THEN
|
||||
DISPLAY "respuesta buscatoken: ",tokenxml," ",codigo
|
||||
EXIT PROGRAM
|
||||
END IF
|
||||
|
||||
|
||||
# Create DomDocument object
|
||||
LET doc = xml.DomDocument.Create()
|
||||
# Notice that whitespaces are significant in cryptography,
|
||||
# therefore it is recommended to remove unnecessary ones
|
||||
CALL doc.setFeature("whitespace-in-element-content",FALSE)
|
||||
|
||||
CALL doc.loadFromString(tokenxml)
|
||||
CALL doc.save(".\\filesXML\\marmotech\\mtechTokenString.xml")
|
||||
|
||||
#FIRMA SEMILLA
|
||||
IF os.Path.exists(".\\filesXML\\marmotech\\mtechTokenString.xml") THEN
|
||||
CALL firmasemilla()
|
||||
ELSE
|
||||
DISPLAY "NO PUDE CREAR SEMILLA"
|
||||
RETURN
|
||||
END IF
|
||||
IF os.Path.exists(".\\filesXML\\marmotech\\Signature.xml") THEN
|
||||
CALL validasemilla() RETURNING codigo,respuesta
|
||||
ELSE
|
||||
DISPLAY "NO ENCONTRE LA SEMILLA FIRMADA"
|
||||
RETURN
|
||||
END IF
|
||||
IF respuesta IS NOT NULL THEN
|
||||
LET doc = xml.DomDocument.Create()
|
||||
|
||||
CALL doc.loadFromString(respuesta)
|
||||
CALL doc.save(".\\filesXML\\marmotech\\RespuestaValida.xml")
|
||||
|
||||
CALL gettoken() RETURNING rtoken
|
||||
LET token = rtoken
|
||||
ELSE
|
||||
DISPLAY "NO TENEMOS RESPUESTA DE VALIDA SEMILLA"
|
||||
RETURN
|
||||
END IF
|
||||
#FRIMA CON GENERO
|
||||
IF xoperacion <> 'consultatrackid' THEN
|
||||
LET filexml = fileporfirmar
|
||||
CALL firmadocumento(fileporfirmar)
|
||||
LET filexml = '.\\filesXML\\marmotech\\\\firmados\\',os.Path.baseName(filexml)
|
||||
CALL enviafiles(token,filexml) RETURNING codigo,respuesta
|
||||
ELSE
|
||||
LET token = " Bearer ",token
|
||||
CALL consultaResultado(token,krespuesta) RETURNING trrespuesta
|
||||
DISPLAY "consulta: ", trrespuesta
|
||||
END IF
|
||||
|
||||
END FUNCTION
|
||||
FUNCTION firmadocumento(fileafirmar)
|
||||
DEFINE doc xml.DomDocument
|
||||
DEFINE doc2 xml.DomDocument
|
||||
DEFINE root xml.DomNode
|
||||
DEFINE node xml.DomNode
|
||||
DEFINE signNode xml.DomNode
|
||||
|
||||
DEFINE sig xml.Signature
|
||||
DEFINE key xml.CryptoKey
|
||||
DEFINE cert xml.CryptoX509
|
||||
DEFINE index INTEGER,
|
||||
fileafirmar,filefirmado STRING
|
||||
|
||||
# Create DomDocument object
|
||||
LET doc = xml.DomDocument.Create()
|
||||
# Notice that whitespaces are significant in cryptography,
|
||||
# therefore it is recommended to remove unnecessary ones
|
||||
CALL doc.setFeature("whitespace-in-element-content",FALSE)
|
||||
#LET fileafirmar = '.\\filesXML\\marmotech\\originales\\',fileafirmar
|
||||
DISPLAY "file ",fileafirmar
|
||||
LET filexml = fileafirmar
|
||||
|
||||
CALL doc.load(fileafirmar)
|
||||
|
||||
TRY
|
||||
|
||||
|
||||
# Create rsa key
|
||||
LET key = xml.CryptoKey.Create("http://www.w3.org/2001/04/xmldsig-more#rsa-sha256")
|
||||
CALL key.loadPEM(".\\cert\\marmotech\\onlyRSA.pem")
|
||||
|
||||
# Create an X509 certificate with the constructor of the CryptoX509 class.
|
||||
LET cert = xml.CryptoX509.Create()
|
||||
CALL cert.setFeature("X509Certificate",TRUE)
|
||||
|
||||
# Load the X509 certificate associated to the RSA or DSA private key into the CryptoKey object.
|
||||
# CALL cert.loadPEM("cert509.crt")
|
||||
CALL cert.loadPEM(".\\cert\\marmotech\\onlyCert.pem")
|
||||
# Create signature object with the key to use
|
||||
LET sig = xml.Signature.Create()
|
||||
# Assign the CryptoKey object to the Signature object.
|
||||
CALL sig.setKey(KEY)
|
||||
|
||||
# Assign the CryptoX509 object to the Signature object.
|
||||
CALL sig.setCertificate(cert)
|
||||
|
||||
# Set XML node to be signed. In our case, the entire document
|
||||
# LET index = sig.createReference("",
|
||||
# "http://www.w3.org/2001/04/xmlenc#sha256")
|
||||
LET index = sig.createReference('""',
|
||||
"http://www.w3.org/2001/04/xmlenc#sha256")
|
||||
|
||||
# Add enveloped method to not take the XML signature node into account
|
||||
# when computing the entire document.
|
||||
CALL sig.appendReferenceTransformation(index,
|
||||
"http://www.w3.org/2000/09/xmldsig#enveloped-signature",doc.getDocumentElement())
|
||||
# Set canonicalization method on the XML fragment to be signed.
|
||||
# CALL sig.appendReferenceTransformation(index,
|
||||
# "http://www.w3.org/2001/10/xml-exc-c14n#")
|
||||
# Compute enveloped signature
|
||||
CALL sig.compute(doc)
|
||||
# Retrieve signature document
|
||||
LET doc2=sig.getDocument()
|
||||
# Append the signature node to the original document to get
|
||||
# a valid enveloped signature
|
||||
# Notice that the enveloped signature can be added anywhere in the
|
||||
# original document
|
||||
LET signNode = doc2.getDocumentElement() # Get Signature node
|
||||
# Import it into the original document
|
||||
LET node = doc.importNode(signNode,true)
|
||||
# Retrieve the original document root node
|
||||
LET root = doc.getDocumentElement()
|
||||
|
||||
# Append the signature node as last child of the original document
|
||||
CALL root.appendChild(node)
|
||||
# Save document with enveloped signature back to disk
|
||||
CALL doc.setFeature("format-pretty-print",TRUE)
|
||||
LET filefirmado = '.\\filesXML\\marmotech\\firmados\\',os.Path.baseName(fileafirmar)
|
||||
CALL doc.save(filefirmado)
|
||||
|
||||
|
||||
CATCH
|
||||
DISPLAY "Unable to create an enveloped signature :",status," ",sqlca.sqlerrm
|
||||
END TRY
|
||||
|
||||
END FUNCTION
|
||||
FUNCTION firmasemilla()
|
||||
DEFINE doc xml.DomDocument
|
||||
DEFINE doc2 xml.DomDocument
|
||||
DEFINE root xml.DomNode
|
||||
DEFINE node xml.DomNode
|
||||
DEFINE signNode xml.DomNode
|
||||
|
||||
DEFINE sig xml.Signature
|
||||
DEFINE key xml.CryptoKey
|
||||
DEFINE cert xml.CryptoX509
|
||||
DEFINE index INTEGER
|
||||
|
||||
# Create DomDocument object
|
||||
LET doc = xml.DomDocument.Create()
|
||||
# Notice that whitespaces are significant in cryptography,
|
||||
# therefore it is recommended to remove unnecessary ones
|
||||
CALL doc.setFeature("whitespace-in-element-content",FALSE)
|
||||
|
||||
LET filexml = ".\\filesXML\\marmotech\\mtechTokenString.xml"
|
||||
|
||||
IF os.Path.exists(filexml) THEN
|
||||
CALL doc.load(filexml)
|
||||
ELSE
|
||||
DISPLAY "NO LO ENCONTRE"
|
||||
RETURN
|
||||
END IF
|
||||
TRY
|
||||
|
||||
# Create rsa key
|
||||
LET key = xml.CryptoKey.Create("http://www.w3.org/2001/04/xmldsig-more#rsa-sha256")
|
||||
CALL key.loadPEM(".\\cert\\marmotech\\onlyRSA.pem")
|
||||
|
||||
# Create an X509 certificate with the constructor of the CryptoX509 class.
|
||||
LET cert = xml.CryptoX509.Create()
|
||||
CALL cert.setFeature("X509Certificate",TRUE)
|
||||
|
||||
# Load the X509 certificate associated to the RSA or DSA private key into the CryptoKey object.
|
||||
# CALL cert.loadPEM("cert509.crt")
|
||||
CALL cert.loadPEM(".\\cert\\marmotech\\onlyCert.pem")
|
||||
# Create signature object with the key to use
|
||||
LET sig = xml.Signature.Create()
|
||||
# Assign the CryptoKey object to the Signature object.
|
||||
CALL sig.setKey(KEY)
|
||||
|
||||
# Assign the CryptoX509 object to the Signature object.
|
||||
CALL sig.setCertificate(cert)
|
||||
|
||||
# Set XML node to be signed. In our case, the entire document
|
||||
# LET index = sig.createReference("",
|
||||
# "http://www.w3.org/2001/04/xmlenc#sha256")
|
||||
LET index = sig.createReference('""',
|
||||
"http://www.w3.org/2001/04/xmlenc#sha256")
|
||||
|
||||
# Add enveloped method to not take the XML signature node into account
|
||||
# when computing the entire document.
|
||||
CALL sig.appendReferenceTransformation(index,
|
||||
"http://www.w3.org/2000/09/xmldsig#enveloped-signature",doc.getDocumentElement())
|
||||
# Set canonicalization method on the XML fragment to be signed.
|
||||
# CALL sig.appendReferenceTransformation(index,
|
||||
# "http://www.w3.org/2001/10/xml-exc-c14n#")
|
||||
# Compute enveloped signature
|
||||
CALL sig.compute(doc)
|
||||
# Retrieve signature document
|
||||
LET doc2=sig.getDocument()
|
||||
# Append the signature node to the original document to get
|
||||
# a valid enveloped signature
|
||||
# Notice that the enveloped signature can be added anywhere in the
|
||||
# original document
|
||||
LET signNode = doc2.getDocumentElement() # Get Signature node
|
||||
# Import it into the original document
|
||||
LET node = doc.importNode(signNode,true)
|
||||
# Retrieve the original document root node
|
||||
LET root = doc.getDocumentElement()
|
||||
|
||||
# Append the signature node as last child of the original document
|
||||
CALL root.appendChild(node)
|
||||
# Save document with enveloped signature back to disk
|
||||
CALL doc.setFeature("format-pretty-print",TRUE)
|
||||
CALL doc.save(".\\cert\\marmotech\\Signature.xml")
|
||||
|
||||
|
||||
CATCH
|
||||
DISPLAY "Unable to create an enveloped signature :",status," ",sqlca.sqlerrm
|
||||
END TRY
|
||||
|
||||
END FUNCTION
|
||||
|
||||
FUNCTION validasemilla()
|
||||
DEFINE respuesta,codigo STRING,
|
||||
http_req com.HttpRequest,
|
||||
http_resp com.HTTPResponse
|
||||
|
||||
|
||||
LET http_req = com.HTTPRequest.Create(url_validasemilla)
|
||||
|
||||
CALL http_req.setMethod("POST")
|
||||
CALL http_req.setCharset("UTF-8")
|
||||
CALL http_req.setHeader("accept","application/xml")
|
||||
|
||||
|
||||
CALL http_req.setMultipartType("form-data",NULL,NULL)
|
||||
|
||||
IF os.Path.exists(".\\cert\\marmotech\\Signature.xml") THEN
|
||||
|
||||
CALL http_req.setHeader("Content-Disposition", "form-data; name=\"xml\"; filename=\".\\filesXML\\marmotech\\Signature.xml\"")
|
||||
CALL http_req.setTimeOut(15)
|
||||
CALL http_req.doFileRequest(".\\cert\\marmotech\\Signature.xml")
|
||||
ELSE
|
||||
DISPLAY "NO LO ENCUENTRO"
|
||||
RETURN 0,"FILE NO EXISTE"
|
||||
END IF
|
||||
# CALL http_req.setHeader("Content-Disposition", "form-data; name=\"xml\"; filename=\"naceSignature.xml\"")
|
||||
|
||||
# CALL http_req.doFileRequest("naceSignature.xml")
|
||||
|
||||
|
||||
LET http_resp= http_req.getResponse()
|
||||
LET codigo = http_resp.getStatusCode()
|
||||
LET respuesta = http_resp.getTextResponse()
|
||||
|
||||
IF http_resp.getStatusCode() != 200 THEN
|
||||
DISPLAY "error: ",codigo," ", respuesta
|
||||
RETURN codigo, respuesta
|
||||
END IF
|
||||
|
||||
DISPLAY "valida semilla: ",codigo," ", respuesta
|
||||
RETURN codigo, respuesta
|
||||
|
||||
|
||||
END FUNCTION
|
||||
FUNCTION enviafiles(btoken,archivo)
|
||||
DEFINE respuesta,btoken,codigo,archivo,contenido,consultaResp STRING,
|
||||
http_req com.HttpRequest,
|
||||
http_resp com.HTTPResponse
|
||||
|
||||
|
||||
|
||||
LET btoken =" Bearer ",btoken
|
||||
DISPLAY "url ",url_recepcion
|
||||
LET http_req = com.HTTPRequest.Create(url_recepcion)
|
||||
|
||||
CALL http_req.setMethod("POST")
|
||||
CALL http_req.setCharset("UTF-8")
|
||||
CALL http_req.setHeader("accept","application/json")
|
||||
CALL http_req.setHeader("Authorization",btoken)
|
||||
|
||||
CALL http_req.setMultipartType("form-data",NULL,NULL)
|
||||
|
||||
# "form-data; name=\"xml\"; filename=\"naceSignature.xml\""
|
||||
# LET archivo = "101521262E310000000001.xml"
|
||||
|
||||
IF os.Path.exists(archivo) THEN
|
||||
DISPLAY "archivo: ",archivo
|
||||
LET contenido = "form-data; name=\"xml\"; filename=",os.path.basename(archivo)
|
||||
#CALL http_req.setHeader("Content-Disposition", "form-data; name=\"xml\"; filename=\"130337391E310000000005.XML\"")
|
||||
|
||||
CALL http_req.setHeader("Content-Disposition", contenido)
|
||||
# CALL http_req.setHeader("Content-Disposition", "form-data; name=\"xml\"; filename=\"130337391E310000000016.xml\"")
|
||||
CALL http_req.doFileRequest(archivo)
|
||||
|
||||
LET http_resp= http_req.getResponse()
|
||||
LET codigo = http_resp.getStatusCode()
|
||||
LET respuesta= http_resp.getTextResponse()
|
||||
|
||||
IF http_resp.getStatusCode() != 200 THEN
|
||||
DISPLAY "error: ",codigo," ", respuesta
|
||||
RETURN codigo, respuesta
|
||||
END IF
|
||||
|
||||
ELSE
|
||||
|
||||
RETURN 0,"FILE NO EXISTE"
|
||||
END IF
|
||||
# CALL http_req.setHeader("Content-Disposition", "form-data; name=\"xml\"; filename=\"naceSignature.xml\"")
|
||||
|
||||
# CALL http_req.doFileRequest("naceSignature.xml")
|
||||
|
||||
DISPLAY "enviafile: ",codigo," ", respuesta
|
||||
IF ptipoRecepcion <> "aprobacion" THEN
|
||||
CALL consultaResultado(btoken,respuesta) RETURNING consultaResp
|
||||
DISPLAY "responde consulta: ",consultaResp
|
||||
END IF
|
||||
RETURN codigo, respuesta
|
||||
|
||||
|
||||
END FUNCTION
|
||||
|
||||
FUNCTION gettoken()
|
||||
DEFINE i, l INTEGER
|
||||
DEFINE r om.XmlReader
|
||||
DEFINE e,tok String
|
||||
DEFINE a om.SaxAttributes
|
||||
DISPLAY "filexml: ",filexml
|
||||
LET r = om.XmlReader.createFileReader(".\\filesXML\\marmotech\\RespuestaValida.xml")
|
||||
LET l = 0
|
||||
LET e = r.read()
|
||||
|
||||
WHILE e IS NOT NULL
|
||||
CASE e
|
||||
WHEN "StartDocument"
|
||||
# DISPLAY "StartDocument:"
|
||||
WHEN "StartElement"
|
||||
LET l=l+1
|
||||
#DISPLAY l SPACES, "StartElement:", r.getTagName()
|
||||
LET a = r.getAttributes()
|
||||
FOR i=1 to a.getLength()
|
||||
IF a.getName(i) = "token" THEN
|
||||
# DISPLAY l SPACES," ",
|
||||
# a.getName(i)," = ",
|
||||
# a.getValueByIndex(i)
|
||||
END IF
|
||||
END FOR
|
||||
WHEN "Characters"
|
||||
|
||||
|
||||
IF r.getTagName() = "token" THEN
|
||||
LET tok = r.getCharacters()
|
||||
# DISPLAY "token dentro de gettoken: ",tok
|
||||
EXIT CASE
|
||||
END IF
|
||||
WHEN "SkippedEntity"
|
||||
# DISPLAY "Entity:'",r.skippedEntity(),"'"
|
||||
WHEN "EndElement"
|
||||
# DISPLAY l SPACES, "EndElement:", r.getTagName()
|
||||
LET l=l-1
|
||||
WHEN "EndDocument"
|
||||
# DISPLAY "EndDocument:"
|
||||
OTHERWISE
|
||||
# DISPLAY "Invalid event: ",e
|
||||
END CASE
|
||||
LET e=r.read()
|
||||
END WHILE
|
||||
RETURN tok
|
||||
END FUNCTION
|
||||
|
||||
FUNCTION buscatoken()
|
||||
|
||||
DEFINE respuesta STRING,
|
||||
http_req com.HttpRequest,
|
||||
http_resp com.HTTPResponse
|
||||
|
||||
#SELECT a.urltoken INTO url FROM companias a
|
||||
#"https://ecf.dgii.gov.do/testecf/autenticacion/api/autenticacion/semilla"
|
||||
#"https://ecf.dgii.gov.do/CerteCF/Autenticacion/api/Autenticacion/Semilla"
|
||||
|
||||
|
||||
LET http_req = com.HTTPRequest.Create(url_semilla)
|
||||
|
||||
CALL http_req.setMethod("GET")
|
||||
CALL http_req.setCharset("UTF-8")
|
||||
CALL http_req.setHeader("accept","application/xml")
|
||||
CALL http_req.doRequest()
|
||||
#CALL http_req.doTextRequest(url)
|
||||
|
||||
LET http_resp= http_req.getResponse()
|
||||
|
||||
IF http_resp.getStatusCode() != 200 THEN
|
||||
RETURN http_resp.getStatusCode(), http_resp.getTextResponse()
|
||||
END IF
|
||||
|
||||
LET respuesta = http_resp.getTextResponse()
|
||||
|
||||
|
||||
RETURN http_resp.getStatusCode(),respuesta
|
||||
END FUNCTION
|
||||
FUNCTION urls()
|
||||
IF xambiente = "produccion" THEN
|
||||
|
||||
IF ptipoRecepcion = "normal" THEN
|
||||
LET url_recepcion ="https://ecf.dgii.gov.do/ecf/Recepcion/api/FacturasElectronicas"
|
||||
ELSE
|
||||
IF ptipoRecepcion = 'consumo' THEN
|
||||
LET url_recepcion ="https://fc.dgii.gov.do/ecf/RecepcionFC/api/Recepcion/ecf"
|
||||
END IF
|
||||
IF ptipoRecepcion = 'anular' THEN
|
||||
LET url_recepcion ="https://ecf.dgii.gov.do/eCF/anulacionrangos/api/operaciones/anularrango"
|
||||
END IF
|
||||
|
||||
END IF
|
||||
DISPLAY "llego a las urls: ",url_recepcion
|
||||
IF ptipoRecepcion = 'normal32' THEN
|
||||
LET url_recepcion ="https://fc.dgii.gov.do/ecf/RecepcionFC/api/Recepcion/ecf"
|
||||
END IF
|
||||
|
||||
LET url_semilla ="https://ecf.dgii.gov.do/ecf/autenticacion/api/autenticacion/semilla"
|
||||
LET url_validasemilla ="https://ecf.dgii.gov.do/ecf/Autenticacion/api/Autenticacion/ValidarSemilla"
|
||||
LET url_consulta = "https://ecf.dgii.gov.do/ecf/ConsultaResultado/api/consultas/estado"
|
||||
|
||||
|
||||
END IF
|
||||
|
||||
|
||||
IF xambiente = "certificacion" THEN
|
||||
|
||||
IF ptipoRecepcion = 'aprobacion' THEN
|
||||
LET url_recepcion ="https://ecf.dgii.gov.do/CerteCF/aprobacioncomercial/api/aprobacioncomercial"
|
||||
END IF
|
||||
IF ptipoRecepcion = "normal" THEN
|
||||
|
||||
LET url_recepcion ="https://ecf.dgii.gov.do/CerteCF/Recepcion/api/FacturasElectronicas"
|
||||
ELSE
|
||||
IF ptipoRecepcion = 'consumo' THEN
|
||||
LET url_recepcion ="https://fc.dgii.gov.do/CerteCF/RecepcionFC/api/Recepcion/ecf"
|
||||
END IF
|
||||
END IF
|
||||
|
||||
IF ptipoRecepcion = 'normal32' THEN
|
||||
LET url_recepcion ="https://fc.dgii.gov.do/CerteCF/RecepcionFC/api/Recepcion/ecf"
|
||||
END IF
|
||||
|
||||
LET url_semilla ="https://ecf.dgii.gov.do/CerteCF/autenticacion/api/autenticacion/semilla"
|
||||
LET url_validasemilla ="https://ecf.dgii.gov.do/CerteCF/Autenticacion/api/Autenticacion/ValidarSemilla"
|
||||
LET url_consulta = "https://ecf.dgii.gov.do/CerteCF/ConsultaResultado/api/consultas/estado"
|
||||
|
||||
END IF
|
||||
|
||||
IF xambiente = "test" THEN
|
||||
|
||||
IF ptipoRecepcion = "normal" THEN
|
||||
LET url_recepcion ="https://ecf.dgii.gov.do/TesteCF/Recepcion/api/FacturasElectronicas"
|
||||
ELSE
|
||||
IF ptipoRecepcion = 'consumo' THEN
|
||||
LET url_recepcion ="https://fc.dgii.gov.do/TesteCF/RecepcionFC/api/Recepcion/ecf"
|
||||
END IF
|
||||
IF ptipoRecepcion = 'anular' THEN
|
||||
LET url_recepcion ="https://ecf.dgii.gov.do/TesteCF/anulacionrangos/api/operaciones/anularrango"
|
||||
END IF
|
||||
END IF
|
||||
|
||||
IF ptipoRecepcion = 'normal32' THEN
|
||||
LET url_recepcion ="https://fc.dgii.gov.do/TesteCF/RecepcionFC/api/Recepcion/ecf"
|
||||
END IF
|
||||
|
||||
LET url_semilla ="https://ecf.dgii.gov.do/TesteCF/autenticacion/api/autenticacion/semilla"
|
||||
LET url_validasemilla ="https://ecf.dgii.gov.do/TesteCF/Autenticacion/api/Autenticacion/ValidarSemilla"
|
||||
LET url_consulta = "https://ecf.dgii.gov.do/TesteCF/ConsultaResultado/api/consultas/estado"
|
||||
|
||||
END IF
|
||||
|
||||
END FUNCTION
|
||||
FUNCTION consultaResultado(ctoken,data)
|
||||
DEFINE data,ctoken STRING
|
||||
|
||||
DEFINE crespuesta STRING,
|
||||
http_req com.HttpRequest,
|
||||
http_resp com.HTTPResponse
|
||||
|
||||
DEFINE dtrackid RECORD
|
||||
trackid,ERROR,mensaje STRING
|
||||
END RECORD
|
||||
|
||||
CALL util.JSON.parse(data,dtrackid)
|
||||
|
||||
DISPLAY "TRACK: ",dtrackid.trackid
|
||||
|
||||
|
||||
#SELECT a.urltoken INTO url FROM companias a
|
||||
#"https://ecf.dgii.gov.do/testecf/autenticacion/api/autenticacion/semilla"
|
||||
#"https://ecf.dgii.gov.do/CerteCF/Autenticacion/api/Autenticacion/Semilla"
|
||||
|
||||
LET url_consulta = url_consulta CLIPPED,"?TrackId=",dtrackid.trackid CLIPPED
|
||||
LET http_req = com.HTTPRequest.Create(url_consulta)
|
||||
|
||||
CALL http_req.setMethod("GET")
|
||||
CALL http_req.setCharset("UTF-8")
|
||||
CALL http_req.setHeader("accept","application/json")
|
||||
CALL http_req.setHeader("Authorization",ctoken)
|
||||
CALL http_req.doRequest()
|
||||
|
||||
|
||||
LET http_resp= http_req.getResponse()
|
||||
LET crespuesta = http_resp.getTextResponse()
|
||||
|
||||
IF http_resp.getStatusCode() != 200 THEN
|
||||
RETURN crespuesta
|
||||
END IF
|
||||
|
||||
|
||||
RETURN crespuesta
|
||||
|
||||
END FUNCTION
|
||||
@@ -0,0 +1,639 @@
|
||||
IMPORT os
|
||||
IMPORT com
|
||||
IMPORT XML
|
||||
IMPORT UTIL
|
||||
|
||||
DEFINE url_semilla,
|
||||
url_validasemilla,
|
||||
url_autorizacion,
|
||||
url_recepcion,
|
||||
url_consulta,
|
||||
xambiente
|
||||
STRING
|
||||
DEFINE codigo,
|
||||
tokenxml,
|
||||
nombreFile,
|
||||
filexml,
|
||||
token,
|
||||
respuesta,
|
||||
ptipoRecepcion,
|
||||
xhash
|
||||
STRING
|
||||
DEFINE doc xml.DomDocument
|
||||
DEFINE ruta, accion, addAnswer STRING
|
||||
|
||||
MAIN
|
||||
|
||||
DEFINE trespuesta STRING
|
||||
|
||||
OPEN WINDOW w1 WITH FORM 'enviafileform'
|
||||
|
||||
INPUT BY NAME accion ATTRIBUTES(UNBUFFERED)
|
||||
|
||||
ON ACTION FileRoute
|
||||
INITIALIZE ruta TO NULL
|
||||
CALL UploadDoc() RETURNING ruta
|
||||
DISPLAY ruta TO ruta
|
||||
|
||||
ON ACTION lesgo
|
||||
|
||||
IF addAnswer IS NOT NULL THEN
|
||||
|
||||
LET trespuesta = addAnswer
|
||||
|
||||
END IF
|
||||
|
||||
CALL procesoencf(
|
||||
ruta CLIPPED,
|
||||
'test',
|
||||
'normal',
|
||||
accion CLIPPED,
|
||||
trespuesta CLIPPED)
|
||||
|
||||
ON ACTION CLOSE
|
||||
END INPUT
|
||||
|
||||
CLOSE WINDOW w1
|
||||
|
||||
-- LET trespuesta = '{"trackId":"cf224fcc-150d-436f-ba05-9610c4792314","codigo":"2","estado":"Rechazado","rnc":"101521262","encf":"E340000000142","secuenciaUtilizada":false,"fechaRecepcion":"3/20/2024 10:12:57 AM","mensajes":[{"valor":"El formato del XML no es válido.","codigo":1}]}'
|
||||
-- CALL procesoencf('.\\filesXML\\101521262E310000001480.xml','produccion','normal','adicionar',trespuesta)
|
||||
|
||||
END MAIN
|
||||
|
||||
FUNCTION procesoEncf(
|
||||
fileporfirmar, ambiente, tiporecepcion, xoperacion, krespuesta)
|
||||
DEFINE fileporfirmar,
|
||||
rtoken,
|
||||
ambiente,
|
||||
tiporecepcion,
|
||||
xoperacion,
|
||||
krespuesta,
|
||||
trrespuesta
|
||||
STRING
|
||||
|
||||
LET ptipoRecepcion = tiporecepcion
|
||||
|
||||
IF ambiente <> "produccion" THEN
|
||||
IF ambiente <> "test" THEN
|
||||
DISPLAY "no llego bien ", ambiente
|
||||
RETURN
|
||||
END IF
|
||||
END IF
|
||||
|
||||
LET xambiente = ambiente
|
||||
CALL urls()
|
||||
|
||||
CALL buscatoken() RETURNING codigo, tokenxml
|
||||
|
||||
IF codigo <> "200" THEN
|
||||
DISPLAY "respuesta buscatoken: ", tokenxml, " ", codigo
|
||||
EXIT PROGRAM
|
||||
END IF
|
||||
|
||||
# Create DomDocument object
|
||||
LET doc = xml.DomDocument.Create()
|
||||
# Notice that whitespaces are significant in cryptography,
|
||||
# therefore it is recommended to remove unnecessary ones
|
||||
CALL doc.setFeature("whitespace-in-element-content", FALSE)
|
||||
|
||||
CALL doc.loadFromString(tokenxml)
|
||||
CALL doc.save(".\\filesXML\\marmotech\\mtechTokenString.xml")
|
||||
|
||||
#FIRMA SEMILLA
|
||||
IF os.Path.exists(".\\filesXML\\marmotech\\mtechTokenString.xml") THEN
|
||||
CALL firmasemilla()
|
||||
ELSE
|
||||
DISPLAY "NO PUDE CREAR SEMILLA"
|
||||
RETURN
|
||||
END IF
|
||||
IF os.Path.exists(".\\filesXML\\marmotech\\mtechSignature.xml") THEN
|
||||
CALL validasemilla() RETURNING codigo, respuesta
|
||||
ELSE
|
||||
DISPLAY "NO ENCONTRE LA SEMILLA FIRMADA"
|
||||
RETURN
|
||||
END IF
|
||||
IF respuesta IS NOT NULL THEN
|
||||
LET doc = xml.DomDocument.Create()
|
||||
|
||||
CALL doc.loadFromString(respuesta)
|
||||
CALL doc.save(".\\filesXMl\\marmotech\\RespuestaValida.xml")
|
||||
|
||||
CALL gettoken() RETURNING rtoken
|
||||
LET token = rtoken
|
||||
ELSE
|
||||
DISPLAY "NO TENEMOS RESPUESTA DE VALIDA SEMILLA"
|
||||
RETURN
|
||||
END IF
|
||||
#FRIMA CON GENERO
|
||||
IF xoperacion <> 'consultatrackid' THEN
|
||||
LET filexml = fileporfirmar
|
||||
CALL firmadocumento(fileporfirmar)
|
||||
LET filexml =
|
||||
'.\\filesXML\\marmotech\\firmados\\', os.Path.baseName(filexml)
|
||||
CALL enviafiles(token, filexml) RETURNING codigo, respuesta
|
||||
ELSE
|
||||
LET token = " Bearer ", token
|
||||
CALL consultaResultado(token, krespuesta) RETURNING trrespuesta
|
||||
DISPLAY "consulta: ", trrespuesta
|
||||
|
||||
--cambios
|
||||
INITIALIZE AddAnswer TO NULL
|
||||
LET AddAnswer = trrespuesta
|
||||
DISPLAY BY NAME addAnswer
|
||||
--end cambios
|
||||
|
||||
END IF
|
||||
|
||||
END FUNCTION
|
||||
FUNCTION firmadocumento(fileafirmar)
|
||||
DEFINE doc xml.DomDocument
|
||||
DEFINE doc2 xml.DomDocument
|
||||
DEFINE root xml.DomNode
|
||||
DEFINE node xml.DomNode
|
||||
DEFINE signNode xml.DomNode
|
||||
|
||||
DEFINE sig xml.Signature
|
||||
DEFINE key xml.CryptoKey
|
||||
DEFINE cert xml.CryptoX509
|
||||
DEFINE
|
||||
index INTEGER,
|
||||
fileafirmar, filefirmado STRING
|
||||
|
||||
# Create DomDocument object
|
||||
LET doc = xml.DomDocument.Create()
|
||||
# Notice that whitespaces are significant in cryptography,
|
||||
# therefore it is recommended to remove unnecessary ones
|
||||
CALL doc.setFeature("whitespace-in-element-content", FALSE)
|
||||
#LET fileafirmar = '.\\filesXML\\marmotech\\originales\\',fileafirmar
|
||||
DISPLAY "file ", fileafirmar
|
||||
LET filexml = fileafirmar
|
||||
|
||||
CALL doc.load(fileafirmar)
|
||||
|
||||
TRY
|
||||
|
||||
# Create rsa key
|
||||
LET key =
|
||||
xml.CryptoKey.Create(
|
||||
"http://www.w3.org/2001/04/xmldsig-more#rsa-sha256")
|
||||
CALL key.loadPEM(".\\cert\\marmotech\\onlyRSA.pem")
|
||||
|
||||
# Create an X509 certificate with the constructor of the CryptoX509 class.
|
||||
LET cert = xml.CryptoX509.Create()
|
||||
CALL cert.setFeature("X509Certificate", TRUE)
|
||||
|
||||
# Load the X509 certificate associated to the RSA or DSA private key into the CryptoKey object.
|
||||
# CALL cert.loadPEM("cert509.crt")
|
||||
CALL cert.loadPEM(".\\cert\\marmotech\\onlyCert.pem")
|
||||
# Create signature object with the key to use
|
||||
LET sig = xml.Signature.Create()
|
||||
# Assign the CryptoKey object to the Signature object.
|
||||
CALL sig.setKey(KEY)
|
||||
|
||||
# Assign the CryptoX509 object to the Signature object.
|
||||
CALL sig.setCertificate(cert)
|
||||
|
||||
# Set XML node to be signed. In our case, the entire document
|
||||
# LET index = sig.createReference("",
|
||||
# "http://www.w3.org/2001/04/xmlenc#sha256")
|
||||
LET index =
|
||||
sig.createReference('""', "http://www.w3.org/2001/04/xmlenc#sha256")
|
||||
|
||||
# Add enveloped method to not take the XML signature node into account
|
||||
# when computing the entire document.
|
||||
CALL sig.appendReferenceTransformation(
|
||||
index,
|
||||
"http://www.w3.org/2000/09/xmldsig#enveloped-signature",
|
||||
doc.getDocumentElement())
|
||||
# Set canonicalization method on the XML fragment to be signed.
|
||||
# CALL sig.appendReferenceTransformation(index,
|
||||
# "http://www.w3.org/2001/10/xml-exc-c14n#")
|
||||
# Compute enveloped signature
|
||||
CALL sig.compute(doc)
|
||||
# Retrieve signature document
|
||||
LET doc2 = sig.getDocument()
|
||||
# Append the signature node to the original document to get
|
||||
# a valid enveloped signature
|
||||
# Notice that the enveloped signature can be added anywhere in the
|
||||
# original document
|
||||
LET signNode = doc2.getDocumentElement() # Get Signature node
|
||||
# Import it into the original document
|
||||
LET node = doc.importNode(signNode, TRUE)
|
||||
# Retrieve the original document root node
|
||||
LET root = doc.getDocumentElement()
|
||||
|
||||
# Append the signature node as last child of the original document
|
||||
CALL root.appendChild(node)
|
||||
# Save document with enveloped signature back to disk
|
||||
CALL doc.setFeature("format-pretty-print", TRUE)
|
||||
LET filefirmado =
|
||||
'.\\filesXML\\marmotech\\firmados\\', os.Path.baseName(fileafirmar)
|
||||
CALL doc.save(filefirmado)
|
||||
|
||||
CATCH
|
||||
DISPLAY "Unable to create an enveloped signature :",
|
||||
status,
|
||||
" ",
|
||||
sqlca.sqlerrm
|
||||
END TRY
|
||||
|
||||
END FUNCTION
|
||||
FUNCTION firmasemilla()
|
||||
DEFINE doc xml.DomDocument
|
||||
DEFINE doc2 xml.DomDocument
|
||||
DEFINE root xml.DomNode
|
||||
DEFINE node xml.DomNode
|
||||
DEFINE signNode xml.DomNode
|
||||
|
||||
DEFINE sig xml.Signature
|
||||
DEFINE key xml.CryptoKey
|
||||
DEFINE cert xml.CryptoX509
|
||||
DEFINE index INTEGER
|
||||
|
||||
# Create DomDocument object
|
||||
LET doc = xml.DomDocument.Create()
|
||||
# Notice that whitespaces are significant in cryptography,
|
||||
# therefore it is recommended to remove unnecessary ones
|
||||
CALL doc.setFeature("whitespace-in-element-content", FALSE)
|
||||
|
||||
LET filexml = ".\\filesXML\\marmotech\\mtechTokenString.xml"
|
||||
|
||||
IF os.Path.exists(filexml) THEN
|
||||
CALL doc.load(filexml)
|
||||
ELSE
|
||||
DISPLAY "NO LO ENCONTRE"
|
||||
RETURN
|
||||
END IF
|
||||
TRY
|
||||
|
||||
# Create rsa key
|
||||
LET key =
|
||||
xml.CryptoKey.Create(
|
||||
"http://www.w3.org/2001/04/xmldsig-more#rsa-sha256")
|
||||
CALL key.loadPEM(".\\cert\\marmotech\\onlyRSA.pem")
|
||||
|
||||
# Create an X509 certificate with the constructor of the CryptoX509 class.
|
||||
LET cert = xml.CryptoX509.Create()
|
||||
CALL cert.setFeature("X509Certificate", TRUE)
|
||||
|
||||
# Load the X509 certificate associated to the RSA or DSA private key into the CryptoKey object.
|
||||
# CALL cert.loadPEM("cert509.crt")
|
||||
CALL cert.loadPEM(".\\cert\\marmotech\\onlyCert.pem")
|
||||
# Create signature object with the key to use
|
||||
LET sig = xml.Signature.Create()
|
||||
# Assign the CryptoKey object to the Signature object.
|
||||
CALL sig.setKey(KEY)
|
||||
|
||||
# Assign the CryptoX509 object to the Signature object.
|
||||
CALL sig.setCertificate(cert)
|
||||
|
||||
# Set XML node to be signed. In our case, the entire document
|
||||
# LET index = sig.createReference("",
|
||||
# "http://www.w3.org/2001/04/xmlenc#sha256")
|
||||
LET index =
|
||||
sig.createReference('""', "http://www.w3.org/2001/04/xmlenc#sha256")
|
||||
|
||||
# Add enveloped method to not take the XML signature node into account
|
||||
# when computing the entire document.
|
||||
CALL sig.appendReferenceTransformation(
|
||||
index,
|
||||
"http://www.w3.org/2000/09/xmldsig#enveloped-signature",
|
||||
doc.getDocumentElement())
|
||||
# Set canonicalization method on the XML fragment to be signed.
|
||||
# CALL sig.appendReferenceTransformation(index,
|
||||
# "http://www.w3.org/2001/10/xml-exc-c14n#")
|
||||
# Compute enveloped signature
|
||||
CALL sig.compute(doc)
|
||||
# Retrieve signature document
|
||||
LET doc2 = sig.getDocument()
|
||||
# Append the signature node to the original document to get
|
||||
# a valid enveloped signature
|
||||
# Notice that the enveloped signature can be added anywhere in the
|
||||
# original document
|
||||
LET signNode = doc2.getDocumentElement() # Get Signature node
|
||||
# Import it into the original document
|
||||
LET node = doc.importNode(signNode, TRUE)
|
||||
# Retrieve the original document root node
|
||||
LET root = doc.getDocumentElement()
|
||||
|
||||
# Append the signature node as last child of the original document
|
||||
CALL root.appendChild(node)
|
||||
# Save document with enveloped signature back to disk
|
||||
CALL doc.setFeature("format-pretty-print", TRUE)
|
||||
CALL doc.save(".\\filesXML\\marmotech\\mtechSignature.xml")
|
||||
|
||||
CATCH
|
||||
DISPLAY "Unable to create an enveloped signature :",
|
||||
status,
|
||||
" ",
|
||||
sqlca.sqlerrm
|
||||
END TRY
|
||||
|
||||
END FUNCTION
|
||||
|
||||
FUNCTION validasemilla()
|
||||
DEFINE
|
||||
respuesta, codigo STRING,
|
||||
http_req com.HttpRequest,
|
||||
http_resp com.HTTPResponse
|
||||
|
||||
LET http_req = com.HTTPRequest.Create(url_validasemilla)
|
||||
|
||||
CALL http_req.setMethod("POST")
|
||||
CALL http_req.setCharset("UTF-8")
|
||||
CALL http_req.setHeader("accept", "application/xml")
|
||||
CALL http_req.setMultipartType("form-data", NULL, NULL)
|
||||
|
||||
IF os.Path.exists(".\\filesXML\\marmotech\\mtechSignature.xml") THEN
|
||||
|
||||
CALL http_req.setHeader(
|
||||
"Content-Disposition",
|
||||
"form-data; name=\"xml\"; filename=\".\\filesXML\\marmotech\\mtechSignature.xml\"")
|
||||
|
||||
CALL http_req.doFileRequest(
|
||||
".\\filesXML\\marmotech\\mtechSignature.xml")
|
||||
ELSE
|
||||
DISPLAY "NO LO ENCUENTRO"
|
||||
RETURN 0, "FILE NO EXISTE"
|
||||
END IF
|
||||
# CALL http_req.setHeader("Content-Disposition", "form-data; name=\"xml\"; filename=\"naceSignature.xml\"")
|
||||
|
||||
# CALL http_req.doFileRequest("naceSignature.xml")
|
||||
|
||||
LET http_resp = http_req.getResponse()
|
||||
LET codigo = http_resp.getStatusCode()
|
||||
LET respuesta = http_resp.getTextResponse()
|
||||
|
||||
IF http_resp.getStatusCode() != 200 THEN
|
||||
DISPLAY "error: ", codigo, " ", respuesta
|
||||
RETURN codigo, respuesta
|
||||
END IF
|
||||
|
||||
DISPLAY "valida semilla: ", codigo, " ", respuesta
|
||||
RETURN codigo, respuesta
|
||||
|
||||
END FUNCTION
|
||||
FUNCTION enviafiles(btoken, archivo)
|
||||
DEFINE
|
||||
respuesta, btoken, codigo, archivo, contenido, consultaResp STRING,
|
||||
http_req com.HttpRequest,
|
||||
http_resp com.HTTPResponse
|
||||
|
||||
LET btoken = " Bearer ", btoken
|
||||
DISPLAY "url ", url_recepcion
|
||||
LET http_req = com.HTTPRequest.Create(url_recepcion)
|
||||
|
||||
CALL http_req.setMethod("POST")
|
||||
CALL http_req.setCharset("UTF-8")
|
||||
CALL http_req.setHeader("accept", "application/json")
|
||||
CALL http_req.setHeader("Authorization", btoken)
|
||||
|
||||
CALL http_req.setMultipartType("form-data", NULL, NULL)
|
||||
|
||||
# "form-data; name=\"xml\"; filename=\"naceSignature.xml\""
|
||||
# LET archivo = "101521262E310000000001.xml"
|
||||
|
||||
IF os.Path.exists(archivo) THEN
|
||||
DISPLAY "archivo: ", archivo
|
||||
LET contenido =
|
||||
"form-data; name=\"xml\"; filename=", os.path.basename(archivo)
|
||||
#CALL http_req.setHeader("Content-Disposition", "form-data; name=\"xml\"; filename=\"130337391E310000000005.XML\"")
|
||||
|
||||
CALL http_req.setHeader("Content-Disposition", contenido)
|
||||
# CALL http_req.setHeader("Content-Disposition", "form-data; name=\"xml\"; filename=\"130337391E310000000016.xml\"")
|
||||
CALL http_req.doFileRequest(archivo)
|
||||
|
||||
LET http_resp = http_req.getResponse()
|
||||
LET codigo = http_resp.getStatusCode()
|
||||
LET respuesta = http_resp.getTextResponse()
|
||||
|
||||
IF http_resp.getStatusCode() != 200 THEN
|
||||
DISPLAY "error: ", codigo, " ", respuesta
|
||||
RETURN codigo, respuesta
|
||||
END IF
|
||||
|
||||
ELSE
|
||||
|
||||
RETURN 0, "FILE NO EXISTE"
|
||||
END IF
|
||||
# CALL http_req.setHeader("Content-Disposition", "form-data; name=\"xml\"; filename=\"naceSignature.xml\"")
|
||||
|
||||
# CALL http_req.doFileRequest("naceSignature.xml")
|
||||
|
||||
DISPLAY "enviafile: ", codigo, " ", respuesta
|
||||
IF ptipoRecepcion <> "aprobacion" THEN
|
||||
CALL consultaResultado(btoken, respuesta) RETURNING consultaResp
|
||||
--cambios
|
||||
INITIALIZE AddAnswer TO NULL
|
||||
LET AddAnswer = consultaResp
|
||||
DISPLAY AddAnswer TO addAnswer
|
||||
--end cambios
|
||||
DISPLAY "responde consulta: ", consultaResp
|
||||
END IF
|
||||
RETURN codigo, respuesta
|
||||
|
||||
END FUNCTION
|
||||
|
||||
FUNCTION gettoken()
|
||||
DEFINE i, l INTEGER
|
||||
DEFINE r om.XmlReader
|
||||
DEFINE e, tok STRING
|
||||
DEFINE a om.SaxAttributes
|
||||
DISPLAY "filexml: ", filexml
|
||||
LET r =
|
||||
om.XmlReader.createFileReader(
|
||||
".\\filesXML\\marmotech\\RespuestaValida.xml")
|
||||
LET l = 0
|
||||
LET e = r.read()
|
||||
|
||||
WHILE e IS NOT NULL
|
||||
CASE e
|
||||
WHEN "StartDocument"
|
||||
# DISPLAY "StartDocument:"
|
||||
WHEN "StartElement"
|
||||
LET l = l + 1
|
||||
#DISPLAY l SPACES, "StartElement:", r.getTagName()
|
||||
LET a = r.getAttributes()
|
||||
FOR i = 1 TO a.getLength()
|
||||
IF a.getName(i) = "token" THEN
|
||||
# DISPLAY l SPACES," ",
|
||||
# a.getName(i)," = ",
|
||||
# a.getValueByIndex(i)
|
||||
END IF
|
||||
END FOR
|
||||
WHEN "Characters"
|
||||
|
||||
IF r.getTagName() = "token" THEN
|
||||
LET tok = r.getCharacters()
|
||||
# DISPLAY "token dentro de gettoken: ",tok
|
||||
EXIT CASE
|
||||
END IF
|
||||
WHEN "SkippedEntity"
|
||||
# DISPLAY "Entity:'",r.skippedEntity(),"'"
|
||||
WHEN "EndElement"
|
||||
# DISPLAY l SPACES, "EndElement:", r.getTagName()
|
||||
LET l = l - 1
|
||||
WHEN "EndDocument"
|
||||
# DISPLAY "EndDocument:"
|
||||
OTHERWISE
|
||||
# DISPLAY "Invalid event: ",e
|
||||
END CASE
|
||||
LET e = r.read()
|
||||
END WHILE
|
||||
RETURN tok
|
||||
END FUNCTION
|
||||
|
||||
FUNCTION buscatoken()
|
||||
|
||||
DEFINE
|
||||
respuesta STRING,
|
||||
http_req com.HttpRequest,
|
||||
http_resp com.HTTPResponse
|
||||
|
||||
#SELECT a.urltoken INTO url FROM companias a
|
||||
#"https://ecf.dgii.gov.do/testecf/autenticacion/api/autenticacion/semilla"
|
||||
#"https://ecf.dgii.gov.do/CerteCF/Autenticacion/api/Autenticacion/Semilla"
|
||||
|
||||
LET http_req = com.HTTPRequest.Create(url_semilla)
|
||||
|
||||
CALL http_req.setMethod("GET")
|
||||
CALL http_req.setCharset("UTF-8")
|
||||
CALL http_req.setHeader("accept", "application/xml")
|
||||
CALL http_req.doRequest()
|
||||
#CALL http_req.doTextRequest(url)
|
||||
|
||||
LET http_resp = http_req.getResponse()
|
||||
|
||||
IF http_resp.getStatusCode() != 200 THEN
|
||||
RETURN http_resp.getStatusCode(), http_resp.getTextResponse()
|
||||
END IF
|
||||
|
||||
LET respuesta = http_resp.getTextResponse()
|
||||
|
||||
RETURN http_resp.getStatusCode(), respuesta
|
||||
END FUNCTION
|
||||
FUNCTION urls()
|
||||
IF xambiente = "produccion" THEN
|
||||
|
||||
IF ptipoRecepcion = "normal" THEN
|
||||
LET url_recepcion =
|
||||
"https://ecf.dgii.gov.do/ecf/Recepcion/api/FacturasElectronicas"
|
||||
ELSE
|
||||
IF ptipoRecepcion = 'consumo' THEN
|
||||
LET url_recepcion =
|
||||
"https://fc.dgii.gov.do/ecf/RecepcionFC/api/Recepcion/ecf"
|
||||
END IF
|
||||
END IF
|
||||
|
||||
IF ptipoRecepcion = 'normal32' THEN
|
||||
LET url_recepcion =
|
||||
"https://fc.dgii.gov.do/ecf/RecepcionFC/api/Recepcion/ecf"
|
||||
END IF
|
||||
|
||||
LET url_semilla =
|
||||
"https://ecf.dgii.gov.do/ecf/autenticacion/api/autenticacion/semilla"
|
||||
LET url_validasemilla =
|
||||
"https://ecf.dgii.gov.do/ecf/Autenticacion/api/Autenticacion/ValidarSemilla"
|
||||
LET url_consulta =
|
||||
"https://ecf.dgii.gov.do/ecf/ConsultaResultado/api/consultas/estado"
|
||||
|
||||
END IF
|
||||
|
||||
IF xambiente = "certificacion" THEN
|
||||
|
||||
IF ptipoRecepcion = 'aprobacion' THEN
|
||||
LET url_recepcion =
|
||||
"https://ecf.dgii.gov.do/CerteCF/aprobacioncomercial/api/aprobacioncomercial"
|
||||
END IF
|
||||
IF ptipoRecepcion = "normal" THEN
|
||||
|
||||
LET url_recepcion =
|
||||
"https://ecf.dgii.gov.do/CerteCF/Recepcion/api/FacturasElectronicas"
|
||||
ELSE
|
||||
IF ptipoRecepcion = 'consumo' THEN
|
||||
LET url_recepcion =
|
||||
"https://fc.dgii.gov.do/CerteCF/RecepcionFC/api/Recepcion/ecf"
|
||||
END IF
|
||||
END IF
|
||||
|
||||
IF ptipoRecepcion = 'normal32' THEN
|
||||
LET url_recepcion =
|
||||
"https://fc.dgii.gov.do/CerteCF/RecepcionFC/api/Recepcion/ecf"
|
||||
END IF
|
||||
|
||||
LET url_semilla =
|
||||
"https://ecf.dgii.gov.do/CerteCF/autenticacion/api/autenticacion/semilla"
|
||||
LET url_validasemilla =
|
||||
"https://ecf.dgii.gov.do/CerteCF/Autenticacion/api/Autenticacion/ValidarSemilla"
|
||||
LET url_consulta =
|
||||
"https://ecf.dgii.gov.do/CerteCF/ConsultaResultado/api/consultas/estado"
|
||||
|
||||
END IF
|
||||
|
||||
IF xambiente = "test" THEN
|
||||
|
||||
IF ptipoRecepcion = "normal" THEN
|
||||
LET url_recepcion =
|
||||
"https://ecf.dgii.gov.do/TesteCF/Recepcion/api/FacturasElectronicas"
|
||||
ELSE
|
||||
IF ptipoRecepcion = 'consumo' THEN
|
||||
LET url_recepcion =
|
||||
"https://fc.dgii.gov.do/TesteCF/RecepcionFC/api/Recepcion/ecf"
|
||||
END IF
|
||||
END IF
|
||||
|
||||
IF ptipoRecepcion = 'normal32' THEN
|
||||
LET url_recepcion =
|
||||
"https://fc.dgii.gov.do/TesteCF/RecepcionFC/api/Recepcion/ecf"
|
||||
END IF
|
||||
|
||||
LET url_semilla =
|
||||
"https://ecf.dgii.gov.do/TesteCF/autenticacion/api/autenticacion/semilla"
|
||||
LET url_validasemilla =
|
||||
"https://ecf.dgii.gov.do/TesteCF/Autenticacion/api/Autenticacion/ValidarSemilla"
|
||||
LET url_consulta =
|
||||
"https://ecf.dgii.gov.do/TesteCF/ConsultaResultado/api/consultas/estado"
|
||||
|
||||
END IF
|
||||
|
||||
END FUNCTION
|
||||
FUNCTION consultaResultado(ctoken, data)
|
||||
DEFINE data, ctoken STRING
|
||||
|
||||
DEFINE
|
||||
crespuesta STRING,
|
||||
http_req com.HttpRequest,
|
||||
http_resp com.HTTPResponse
|
||||
|
||||
DEFINE dtrackid RECORD
|
||||
trackid, ERROR, mensaje STRING
|
||||
END RECORD
|
||||
|
||||
CALL util.JSON.parse(data, dtrackid)
|
||||
|
||||
DISPLAY "TRACK: ", dtrackid.trackid
|
||||
|
||||
#SELECT a.urltoken INTO url FROM companias a
|
||||
#"https://ecf.dgii.gov.do/testecf/autenticacion/api/autenticacion/semilla"
|
||||
#"https://ecf.dgii.gov.do/CerteCF/Autenticacion/api/Autenticacion/Semilla"
|
||||
|
||||
LET url_consulta =
|
||||
url_consulta CLIPPED, "?TrackId=", dtrackid.trackid CLIPPED
|
||||
LET http_req = com.HTTPRequest.Create(url_consulta)
|
||||
|
||||
CALL http_req.setMethod("GET")
|
||||
CALL http_req.setCharset("UTF-8")
|
||||
CALL http_req.setHeader("accept", "application/json")
|
||||
CALL http_req.setHeader("Authorization", ctoken)
|
||||
CALL http_req.doRequest()
|
||||
|
||||
LET http_resp = http_req.getResponse()
|
||||
LET crespuesta = http_resp.getTextResponse()
|
||||
|
||||
IF http_resp.getStatusCode() != 200 THEN
|
||||
RETURN crespuesta
|
||||
END IF
|
||||
|
||||
RETURN crespuesta
|
||||
|
||||
END FUNCTION
|
||||
@@ -0,0 +1,31 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<ManagedForm fileVersion="31400" gstVersion="3140a" name="managedform" uid="{badb86d7-5f8f-450c-93df-68bd93c3cd4d}">
|
||||
<AGSettings>
|
||||
<DynamicProperties version="2"/>
|
||||
</AGSettings>
|
||||
<Record name="record1" uid="{9452e4f6-d1f9-4d3f-b060-ce6551427996}">
|
||||
<RecordField fieldIdRef="1" name="ruta" uid="{c33d7fc8-f1af-458b-ac8e-5a894248ba0a}"/>
|
||||
<RecordField fieldIdRef="3" name="accion" uid="{95d9e81b-88b3-400c-a067-cd6b2f1afcb3}"/>
|
||||
<RecordField fieldIdRef="2" name="addAnswer" uid="{103ace7e-0556-4fb2-9482-ffb934c2f5d8}"/>
|
||||
</Record>
|
||||
<Form gridHeight="25" gridWidth="80" name="form" text="Form">
|
||||
<Grid gridHeight="17" gridWidth="60" name="grid1" posX="7" posY="1">
|
||||
<Group gridHeight="6" gridWidth="58" name="group1" posX="1" posY="1" text="">
|
||||
<Button gridHeight="1" gridWidth="13" name="FileRoute" posX="1" posY="2" sizePolicy="fixed" tabIndex="-1" text="BUSCAR XML FILE"/>
|
||||
<Edit fieldId="1" gridHeight="1" gridWidth="41" name="ruta" noEntry="true" posX="16" posY="2" scroll="true" sizePolicy="fixed" tabIndex="-1" title="fflabel1" widget="Edit"/>
|
||||
<Label gridHeight="1" gridWidth="12" justify="center" name="label1" posX="1" posY="4" text="TRACKID"/>
|
||||
<Edit fieldId="2" gridHeight="1" gridWidth="41" name="addAnswer" noEntry="true" posX="16" posY="4" scroll="true" sizePolicy="fixed" tabIndex="-1" title="edit1" widget="Edit"/>
|
||||
</Group>
|
||||
<Group gridHeight="6" gridWidth="37" name="group2" posX="11" posY="9" text="">
|
||||
<RadioGroup fieldId="3" gridHeight="4" gridWidth="20" items="ENVIAR A LA DGII, CONSULTAR TRACK ID" name="accion" posX="1" posY="1" sizePolicy="fixed" tabIndex="-1" title="radiogroup1" widget="RadioGroup">
|
||||
<Item lstrtext="false" name="adicionar" text="ENVIAR A LA DGII"/>
|
||||
<Item lstrtext="false" name="consultatrackid" text="CONSULTAR TRACK ID"/>
|
||||
</RadioGroup>
|
||||
<Button gridHeight="1" gridWidth="7" name="lesgo" posX="26" posY="3" sizePolicy="fixed" tabIndex="-1" text="GO"/>
|
||||
</Group>
|
||||
</Grid>
|
||||
</Form>
|
||||
<DiagramLayout>
|
||||
<![CDATA[AAAAAgAAAEwAewA5ADQANQAyAGUANABmADYALQBkADEAZgA5AC0ANABkADMAZgAtAGIAMAA2ADAALQBjAGUANgA1ADUAMQA0ADIANwA5ADkANgB9AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQ==]]>
|
||||
</DiagramLayout>
|
||||
</ManagedForm>
|
||||
Reference in New Issue
Block a user