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
(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_CkJsonObject.h> #include <C_CkCert.h> #include <C_CkCrypt2.h> #include <C_CkHttpRequest.h> #include <C_CkHttp.h> #include <C_CkHttpResponse.h> void ChilkatSample(void) { BOOL success; HCkJsonObject json; HCkCert cert; HCkCrypt2 crypt; const char *sigBase64; const char *url; HCkHttpRequest req; HCkHttp http; HCkHttpResponse 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 = CkJsonObject_Create(); CkJsonObject_UpdateString(json,"nuCPFCNPJ","12668"); CkJsonObject_UpdateString(json,"filialCPFCNPJ","1"); CkJsonObject_UpdateString(json,"ctrlCPFCNPJ","59"); CkJsonObject_UpdateString(json,"cdTipoAcesso","2"); CkJsonObject_UpdateString(json,"idProduto","9"); CkJsonObject_UpdateString(json,"nuNegociacao","262200000000005577"); CkJsonObject_UpdateString(json,"nuCliente","SEU_NUM_CLIENTE"); CkJsonObject_UpdateString(json,"dtEmissaoTitulo","21.09.2016"); CkJsonObject_UpdateString(json,"dtVencimentoTitulo","21.09.2016"); CkJsonObject_UpdateString(json,"vlNominalTitulo","888888"); CkJsonObject_UpdateString(json,"cdEspecieTitulo","2"); CkJsonObject_UpdateString(json,"nomePagador","NOME DO PAGADOR"); CkJsonObject_UpdateString(json,"logradouroPagador","ENDERECO DO PAGADOR"); CkJsonObject_UpdateString(json,"nuLogradouroPagador","1145"); CkJsonObject_UpdateString(json,"complementoLogradouroPagador","APTO 34"); CkJsonObject_UpdateString(json,"cepPagador","5588"); CkJsonObject_UpdateString(json,"complementoCepPagador","1"); CkJsonObject_UpdateString(json,"bairroPagador","BAIRRO PAGADOR"); CkJsonObject_UpdateString(json,"municipioPagador","MUNICIPIO PAGADOR"); CkJsonObject_UpdateString(json,"ufPagador","SP"); CkJsonObject_UpdateString(json,"cdIndCpfcnpjPagador","2"); CkJsonObject_UpdateString(json,"nuCpfcnpjPagador","12668000159"); CkJsonObject_UpdateString(json,"endEletronicoPagador","PAGADOR@BRADESCO.COM.BR"); CkJsonObject_UpdateString(json,"nomeSacadorAvalista","NOME SACADOR AVALISTA"); CkJsonObject_UpdateString(json,"logradouroSacadorAvalista","ENDERECO SACADOR AVALISTA"); CkJsonObject_UpdateString(json,"nuLogradouroSacadorAvalista","5555"); CkJsonObject_UpdateString(json,"complementoLogradouroSacadorAvalista","BLOCO 23"); CkJsonObject_UpdateString(json,"cepSacadorAvalista","6182"); CkJsonObject_UpdateString(json,"complementoCepSacadorAvalista","160"); CkJsonObject_UpdateString(json,"bairroSacadorAvalista","BAIRRO SACADOR AVALISTA"); CkJsonObject_UpdateString(json,"municipioSacadorAvalista","MUNICIPIO SACADOR AVALISTA"); CkJsonObject_UpdateString(json,"ufSacadorAvalista","SP"); CkJsonObject_UpdateString(json,"cdIndCpfcnpjSacadorAvalista","2"); CkJsonObject_UpdateString(json,"nuCpfcnpjSacadorAvalista","12668000159"); CkJsonObject_UpdateString(json,"endEletronicoSacadorAvalista","SACADOR@BRADESCO.COM.BR"); // Load out PFX file cert = CkCert_Create(); success = CkCert_LoadPfxFile(cert,"qa_data/pfx/cert_test123.pfx","test123"); if (success != TRUE) { printf("%s\n",CkCert_lastErrorText(cert)); CkJsonObject_Dispose(json); CkCert_Dispose(cert); return; } crypt = CkCrypt2_Create(); success = CkCrypt2_SetSigningCert(crypt,cert); if (success != TRUE) { printf("%s\n",CkCrypt2_lastErrorText(crypt)); CkJsonObject_Dispose(json); CkCert_Dispose(cert); CkCrypt2_Dispose(crypt); return; } // Use SHA-256 within the signing.. CkCrypt2_putHashAlgorithm(crypt,"sha256"); // IMPORTANT: This example requires Chilkat v9.5.0.77 or later. // Use no authenticated attributes CkCrypt2_putSigningAttributes(crypt,"{}"); CkJsonObject_putEmitCompact(json,TRUE); sigBase64 = CkCrypt2_opaqueSignStringENC(crypt,CkJsonObject_emit(json)); if (CkCrypt2_getLastMethodSuccess(crypt) != TRUE) { printf("%s\n",CkCrypt2_lastErrorText(crypt)); CkJsonObject_Dispose(json); CkCert_Dispose(cert); CkCrypt2_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 = "https://cobranca.bradesconetempresa.b.br/ibpjregistrotitulows/registrotitulohomologacao"; req = CkHttpRequest_Create(); CkHttpRequest_putHttpVerb(req,"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. CkHttpRequest_putContentType(req,"text/xml"); CkHttpRequest_LoadBodyFromString(req,sigBase64,"utf-8"); // We don't actually pass the URL, we set the path here, and the domain is passed below.. CkHttpRequest_putPath(req,"/ibpjregistrotitulows/registrotitulohomologacao"); http = CkHttp_Create(); resp = CkHttp_SynchronousRequest(http,"cobranca.bradesconetempresa.b.br",443,TRUE,req); if (CkHttp_getLastMethodSuccess(http) != TRUE) { printf("%s\n",CkHttp_lastErrorText(http)); CkJsonObject_Dispose(json); CkCert_Dispose(cert); CkCrypt2_Dispose(crypt); CkHttpRequest_Dispose(req); CkHttp_Dispose(http); return; } printf("Response status code: %d\n",CkHttpResponse_getStatusCode(resp)); printf("Response body:\n"); printf("%s\n",CkHttpResponse_bodyStr(resp)); CkHttpResponse_Dispose(resp); CkJsonObject_Dispose(json); CkCert_Dispose(cert); CkCrypt2_Dispose(crypt); CkHttpRequest_Dispose(req); CkHttp_Dispose(http); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.