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) Send POST to Bradesco Platform with Billing Ticket for RegistrationSends a POST request to the Bradesco platform containing the JSON data of the Billing Ticket for registration. Note: This example requires updates that are in Chilkat v9.5.0.77 and later.
#include <C_CkJsonObjectW.h> #include <C_CkCertW.h> #include <C_CkCrypt2W.h> #include <C_CkHttpRequestW.h> #include <C_CkHttpW.h> #include <C_CkHttpResponseW.h> void ChilkatSample(void) { BOOL success; HCkJsonObjectW json; HCkCertW cert; HCkCrypt2W crypt; const wchar_t *sigBase64; const wchar_t *url; HCkHttpRequestW req; HCkHttpW http; HCkHttpResponseW resp; // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. // First build the JSON containing the data to be sent. // { // "nuCPFCNPJ":"12668", // "filialCPFCNPJ":"1", // "ctrlCPFCNPJ":"59", // "cdTipoAcesso":"2", // "idProduto":"9", // "nuNegociacao":"262200000000005577", // "nuCliente":"SEU_NUM_CLIENTE", // "dtEmissaoTitulo":"21.09.2016", // "dtVencimentoTitulo":"21.09.2016", // "vlNominalTitulo":"888888", // "cdEspecieTitulo":"2", // "nomePagador":"NOME DO PAGADOR", // "logradouroPagador":"ENDERECO DO PAGADOR", // "nuLogradouroPagador":"1145", // "complementoLogradouroPagador":"APTO 34", // "cepPagador":"5588", // "complementoCepPagador":"1", // "bairroPagador":"BAIRRO PAGADOR", // "municipioPagador":"MUNICIPIO PAGADOR", // "ufPagador":"SP", // "cdIndCpfcnpjPagador":"2", // "nuCpfcnpjPagador":"12668000159", // "endEletronicoPagador":"PAGADOR@BRADESCO.COM.BR", // "nomeSacadorAvalista":"NOME SACADOR AVALISTA", // "logradouroSacadorAvalista":"ENDERECO SACADOR AVALISTA", // "nuLogradouroSacadorAvalista":"5555", // "complementoLogradouroSacadorAvalista":"BLOCO 23", // "cepSacadorAvalista":"6182", // "complementoCepSacadorAvalista":"160", // "bairroSacadorAvalista":"BAIRRO SACADOR AVALISTA", // "municipioSacadorAvalista":"MUNICIPIO SACADOR AVALISTA", // "ufSacadorAvalista":"SP", // "cdIndCpfcnpjSacadorAvalista":"2", // "nuCpfcnpjSacadorAvalista":"12668000159", // "endEletronicoSacadorAvalista":"SACADOR@BRADESCO.COM.BR", // } // json = CkJsonObjectW_Create(); CkJsonObjectW_UpdateString(json,L"nuCPFCNPJ",L"12668"); CkJsonObjectW_UpdateString(json,L"filialCPFCNPJ",L"1"); CkJsonObjectW_UpdateString(json,L"ctrlCPFCNPJ",L"59"); CkJsonObjectW_UpdateString(json,L"cdTipoAcesso",L"2"); CkJsonObjectW_UpdateString(json,L"idProduto",L"9"); CkJsonObjectW_UpdateString(json,L"nuNegociacao",L"262200000000005577"); CkJsonObjectW_UpdateString(json,L"nuCliente",L"SEU_NUM_CLIENTE"); CkJsonObjectW_UpdateString(json,L"dtEmissaoTitulo",L"21.09.2016"); CkJsonObjectW_UpdateString(json,L"dtVencimentoTitulo",L"21.09.2016"); CkJsonObjectW_UpdateString(json,L"vlNominalTitulo",L"888888"); CkJsonObjectW_UpdateString(json,L"cdEspecieTitulo",L"2"); CkJsonObjectW_UpdateString(json,L"nomePagador",L"NOME DO PAGADOR"); CkJsonObjectW_UpdateString(json,L"logradouroPagador",L"ENDERECO DO PAGADOR"); CkJsonObjectW_UpdateString(json,L"nuLogradouroPagador",L"1145"); CkJsonObjectW_UpdateString(json,L"complementoLogradouroPagador",L"APTO 34"); CkJsonObjectW_UpdateString(json,L"cepPagador",L"5588"); CkJsonObjectW_UpdateString(json,L"complementoCepPagador",L"1"); CkJsonObjectW_UpdateString(json,L"bairroPagador",L"BAIRRO PAGADOR"); CkJsonObjectW_UpdateString(json,L"municipioPagador",L"MUNICIPIO PAGADOR"); CkJsonObjectW_UpdateString(json,L"ufPagador",L"SP"); CkJsonObjectW_UpdateString(json,L"cdIndCpfcnpjPagador",L"2"); CkJsonObjectW_UpdateString(json,L"nuCpfcnpjPagador",L"12668000159"); CkJsonObjectW_UpdateString(json,L"endEletronicoPagador",L"PAGADOR@BRADESCO.COM.BR"); CkJsonObjectW_UpdateString(json,L"nomeSacadorAvalista",L"NOME SACADOR AVALISTA"); CkJsonObjectW_UpdateString(json,L"logradouroSacadorAvalista",L"ENDERECO SACADOR AVALISTA"); CkJsonObjectW_UpdateString(json,L"nuLogradouroSacadorAvalista",L"5555"); CkJsonObjectW_UpdateString(json,L"complementoLogradouroSacadorAvalista",L"BLOCO 23"); CkJsonObjectW_UpdateString(json,L"cepSacadorAvalista",L"6182"); CkJsonObjectW_UpdateString(json,L"complementoCepSacadorAvalista",L"160"); CkJsonObjectW_UpdateString(json,L"bairroSacadorAvalista",L"BAIRRO SACADOR AVALISTA"); CkJsonObjectW_UpdateString(json,L"municipioSacadorAvalista",L"MUNICIPIO SACADOR AVALISTA"); CkJsonObjectW_UpdateString(json,L"ufSacadorAvalista",L"SP"); CkJsonObjectW_UpdateString(json,L"cdIndCpfcnpjSacadorAvalista",L"2"); CkJsonObjectW_UpdateString(json,L"nuCpfcnpjSacadorAvalista",L"12668000159"); CkJsonObjectW_UpdateString(json,L"endEletronicoSacadorAvalista",L"SACADOR@BRADESCO.COM.BR"); // Load out PFX file cert = CkCertW_Create(); success = CkCertW_LoadPfxFile(cert,L"qa_data/pfx/cert_test123.pfx",L"test123"); if (success != TRUE) { wprintf(L"%s\n",CkCertW_lastErrorText(cert)); CkJsonObjectW_Dispose(json); CkCertW_Dispose(cert); return; } crypt = CkCrypt2W_Create(); success = CkCrypt2W_SetSigningCert(crypt,cert); if (success != TRUE) { wprintf(L"%s\n",CkCrypt2W_lastErrorText(crypt)); CkJsonObjectW_Dispose(json); CkCertW_Dispose(cert); CkCrypt2W_Dispose(crypt); return; } // Use SHA-256 within the signing.. CkCrypt2W_putHashAlgorithm(crypt,L"sha256"); // IMPORTANT: This example requires Chilkat v9.5.0.77 or later. // Use no authenticated attributes CkCrypt2W_putSigningAttributes(crypt,L"{}"); CkJsonObjectW_putEmitCompact(json,TRUE); sigBase64 = CkCrypt2W_opaqueSignStringENC(crypt,CkJsonObjectW_emit(json)); if (CkCrypt2W_getLastMethodSuccess(crypt) != TRUE) { wprintf(L"%s\n",CkCrypt2W_lastErrorText(crypt)); CkJsonObjectW_Dispose(json); CkCertW_Dispose(cert); CkCrypt2W_Dispose(crypt); return; } // Next, we need to send a POST to the following URL where the body of the POST // contains the binary PKCS7 signature (which embeds the JSON). url = L"https://cobranca.bradesconetempresa.b.br/ibpjregistrotitulows/registrotitulohomologacao"; req = CkHttpRequestW_Create(); CkHttpRequestW_putHttpVerb(req,L"POST"); // This is strange because apparently the server wants a "text/xml" Content-Type, // but the content in the body is not actually XML, it's binary PKCS7. CkHttpRequestW_putContentType(req,L"text/xml"); CkHttpRequestW_LoadBodyFromString(req,sigBase64,L"utf-8"); // We don't actually pass the URL, we set the path here, and the domain is passed below.. CkHttpRequestW_putPath(req,L"/ibpjregistrotitulows/registrotitulohomologacao"); http = CkHttpW_Create(); resp = CkHttpW_SynchronousRequest(http,L"cobranca.bradesconetempresa.b.br",443,TRUE,req); if (CkHttpW_getLastMethodSuccess(http) != TRUE) { wprintf(L"%s\n",CkHttpW_lastErrorText(http)); CkJsonObjectW_Dispose(json); CkCertW_Dispose(cert); CkCrypt2W_Dispose(crypt); CkHttpRequestW_Dispose(req); CkHttpW_Dispose(http); return; } wprintf(L"Response status code: %d\n",CkHttpResponseW_getStatusCode(resp)); wprintf(L"Response body:\n"); wprintf(L"%s\n",CkHttpResponseW_bodyStr(resp)); CkHttpResponseW_Dispose(resp); CkJsonObjectW_Dispose(json); CkCertW_Dispose(cert); CkCrypt2W_Dispose(crypt); CkHttpRequestW_Dispose(req); CkHttpW_Dispose(http); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.