Re: Timbrado con Diverza
Publicado: Mié Oct 11, 2017 1:34 pm
Por nada Juan Gilberto, suerte.
Saludos.
Moisés Fabro.
Saludos.
Moisés Fabro.
Código: Seleccionar todo
{"stage":"content_reading","request_headers":[{"host":"10.223.80.42:4012"},{"accept":"*/*"},{"accept-language":"es-mx"},{"x-auth-token":"ABCD1234"},{"content-type":"application/json"},{"accept-encoding":"gzip, deflate"},{"user-agent":"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; Trident/7.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; InfoPath.3)"},{"cache-control":"no-cache"},{"cookie":"_ga=GA1.2.1900153654.1486992001"},{"x-forwarded-for":"189.162.119.26"},{"x-forwarded-host":"serviciosdemo.diverza.com"},{"x-forwarded-server":"serviciosdemo.diverza.com"},{"connection":"Keep-Alive"},{"content-length":"5928"}],"message":"The request content in body is not valid","level":5,"error_id":4095262,"error_details":"[{\"document.content\":\"is invalid, it must be in base64\"}]","comp_error_details":[{"document.content":"is invalid, it must be in base64"}],"code":4352}
Código: Seleccionar todo
Private Function encodeBase64(ByRef arrData() As Byte) As String
Dim objXML As MSXML2.DOMDocument
Dim objNode As MSXML2.IXMLDOMElement
Set objXML = New MSXML2.DOMDocument
Set objNode = objXML.createElement("b64")
objNode.DataType = "bin.base64"
objNode.nodeTypedValue = arrData
encodeBase64 = objNode.Text
Set objNode = Nothing
Set objXML = Nothing
End Function
Código: Seleccionar todo
'Declaration
Private Declare Function WideCharToMultiByte Lib "kernel32" ( _
ByVal CodePage As Long, _
ByVal dwFlags As Long, _
ByVal lpWideCharStr As Long, _
ByVal cchWideChar As Long, _
ByVal lpMultiByteStr As Long, _
ByVal cbMultiByte As Long, _
ByVal lpDefaultChar As Long, _
ByVal lpUsedDefaultChar As Long) As Long
'CodePage constant for UTF-8
Private Const CP_UTF8 = 65001
'Return byte array with VB "Unicode" string encoded in UTF-8
Public Function Utf8BytesFromString(strInput As String) As Byte()
Dim nBytes As Long
Dim abBuffer() As Byte
'Get length in bytes *including* terminating null
nBytes = WideCharToMultiByte(CP_UTF8, 0&, ByVal StrPtr(strInput), -1, vbNull, 0&, 0&, 0&)
'We don't want the terminating null in our byte array, so ask for `nBytes-1` bytes
ReDim abBuffer(nBytes - 2) ' NB ReDim with one less byte than you need
nBytes = WideCharToMultiByte(CP_UTF8, 0&, ByVal StrPtr(strInput), -1, ByVal VarPtr(abBuffer(0)), nBytes - 1, 0&, 0&)
Utf8BytesFromString = abBuffer
End Function
'My Code
' XMLFactura.XML is the xml string
'Convert XML to ByteArray (UTF-8)
Dim MyByte() As Byte
MyByte = Utf8BytesFromString(XMLFactura.XML)
'Convert to Base64
Dim MyBase64 As String
Dim lo_CkCrypt As New Chilkat_v9_5_0.ChilkatCrypt2
With lo_CkCrypt
.Charset = "unicode"
.CryptAlgorithm = "none"
.EncodingMode = "base64"
End With
MyBase64 = lo_CkCrypt.EncryptBytesENC(MyByte)
Set lo_CkCrypt = Nothing
'add xml in base64 to json request
success = document.AddStringAt(-1, "content", MyBase64)