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
(Unicode C++) Hungary NAV Query TaxpayerDemonstrates the queryTaxpayer request for the Hungarian NAV Online Invoicing System REST API v2.0. Note: This example requires Chilkat v9.5.0.83 or greater. For more information, see https://onlineszamla.nav.gov.hu/api/files/container/download/Online%20Szamla_Interfesz%20specifik%C3%A1ci%C3%B3_EN_v2.0.pdf
#include <CkCrypt2W.h> #include <CkDateTimeW.h> #include <CkPrngW.h> #include <CkStringBuilderW.h> #include <CkXmlW.h> #include <CkHttpW.h> #include <CkHttpResponseW.h> void ChilkatSample(void) { // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. // Build the following XML: // <?xml version="1.0" encoding="UTF-8"?> // <QueryTaxpayerRequest xmlns="http://schemas.nav.gov.hu/OSA/2.0/api"> // <header> // <requestId>RID215118906689</requestId> // <timestamp>2019-09-11T11:11:08.579Z</timestamp> // <requestVersion>2.0</requestVersion> // <headerVersion>1.0</headerVersion> // </header> // <user> // <login>lwilsmn0uqdxe6u</login> // <passwordHash>2F43840A882CFDB7DB0FEC07D419D030D864B47B6B541DC280EF81B937B7A176E33C052B0D26638CC18A7A2C08D8D311733078A774BF43F6CA57FE8CD74DC28E</passwordHash> // <taxNumber>11111111</taxNumber> // <requestSignature>C5ADE8A2231C509D2887E6C2C4406CC5F72CA25B070AD3E94FADFA3F91A8A3667AF882DEDC7D67E9086E3D34A95886E929ACD8C924CD1E8357C89BEF43BA9126</requestSignature> // </user> // <software> // <softwareId>123456789123456789</softwareId> // <softwareName>string</softwareName> // <softwareOperation>LOCAL_SOFTWARE</softwareOperation> // <softwareMainVersion>string</softwareMainVersion> // <softwareDevName>string</softwareDevName> // <softwareDevContact>string</softwareDevContact> // <softwareDevCountryCode>HU</softwareDevCountryCode> // <softwareDevTaxNumber>string</softwareDevTaxNumber> // </software> // <taxNumber>22222222</taxNumber> // </QueryTaxpayerRequest> bool success; CkCrypt2W crypt; CkDateTimeW dtNow; dtNow.SetFromCurrentSystemTime(); wprintf(L"%s\n",dtNow.getAsTimestamp(false)); // The hash algorithm for the password is SHA512 (not SHA3-512). crypt.put_HashAlgorithm(L"sha512"); crypt.put_EncodingMode(L"hex"); const wchar_t *myPassword = L"my-password"; const wchar_t *passwordHash = crypt.hashStringENC(myPassword); // Generate a random request ID like "RID215118906689" CkPrngW prng; CkStringBuilderW sbRequestId; sbRequestId.Append(L"RID"); sbRequestId.Append(prng.randomString(12,true,false,false)); wprintf(L"generated requestId = %s\n",sbRequestId.getAsString()); // Calculate the requestSignature // IMPORTANT: This example requires Chilkat v9.5.0.83 or greater. The SHA3 hash algorithm is implemented in Chilkat v9.5.0.83, but not in earlier versions. // IMPORTANT: This example requires Chilkat v9.5.0.83 or greater. The SHA3 hash algorithm is implemented in Chilkat v9.5.0.83, but not in earlier versions. // IMPORTANT: This example requires Chilkat v9.5.0.83 or greater. The SHA3 hash algorithm is implemented in Chilkat v9.5.0.83, but not in earlier versions. // IMPORTANT: This example requires Chilkat v9.5.0.83 or greater. The SHA3 hash algorithm is implemented in Chilkat v9.5.0.83, but not in earlier versions. // IMPORTANT: This example requires Chilkat v9.5.0.83 or greater. The SHA3 hash algorithm is implemented in Chilkat v9.5.0.83, but not in earlier versions. crypt.put_HashAlgorithm(L"sha3-512"); const wchar_t *signatureKey = L"ce-8f5e-215119fa7dd621DLMRHRLH2S"; CkStringBuilderW sbFinalHashBase; // First append the timestamp because we are going to remove certain chars/parts. sbFinalHashBase.Append(dtNow.getAsTimestamp(false)); int numReplaced = sbFinalHashBase.Replace(L"Z",L""); numReplaced = sbFinalHashBase.Replace(L"-",L""); numReplaced = sbFinalHashBase.Replace(L":",L""); numReplaced = sbFinalHashBase.Replace(L"T",L""); // Prepend the requestId and append the signatureKey sbFinalHashBase.Prepend(sbRequestId.getAsString()); sbFinalHashBase.Append(signatureKey); const wchar_t *requestSignature = crypt.hashStringENC(sbFinalHashBase.getAsString()); CkXmlW xml; xml.put_Tag(L"QueryTaxpayerRequest"); xml.AddAttribute(L"xmlns",L"http://schemas.nav.gov.hu/OSA/2.0/api"); xml.UpdateChildContent(L"header|requestId",sbRequestId.getAsString()); xml.UpdateChildContent(L"header|timestamp",dtNow.getAsTimestamp(false)); xml.UpdateChildContent(L"header|requestVersion",L"2.0"); xml.UpdateChildContent(L"header|headerVersion",L"1.0"); xml.UpdateChildContent(L"user|login",L"lwilsmn0uqdxe6u"); xml.UpdateChildContent(L"user|passwordHash",passwordHash); xml.UpdateChildContent(L"user|taxNumber",L"11111111"); xml.UpdateChildContent(L"user|requestSignature",requestSignature); xml.UpdateChildContent(L"software|softwareId",L"123456789123456789"); xml.UpdateChildContent(L"software|softwareName",L"string"); xml.UpdateChildContent(L"software|softwareOperation",L"LOCAL_SOFTWARE"); xml.UpdateChildContent(L"software|softwareMainVersion",L"string"); xml.UpdateChildContent(L"software|softwareDevName",L"string"); xml.UpdateChildContent(L"software|softwareDevContact",L"string"); xml.UpdateChildContent(L"software|softwareDevCountryCode",L"HU"); xml.UpdateChildContent(L"software|softwareDevTaxNumber",L"string"); xml.UpdateChildContent(L"taxNumber",L"22222222"); // POST the XML to https://api-test.onlineszamla.nav.gov.hu/invoiceService/v2/queryTaxpayer CkHttpW http; http.put_Accept(L"application/xml"); http.SetRequestHeader(L"Content-Type",L"application/xml"); const wchar_t *endpoint = L"https://api-test.onlineszamla.nav.gov.hu/invoiceService/v2/queryTaxpayer"; CkHttpResponseW *resp = http.PostXml(endpoint,xml.getXml(),L"utf-8"); if (http.get_LastMethodSuccess() == false) { wprintf(L"%s\n",http.lastErrorText()); return; } wprintf(L"Response status code = %d\n",resp->get_StatusCode()); CkXmlW respXml; respXml.LoadXml(resp->bodyStr()); wprintf(L"Response body:\n"); wprintf(L"%s\n",respXml.getXml()); delete resp; // The result looks like this: // <?xml version="1.0" encoding="UTF-8" standalone="yes"?> // <QueryTaxpayerResponse xmlns="http://schemas.nav.gov.hu/OSA/2.0/api" xmlns:ns2="http://schemas.nav.gov.hu/OSA/2.0/data"> // <header> // <requestId>RID847153193061</requestId> // <timestamp>2020-03-24T16:00:34Z</timestamp> // <requestVersion>2.0</requestVersion> // <headerVersion>1.0</headerVersion> // </header> // <result> // <funcCode>OK</funcCode> // </result> // <software> // <softwareId>123456789123456789</softwareId> // <softwareName>string</softwareName> // <softwareOperation>LOCAL_SOFTWARE</softwareOperation> // <softwareMainVersion>string</softwareMainVersion> // <softwareDevName>string</softwareDevName> // <softwareDevContact>string</softwareDevContact> // <softwareDevCountryCode>HU</softwareDevCountryCode> // <softwareDevTaxNumber>string</softwareDevTaxNumber> // </software> // <infoDate>1993-01-01T00:00:00.000+01:00</infoDate> // <taxpayerValidity>true</taxpayerValidity> // <taxpayerData> // <taxpayerName>some taxpayer name</taxpayerName> // <taxNumberDetail> // <ns2:taxpayerId>22222222</ns2:taxpayerId> // <ns2:vatCode>2</ns2:vatCode> // </taxNumberDetail> // <taxpayerAddressList> // <taxpayerAddressItem> // <taxpayerAddressType>HQ</taxpayerAddressType> // <taxpayerAddress> // <ns2:countryCode>HU</ns2:countryCode> // <ns2:postalCode>1121</ns2:postalCode> // <ns2:city>BUDAPEST 12</ns2:city> // <ns2:streetName>ABCD</ns2:streetName> // <ns2:publicPlaceCategory>UTCA</ns2:publicPlaceCategory> // <ns2:number>20</ns2:number> // </taxpayerAddress> // </taxpayerAddressItem> // </taxpayerAddressList> // </taxpayerData> // </QueryTaxpayerResponse> // Use this online tool to generate parsing code from sample XML: // Generate Parsing Code from XML // Chilkat functions returning "const char *" return a pointer to temporary internal memory owned and managed by Chilkat. // See this example explaining how this memory should be used: const char * functions. const wchar_t *QueryTaxpayerResponse_xmlns = respXml.getAttrValue(L"xmlns"); const wchar_t *QueryTaxpayerResponse_xmlns_ns2 = respXml.getAttrValue(L"xmlns:ns2"); const wchar_t *requestId = respXml.getChildContent(L"header|requestId"); const wchar_t *timestamp = respXml.getChildContent(L"header|timestamp"); const wchar_t *requestVersion = respXml.getChildContent(L"header|requestVersion"); const wchar_t *headerVersion = respXml.getChildContent(L"header|headerVersion"); const wchar_t *funcCode = respXml.getChildContent(L"result|funcCode"); const wchar_t *softwareId = respXml.getChildContent(L"software|softwareId"); const wchar_t *softwareName = respXml.getChildContent(L"software|softwareName"); const wchar_t *softwareOperation = respXml.getChildContent(L"software|softwareOperation"); const wchar_t *softwareMainVersion = respXml.getChildContent(L"software|softwareMainVersion"); const wchar_t *softwareDevName = respXml.getChildContent(L"software|softwareDevName"); const wchar_t *softwareDevContact = respXml.getChildContent(L"software|softwareDevContact"); const wchar_t *softwareDevCountryCode = respXml.getChildContent(L"software|softwareDevCountryCode"); const wchar_t *softwareDevTaxNumber = respXml.getChildContent(L"software|softwareDevTaxNumber"); const wchar_t *infoDate = respXml.getChildContent(L"infoDate"); const wchar_t *taxpayerValidity = respXml.getChildContent(L"taxpayerValidity"); const wchar_t *taxpayerName = respXml.getChildContent(L"taxpayerData|taxpayerName"); int ns2_taxpayerId = respXml.GetChildIntValue(L"taxpayerData|taxNumberDetail|ns2:taxpayerId"); int ns2_vatCode = respXml.GetChildIntValue(L"taxpayerData|taxNumberDetail|ns2:vatCode"); const wchar_t *taxpayerAddressType = respXml.getChildContent(L"taxpayerData|taxpayerAddressList|taxpayerAddressItem|taxpayerAddressType"); const wchar_t *ns2_countryCode = respXml.getChildContent(L"taxpayerData|taxpayerAddressList|taxpayerAddressItem|taxpayerAddress|ns2:countryCode"); int ns2_postalCode = respXml.GetChildIntValue(L"taxpayerData|taxpayerAddressList|taxpayerAddressItem|taxpayerAddress|ns2:postalCode"); const wchar_t *ns2_city = respXml.getChildContent(L"taxpayerData|taxpayerAddressList|taxpayerAddressItem|taxpayerAddress|ns2:city"); const wchar_t *ns2_streetName = respXml.getChildContent(L"taxpayerData|taxpayerAddressList|taxpayerAddressItem|taxpayerAddress|ns2:streetName"); const wchar_t *ns2_publicPlaceCategory = respXml.getChildContent(L"taxpayerData|taxpayerAddressList|taxpayerAddressItem|taxpayerAddress|ns2:publicPlaceCategory"); int ns2_number = respXml.GetChildIntValue(L"taxpayerData|taxpayerAddressList|taxpayerAddressItem|taxpayerAddress|ns2:number"); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.