viernes, 27 de mayo de 2022

FirmaSat Sellado

 
///*******************************************************************************************

sPassword         is string
sMiCertificado     is string
sMiLlave         is string

sMiArchivo1        is string
sMiArchivo2     is string

sMiXMLSellado is string


nOpcion         is int = 0
nResultado         is int
sP2buf             is string = Charact(0)
sPbuf             is string = Charact(0)
hInst             is system int
nLongitud         is int = 4096
nL2ongitud         is int = 20



HReadSeekFirst(DB_Sat,Consecutivo,1,hGeneric)
IF HFound(DB_Sat) = True THEN
    sPassword = DB_Sat.Contraseña
    fSaveBuffer(fTempDir() + DB_Sat.CertificadoNombre  + ".cer", DB_Sat.Certificado)
    fSaveBuffer(fTempDir() + DB_Sat.LlaveNombre        + ".key", DB_Sat.Llave)
    sMiCertificado     = fTempDir() +  DB_Sat.CertificadoNombre + ".cer"
    sMiLlave         = fTempDir() +  DB_Sat.LlaveNombre       + ".key"
END


HReadSeekFirst(DB_Cfdi,IdDB_Cfdi,gsIdDB_Cfdi,hGeneric)
IF HFound(DB_Cfdi) = True THEN
    fSaveBuffer(fTempDir() + "\" + DB_Cfdi.IdDB_Cfdi + ".xml", DB_Cfdi.Contenido)
    sMiArchivo1        = fTempDir() + "\" + DB_Cfdi.IdDB_Cfdi + ".xml"
    sMiArchivo2     = fTempDir() + "\" + "Se" + DB_Cfdi.IdDB_Cfdi + ".xml"
END


hInst             = LoadDLL("diFirmaSAT2.DLL")

IF hInst         = 0 THEN
    Error("Error al cargar dll para colocar sello en el XML")
ELSE
    nResultado = CallDLL32("diFirmaSAT2", "SAT_ValidateXml", sMiArchivo1, nOpcion)
    IF nResultado <> 0 THEN
        Info("ERROR", "SAT_ValidateXML regresa el valor: " + nResultado + " fallidamente")
    ELSE
        nResultado = CallDLL32("diFirmaSAT2", "SAT_SignXml", sMiArchivo2, sMiArchivo1, sMiLlave,sPassword,sMiCertificado,nOpcion)
        IF nResultado <> 0 THEN
            Info("ERROR AL SELLAR EL XML","RESULTADO :" + nResultado)
            
        ELSE
            nResultado = CallDLL32("diFirmaSAT2", "SAT_VerifySignature", sMiArchivo2, sP2buf,nOpcion)
            IF nResultado <> 0 THEN
                Info("Verificación Fallida de Firma" + sMiArchivo2, "returns: " + nResultado)
            ELSE
                sMiXMLSellado = fLoadBuffer(sMiArchivo2)    
            END
        END
    END
    FreeDLL(hInst)
END

RESULT sMiXMLSellado

No hay comentarios.:

Publicar un comentario

Try catch end

 // -------------------------------------------------- // Procedure principal que executa uma query com tratamento de exceção // -----------...