FTP | CCD | Buscar | Trucos | Trabajo | Foros |
|
Registrarse | FAQ | Miembros | Calendario | Guía de estilo | Temas de Hoy |
|
Herramientas | Buscar en Tema | Desplegado |
|
#1
|
||||
|
||||
Loados los hados del VB6
Cita:
aquí estoy .... Saludos y gracias de antemano |
#2
|
|||
|
|||
Cita:
Código:
Attribute VB_Name = "TicketBAI" Option Explicit Public Function GenerarXMLTbai() '(ejercicio As Integer, serie As String, factura As Long) As Boolean Dim success As Long Dim rsFactura As Recordset Dim sSQL As String success = 1 ' Create the XML to be signed... Dim xmlToSign As New ChilkatXml xmlToSign.Tag = "T:TicketBai" success = xmlToSign.AddAttribute("xmlns:T", "urn:ticketbai:emision") xmlToSign.UpdateChildContent "Cabecera|IDVersionTBAI", "1.2" xmlToSign.UpdateChildContent "Sujetos|Emisor|NIF", "B00000034" xmlToSign.UpdateChildContent "Sujetos|Emisor|ApellidosNombreRazonSocial", "HOTEL ADIBIDEZ" xmlToSign.UpdateChildContent "Sujetos|Destinatarios|IDDestinatario|NIF", "B26248146" xmlToSign.UpdateChildContent "Sujetos|Destinatarios|IDDestinatario|ApellidosNombreRazonSocial", "EMPRESA LANTEGIA" xmlToSign.UpdateChildContent "Factura|CabeceraFactura|SerieFactura", "B2022" xmlToSign.UpdateChildContent "Factura|CabeceraFactura|NumFactura", "0100" xmlToSign.UpdateChildContent "Factura|CabeceraFactura|FechaExpedicionFactura", "30-01-2021" xmlToSign.UpdateChildContent "Factura|CabeceraFactura|HoraExpedicionFactura", "18:00:17" xmlToSign.UpdateChildContent "Factura|DatosFactura|DescripcionFactura", "Servicios Hotel" xmlToSign.UpdateChildContent "Factura|DatosFactura|DetallesFactura|IDDetalleFactura|DescripcionDetalle", "" xmlToSign.UpdateChildContent "Factura|DatosFactura|DetallesFactura|IDDetalleFactura|Cantidad", "1" xmlToSign.UpdateChildContent "Factura|DatosFactura|DetallesFactura|IDDetalleFactura|ImporteUnitario", "55" xmlToSign.UpdateChildContent "Factura|DatosFactura|DetallesFactura|IDDetalleFactura|Descuento", "0" xmlToSign.UpdateChildContent "Factura|DatosFactura|DetallesFactura|IDDetalleFactura|ImporteTotal", "66.55" xmlToSign.UpdateChildContent "Factura|DatosFactura|ImporteTotalFactura", "66.55" xmlToSign.UpdateChildContent "Factura|DatosFactura|Claves|IDClave|ClaveRegimenIvaOpTrascendencia", "01" xmlToSign.UpdateChildContent "Factura|TipoDesglose|DesgloseFactura|Sujeta|NoExenta|DetalleNoExenta|TipoNoExenta", "S1" xmlToSign.UpdateChildContent "Factura|TipoDesglose|DesgloseFactura|Sujeta|NoExenta|DetalleNoExenta|DesgloseIVA|DetalleIVA|BaseImponible", "55.00" xmlToSign.UpdateChildContent "Factura|TipoDesglose|DesgloseFactura|Sujeta|NoExenta|DetalleNoExenta|DesgloseIVA|DetalleIVA|TipoImpositivo", "21.00" xmlToSign.UpdateChildContent "Factura|TipoDesglose|DesgloseFactura|Sujeta|NoExenta|DetalleNoExenta|DesgloseIVA|DetalleIVA|CuotaImpuesto", "11.55" xmlToSign.UpdateChildContent "HuellaTBAI|EncadenamientoFacturaAnterior|SerieFacturaAnterior", "B2022" xmlToSign.UpdateChildContent "HuellaTBAI|EncadenamientoFacturaAnterior|NumFacturaAnterior", "0099" xmlToSign.UpdateChildContent "HuellaTBAI|EncadenamientoFacturaAnterior|FechaExpedicionFacturaAnterior", "29-01-2022" xmlToSign.UpdateChildContent "HuellaTBAI|EncadenamientoFacturaAnterior|SignatureValueFirmaFacturaAnterior", "BeMkKwXaFsxHQec65SKpVP7EU9o4nUXOx7SAftIToFsxH+2j2tXPXhpBUnS26dhdSpiMl2DlTuqRsFdZfWyYazaGHgSRQHZZAnFt" xmlToSign.UpdateChildContent "HuellaTBAI|Software|LicenciaTBAI", "TBAXXXXX" xmlToSign.UpdateChildContent "HuellaTBAI|Software|EntidadDesarrolladora|NIF", "XXXXXX" xmlToSign.UpdateChildContent "HuellaTBAI|Software|Nombre", "XXXXXXX" xmlToSign.UpdateChildContent "HuellaTBAI|Software|Version", App.Major & "." & App.Minor & "." & App.Revision FirmarXMLTbai xmlToSign End Function Public Function FirmarXMLTbai(xmlToSign As ChilkatXml) As Boolean Dim gen As New ChilkatXmlDSigGen Dim success As Long success = 1 gen.SigLocation = "T:TicketBai" gen.SigLocationMod = 0 gen.SigId = "Signature-a53a6ab2-f904-4f7c-be64-603333f651bf-Signature" gen.SigNamespacePrefix = "ds" gen.SigNamespaceUri = "http://www.w3.org/2000/09/xmldsig#" gen.SigValueId = "Signature-a53a6ab2-f904-4f7c-be64-603333f651bf-SignatureValue" gen.SignedInfoCanonAlg = "C14N" gen.SignedInfoDigestMethod = "sha256" ' Set the KeyInfoId before adding references.. gen.KeyInfoId = "Signature-a53a6ab2-f904-4f7c-be64-603333f651bf-KeyInfo" ' Create an Object to be added to the Signature. Dim object1 As New ChilkatXml object1.Tag = "xades:QualifyingProperties" success = object1.AddAttribute("xmlns:xades", "http://uri.etsi.org/01903/v1.3.2#") success = object1.AddAttribute("Id", "Signature-a53a6ab2-f904-4f7c-be64-603333f651bf-QualifyingProperties") success = object1.AddAttribute("Target", "#Signature-a53a6ab2-f904-4f7c-be64-603333f651bf-Signature") success = object1.AddAttribute("xmlns:ds", "http://www.w3.org/2000/09/xmldsig#") success = object1.UpdateAttrAt("xades:SignedProperties", 1, "Id", "Signature-a53a6ab2-f904-4f7c-be64-603333f651bf-SignedProperties") object1.UpdateChildContent "xades:SignedProperties|xades:SignedSignatureProperties|xades:SigningTime", "TO BE GENERATED BY CHILKAT" success = object1.UpdateAttrAt("xades:SignedProperties|xades:SignedSignatureProperties|xades:SigningCertificate|xades:Cert|xades:CertDigest|ds:DigestMethod", 1, "Algorithm", "http://www.w3.org/2001/04/xmlenc#sha512") object1.UpdateChildContent "xades:SignedProperties|xades:SignedSignatureProperties|xades:SigningCertificate|xades:Cert|xades:CertDigest|ds:DigestValue", "TO BE GENERATED BY CHILKAT" object1.UpdateChildContent "xades:SignedProperties|xades:SignedSignatureProperties|xades:SigningCertificate|xades:Cert|xades:IssuerSerial|ds:X509IssuerName", "TO BE GENERATED BY CHILKAT" object1.UpdateChildContent "xades:SignedProperties|xades:SignedSignatureProperties|xades:SigningCertificate|xades:Cert|xades:IssuerSerial|ds:X509SerialNumber", "TO BE GENERATED BY CHILKAT" object1.UpdateChildContent "xades:SignedProperties|xades:SignedSignatureProperties|xades:SignaturePolicyIdentifier|xades:SignaturePolicyId|xades:SigPolicyId|xades:Identifier", "https://www.batuz.eus/fitxategiak/batuz/ticketbai/sinadura_elektronikoaren_zehaztapenak_especificaciones_de_la_firma_electronica_v1_0.pdf" object1.UpdateChildContent "xades:SignedProperties|xades:SignedSignatureProperties|xades:SignaturePolicyIdentifier|xades:SignaturePolicyId|xades:SigPolicyId|xades:Description", "" success = object1.UpdateAttrAt("xades:SignedProperties|xades:SignedSignatureProperties|xades:SignaturePolicyIdentifier|xades:SignaturePolicyId|xades:SigPolicyHash|ds:DigestMethod", 1, "Algorithm", "http://www.w3.org/2001/04/xmlenc#sha256") object1.UpdateChildContent "xades:SignedProperties|xades:SignedSignatureProperties|xades:SignaturePolicyIdentifier|xades:SignaturePolicyId|xades:SigPolicyHash|ds:DigestValue", "Quzn98x3PMbSHwbUzaj5f5KOpiH0u8bvmwbbbNkO9Es=" object1.UpdateChildContent "xades:SignedProperties|xades:SignedSignatureProperties|xades:SignaturePolicyIdentifier|xades:SignaturePolicyId|xades:SigPolicyQualifiers|xades:SigPolicyQualifier|xades:SPURI", "https://www.batuz.eus/fitxategiak/batuz/ticketbai/sinadura_elektronikoaren_zehaztapenak_especificaciones_de_la_firma_electronica_v1_0.pdf" success = object1.UpdateAttrAt("xades:SignedProperties|xades:SignedDataObjectProperties|xades:DataObjectFormat", 1, "ObjectReference", "#Reference-cf54e6a9-7bf2-4128-8cae-474a267a16a1") object1.UpdateChildContent "xades:SignedProperties|xades:SignedDataObjectProperties|xades:DataObjectFormat|xades:Description", "" success = object1.UpdateAttrAt("xades:SignedProperties|xades:SignedDataObjectProperties|xades:DataObjectFormat|xades:ObjectIdentifier|xades:Identifier", 1, "Qualifier", "OIDAsURN") object1.UpdateChildContent "xades:SignedProperties|xades:SignedDataObjectProperties|xades:DataObjectFormat|xades:ObjectIdentifier|xades:Identifier", "urn:oid:1.2.840.10003.5.109.10" object1.UpdateChildContent "xades:SignedProperties|xades:SignedDataObjectProperties|xades:DataObjectFormat|xades:ObjectIdentifier|xades:Description", "" object1.UpdateChildContent "xades:SignedProperties|xades:SignedDataObjectProperties|xades:DataObjectFormat|xades:MimeType", "text/xml" object1.UpdateChildContent "xades:SignedProperties|xades:SignedDataObjectProperties|xades:DataObjectFormat|xades:Encoding", "" success = gen.AddObject("", object1.GetXml(), "", "") ' -------- Reference 1 -------- success = gen.AddSameDocRef("", "sha512", "C14N", "", "http://www.w3.org/2000/09/xmldsig#Object") success = gen.SetRefIdAttr("", "Reference-cf54e6a9-7bf2-4128-8cae-474a267a16a1") ' -------- Reference 2 -------- success = gen.AddObjectRef("Signature-a53a6ab2-f904-4f7c-be64-603333f651bf-SignedProperties", "sha512", "", "", "http://uri.etsi.org/01903#SignedProperties") ' -------- Reference 3 -------- success = gen.AddSameDocRef("Signature-a53a6ab2-f904-4f7c-be64-603333f651bf-KeyInfo", "sha512", "", "", "") ' Provide a certificate + private key. (PFX password is test123) Dim cert As New ChilkatCert success = cert.LoadPfxFile("ruta.pfx", "1234") If (success <> 1) Then Debug.Print cert.LastErrorText Exit Function End If success = gen.SetX509Cert(cert, 1) gen.KeyInfoType = "X509Data+KeyValue" gen.X509Type = "Certificate" ' Load XML to be signed... Dim sbXml As New ChilkatStringBuilder success = xmlToSign.GetXmlSb(sbXml) gen.Behaviors = "IndentedSignature,TransformSignatureXPath" ' Sign the XML... success = gen.CreateXmlDSigSb(sbXml) If (success <> 1) Then Debug.Print gen.LastErrorText Exit Function End If ' Save the signed XML to a file. success = sbXml.WriteFile("c:\signedXml.xml", "utf-8", 0) 'Debug.Print sbXml.GetAsString() VerificarFirmaXMLTbai sbXml End Function Public Function VerificarFirmaXMLTbai(sbXml As ChilkatStringBuilder) As Boolean Dim verifier As New ChilkatXmlDSig Dim success As Long success = 1 success = verifier.LoadSignatureSb(sbXml) If (success <> 1) Then Debug.Print verifier.LastErrorText Exit Function End If Dim numSigs As Long numSigs = verifier.NumSignatures Dim verifyIdx As Long verifyIdx = 0 Do While verifyIdx < numSigs verifier.selector = verifyIdx Dim verified As Long verified = verifier.VerifySignature(1) If (verified <> 1) Then Debug.Print verifier.LastErrorText Exit Function End If verifyIdx = verifyIdx + 1 Loop Debug.Print "All signatures were successfully verified." End Function Public Sub EnviarXMLTbai() Dim Http As New ChilkatHttp Dim success As Boolean success = Http.SetSslClientCertPfx("ruta.pfx", "1234") If (success = False) Then Debug.Print Http.LastErrorText Exit Sub End If ' Get the XML we wish to send in the body of the request. Dim sbXml As New ChilkatStringBuilder success = sbXml.LoadFile("c:\signedXml.xml", "utf-8") If (success = False) Then Debug.Print ("Failed to load XML that is to be the HTTP request body") Exit Sub End If Dim url As String url = "https://tbai-prep.egoitza.gipuzkoa.eus/WAS/HACI/HTBRecepcionFacturasWEB/rest/recepcionFacturas/alta" Dim bGzip As Boolean bGzip = True Dim resp As ChilkatHttpResponse Set resp = Http.PostXml(url, sbXml.GetAsString, "utf-8") If (Http.LastMethodSuccess = False) Then Debug.Print (Http.LastErrorText) Exit Sub End If Http.ClearHeaders Debug.Print ("response status code: " & resp.StatusCode) ' Examine the response (it is already decompressed) Debug.Print ("response body:") Debug.Print (resp.BodyStr) End Sub |
#3
|
||||
|
||||
Disculpa, a ti no te sale este error al enviar? Me da el fichero como recibido pero me dice lo siguiente:
Código PHP:
|
#4
|
|||
|
|||
Cita:
A mí me ha dado ese error cuando no he enviado los datos en UTF8. También debes cambiar los "signature" (solo hay dos diferentes) por otros que sean distintos para cada envío, para lo que puedes usar la función generateUuid() de la clase CkCrypt2. Por ejemplo (código C++): Cita:
|
#5
|
||||
|
||||
Genial! Voy a probar, muchas gracias! Pero cómo te aseguras que lo envías con esa codificación? Porque lo tengo en el código en varios puntos y luego lo tengo adjuntado en el header de la petición. Tú cómo lo estás haciendo?
|
#6
|
|||
|
|||
Yo tengo el mismo problema de error en tránsito, le he metido utf-8 por todo slo sitios y sigo igual, alguien puede poner la firma y envío con Chilkat en VB6? estoy encallado. La firma está bien o eso dicen todos los validadores. Uso el ejemplo que genera las tools de Chilkat.
|
#7
|
||||
|
||||
Lo mismo yo, aunque en C#
|
#8
|
|||
|
|||
Cita:
Saludos |
#9
|
|||
|
|||
Cita:
|
#10
|
|||
|
|||
Cita:
IMPORTANTE: recuerda que hay que convertirlo a UTF8 antes de firmarlo. |
#11
|
||||
|
||||
¿Y en qué consiste esa función de conversión?
|
#12
|
||||
|
||||
De lujo compañero !!!!! muy agradecido voy ha probar
|
#13
|
||||
|
||||
Cita:
Última edición por Neftali [Germán.Estévez] fecha: 14-07-2021 a las 12:49:12. Razón: Corregir etiquetas |
#14
|
|||
|
|||
Otro problema que estoy teniendo es cuando quiero transmitir una factura de un NIF de fuera de España, que me dice el fichero no cumple el esquema XSD.
¿os ha pasado? |
#15
|
||||
|
||||
Cita:
¿Dónde la estás enviando? y ¿Qué estás enviando? (puedes poner el trozo del XML) (sección de <Destinatarios>)
__________________
Germán Estévez => Web/Blog Guía de estilo, Guía alternativa Utiliza TAG's en tus mensajes. Contactar con el Clubdelphi P.D: Más tiempo dedicado a la pregunta=Mejores respuestas. |
#16
|
|||
|
|||
Resuperar ds:SignatureValue
Hola,
Alguien sabe como recuperar la firma de un xml firmado con Chilckat? Saludos |
#17
|
|||
|
|||
Cita:
Dim xml as new ChilckatXml .... cargamos el xml ds_SignatureValue = xml.GetChildContent("ds:Signature|ds:SignatureValue") Gracias |
#18
|
|||
|
|||
Cita:
Yo lo necesitaba para otras cosas y al final tuve que hacérmelo. No es difícil, aunque requiere bastantes horas de trabajo para pulirlo, pero una vez hecho es una delicia poder procesar cualquier XML sin despeinarse. Si quieres salir del paso, puedes buscar "<ds:SignatureValue" en el texto. Una vez encontrado tienes que buscar el siguiente '>', apuntar la posición, buscar el siguiente '<', apuntar la posición, y extraer el fragmento comprendido entre las dos posiciones. |
#19
|
|||
|
|||
A Guipuzcoa. Si envío un NIF español, sí que llega
<Destinatarios> <IDDestinatario> <NIF>NL855820627B01</NIF> <ApellidosNombreRazonSocial>ITX MERKEN B.V.</ApellidosNombreRazonSocial> </IDDestinatario> </Destinatarios> Y me da el siguiente error: Error: El fichero de alta TicketBAI no cumple el esquema XSD. Detalle del error: cvc-pattern-valid: Value 'NL855820627B01' is not facet-valid with respect to pattern '(([a-z|A-Z]{1}\d{7}[a-z|A-Z]{1})|(\d{8}[a-z|A-Z]{1})|([a-z|A-Z]{1}\d{8}))' for type 'NIFType'.</Descripcion> |
#20
|
|||
|
|||
Bueno, parece que finalmente sí que consigo enviar el XML, recoger la firma para encadenar y generar el QR (al menos para Guipuzcoa)
Lo que no consigo es que dicho QR sea correcto. No sé si porque estoy obtieniendo el CRC mal, o cual es el motivo. (Y tampoco he visto ninguna url que funcione en todo el hilo) Me genera la siguiente cadena: https ://tbai.prep.gipuzkoa.eus/qr/?id=TBAI-B09500307-130521-YiT5C1USVoYiN-002&s=MP&nf=210914&i=5348.20&cr=245 No accede a la factura pero si accedo desde : https ://tbai.prep.gipuzkoa.eus/qr/verificar , ahí si que la encuentra También he probado con: https ://tbai.egoitza.gipuzkoa.eus/qr/verificar ,pero ahí tampoco la encuentra ¿qué diferencia hay entre un subdominio y el otro? La función en VB que utilizo para el cálculo del CRC es: Public Function calculateCRC8(ByVal AppID As String) As String Dim CRC8 As Byte Dim i As Integer Dim j As Integer Dim AppIDarray() As Byte '<--- explicitly dimensioned as a Byte array to avoid confusion Dim aidLength As Integer CRC8 = &HC7 'The AppID is actually bytes stored in hexadecimal in a string. You have to convert them back to bytes before you can run a crc8 on them. AppIDarray = HexToByte(AppID) aidLength = UBound(AppIDarray) For j = 0 To aidLength CRC8 = CRC8 Xor AppIDarray(j) For i = 1 To 8 If CRC8 And &H80 Then 'masking off the left-most bit before shifting prevents the Overflow error. CRC8 = ((&H7F And CRC8) * 2) Xor &H1D Else CRC8 = CRC8 * 2 End If Next i Next j calculateCRC8 = CRC8 End Function Private Function HexToByte(strHex As String) As Byte() Dim i As Integer Dim j As Integer Dim tempByte As Byte Dim outBytes() As Byte Dim Char As String ReDim outBytes(Len(strHex) \ 2 - 1) For i = 0 To Len(strHex) \ 2 - 1 For j = 0 To 1 Char = Mid(strHex, i * 2 + j + 1, 1) Select Case Char Case "0", "1", "2", "3", "4", "5", "6", "7", "8", "9": tempByte = tempByte Or (Asc(Char) - 48) Case "A", "B", "C", "D", "E", "F": tempByte = tempByte Or (Asc(Char) - 55) End Select If j = 0 Then tempByte = tempByte * 2 ^ 4 Else outBytes(i) = tempByte tempByte = 0 End If Next Next HexToByte = outBytes End Function |
|
|
Temas Similares | ||||
Tema | Autor | Foro | Respuestas | Último mensaje |
SII -Nuevo sistema de la Agencia Tributaria española de envío de datos vía Webservice | newtron | Internet | 3565 | Hace 1 Día 11:04:13 |
Como utilizar la ayuda del nuevo Sistema Operativo | gluglu | Humor | 3 | 24-09-2007 09:39:05 |
Aplicacion Agencia De Viajes | ArdiIIa | Varios | 9 | 20-01-2007 16:49:53 |
El Vasco Aguirre | Al González | La Taberna | 5 | 26-05-2006 09:22:28 |
Microsoft ha lanzado su nuevo sistema operativo | DarkByte | Humor | 0 | 25-01-2004 09:21:14 |
|