Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(PureBasic) Aruba Fatturazione Elettronica Get Zip by FilenameReturns an invoice with all of its notifications in Zip format (e.g. IT01879020517_abcde.xml.p7m). For more information, see https://fatturazioneelettronica.aruba.it/apidoc/docs_EN.html#_getzipbyfilename
IncludeFile "CkBinData.pb" IncludeFile "CkHttp.pb" IncludeFile "CkZipEntry.pb" IncludeFile "CkZip.pb" IncludeFile "CkCrypt2.pb" Procedure ChilkatExample() ; This example assumes the Chilkat API to have been previously unlocked. ; See Global Unlock Sample for sample code. http.i = CkHttp::ckCreate() If http.i = 0 Debug "Failed to create object." ProcedureReturn EndIf success.i ; Implements the following CURL command: ; curl -X GET https://ws.fatturazioneelettronica.aruba.it/services/invoice/in/getZipByFilename?filename=IT01879020517_jtlk1.xml.p7m \ ; -H "Accept: application/json" \ ; -H "Authorization: Bearer NLOGDVXLVaF3tzmnVPkTwpkuh7dG0i09uSCcog3u+rE=" ; Use the following online tool to generate HTTP code from a CURL command ; Convert a cURL Command to HTTP Source Code ; Adds the "Authorization: Bearer NLOGDVXLVaF3tzmnVPkTwpkuh7dG0i09uSCcog3u+rE=" header. CkHttp::setCkAuthToken(http, "NLOGDVXLVaF3tzmnVPkTwpkuh7dG0i09uSCcog3u+rE=") CkHttp::ckSetRequestHeader(http,"Accept","application/json") bdZip.i = CkBinData::ckCreate() If bdZip.i = 0 Debug "Failed to create object." ProcedureReturn EndIf success = CkHttp::ckQuickGetBd(http,"https://ws.fatturazioneelettronica.aruba.it/services/invoice/in/getZipByFilename?filename=IT01879020517_jtlk1.xml.p7m",bdZip) If success = 0 Debug CkHttp::ckLastErrorText(http) CkHttp::ckDispose(http) CkBinData::ckDispose(bdZip) ProcedureReturn EndIf respStatusCode.i = CkHttp::ckLastStatus(http) Debug "response status code = " + Str(respStatusCode) If respStatusCode <> 200 ; If it failed, the response body will not contain the .zip file data. ; It will likely contain an error message. Debug CkBinData::ckGetString(bdZip,"utf-8") Debug "Failed." CkHttp::ckDispose(http) CkBinData::ckDispose(bdZip) ProcedureReturn EndIf ; Open the zip and extract the .p7m zip.i = CkZip::ckCreate() If zip.i = 0 Debug "Failed to create object." ProcedureReturn EndIf success = CkZip::ckOpenBd(zip,bdZip) If success = 0 Debug CkZip::ckLastErrorText(zip) CkHttp::ckDispose(http) CkBinData::ckDispose(bdZip) CkZip::ckDispose(zip) ProcedureReturn EndIf ; If desired, we can unzip to the filesystem.. numUnzipped.i = CkZip::ckUnzip(zip,"c:/mySignedInvoices") If numUnzipped < 0 Debug CkZip::ckLastErrorText(zip) CkHttp::ckDispose(http) CkBinData::ckDispose(bdZip) CkZip::ckDispose(zip) ProcedureReturn EndIf ; Alternatively, we can unzip into memory.. entry.i = CkZip::ckGetEntryByIndex(zip,0) If CkZip::ckLastMethodSuccess(zip) = 0 Debug CkZip::ckLastErrorText(zip) CkHttp::ckDispose(http) CkBinData::ckDispose(bdZip) CkZip::ckDispose(zip) ProcedureReturn EndIf bdP7m.i = CkBinData::ckCreate() If bdP7m.i = 0 Debug "Failed to create object." ProcedureReturn EndIf success = CkZipEntry::ckUnzipToBd(entry,bdP7m) If success = 0 Debug CkZipEntry::ckLastErrorText(entry) CkHttp::ckDispose(http) CkBinData::ckDispose(bdZip) CkZip::ckDispose(zip) CkBinData::ckDispose(bdP7m) ProcedureReturn EndIf CkZipEntry::ckDispose(entry) ; Verify the signature and extract the XML from the p7m ; If the signature verification is successful, the contents of bdP7m are unwrapped and what ; remains is the original signed document.. crypt.i = CkCrypt2::ckCreate() If crypt.i = 0 Debug "Failed to create object." ProcedureReturn EndIf success = CkCrypt2::ckOpaqueVerifyBd(crypt,bdP7m) If success = 0 Debug CkCrypt2::ckLastErrorText(crypt) CkHttp::ckDispose(http) CkBinData::ckDispose(bdZip) CkZip::ckDispose(zip) CkBinData::ckDispose(bdP7m) CkCrypt2::ckDispose(crypt) ProcedureReturn EndIf Debug "The signature was verified." ; The bdp7m now contains the XML that was originally signed. Debug "Original XML:" Debug CkBinData::ckGetString(bdP7m,"utf-8") CkHttp::ckDispose(http) CkBinData::ckDispose(bdZip) CkZip::ckDispose(zip) CkBinData::ckDispose(bdP7m) CkCrypt2::ckDispose(crypt) ProcedureReturn EndProcedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.