Ver Mensaje Individual
  #1050  
Antiguo 14-07-2021
skatologiko skatologiko is offline
Miembro
 
Registrado: jul 2021
Posts: 27
Reputación: 0
skatologiko Va por buen camino
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
Responder Con Cita