![]() |
![]() |
| Paypal | FTP | CCD | Buscar | Trucos | Trabajo | Foros |
|
|||||||
| Registrarse | FAQ | Miembros | Calendario | Guía de estilo | Buscar | Temas de Hoy | Marcar Foros Como Leídos |
![]() |
|
|
Herramientas | Buscar en Tema | Desplegado |
|
|
|
#1
|
|||
|
|||
|
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
|
|
#2
|
||||
|
||||
|
Disculpa, a ti no te sale este error al enviar? Me da el fichero como recibido pero me dice lo siguiente:
Código PHP:
|
|
#3
|
|||
|
|||
|
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:
|
|
#4
|
||||
|
||||
|
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?
|
|
#5
|
|||
|
|||
|
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.
|
|
#6
|
||||
|
||||
|
Lo mismo yo, aunque en C#
|
|
#7
|
|||
|
|||
|
Cita:
![]() ![]() ![]() ![]() El error era pq el nombre del cliente tenía un acento. ya podia ir probando cosas Saludos |
|
#8
|
|||
|
|||
|
Precisamente para eso sirve la conversión a UTF8. Si algo con acentos lo conviertes a UTF8 antes de firmar no hay problemas.
|
|
#9
|
|||
|
|||
|
Cita:
|
|
#10
|
|||
|
|||
|
Gracias Glaxian, el error era por el nombre del cliente que contenia un acento :-(, limpiando acentos y otros carácteres me ha funcionado con Chilckat
|
|
#11
|
|||
|
|||
|
Cita:
IMPORTANTE: recuerda que hay que convertirlo a UTF8 antes de firmarlo. |
|
#12
|
||||
|
||||
|
¿Y en qué consiste esa función de conversión?
|
|
#13
|
|||
|
|||
|
Código:
std::string cdfCodificarUtf8(const char *txt)
{
int lnga=MultiByteToWideChar(CP_ACP,0,txt,-1,nullptr,0);
WCHAR *tmpa=new WCHAR[lnga];
MultiByteToWideChar(CP_ACP,0,txt,-1,tmpa,lnga);
int lngb=WideCharToMultiByte(CP_UTF8,0,tmpa,-1,nullptr,0,nullptr,nullptr);
char *tmpb=new char[lngb];
WideCharToMultiByte(CP_UTF8,0,tmpa,-1,tmpb,lngb,nullptr,nullptr);
std::string dst=tmpb;
delete tmpa;
delete tmpb;
return(dst);
}
|
|
#14
|
||||
|
||||
|
De lujo compañero !!!!! muy agradecido voy ha probar
|
|
#15
|
||||
|
||||
|
Cita:
![]() ![]() ![]() ![]() Última edición por Neftali [Germán.Estévez] fecha: 14-07-2021 a las 12:49:12. Razón: Corregir etiquetas |
|
#16
|
|||
|
|||
|
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? |
|
#17
|
||||
|
||||
|
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. |
|
#18
|
|||
|
|||
|
Resuperar ds:SignatureValue
Hola,
Alguien sabe como recuperar la firma de un xml firmado con Chilckat? Saludos |
|
#19
|
|||
|
|||
|
Cita:
Dim xml as new ChilckatXml .... cargamos el xml ds_SignatureValue = xml.GetChildContent("ds:Signature|ds:SignatureValue") Gracias |
|
#20
|
||||
|
||||
|
Crc-8
Hola!
He utilizado chilkat para firmar el XML pero me surge una duda, el CRC-8 se está realizando automáticamente en algún momento dado? Porque el servidor recibe la factura y me retorna el código TBAI (que contiene 3 dígitos de haber aplicado el CRC-8). Porque vosotros el TBAI lo obtenéis de la respuesta del server o lo formáis manualmente? |
![]() |
| Herramientas | Buscar en Tema |
| Desplegado | |
|
|
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 | 3716 | 19-01-2026 20:01:34 |
| 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 |
|