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
(Delphi DLL) 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.
uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Http, HttpResponse, HttpRequest, JsonObject, Cert, Crypt2; ... procedure TForm1.Button1Click(Sender: TObject); var success: Boolean; json: HCkJsonObject; cert: HCkCert; crypt: HCkCrypt2; sigBase64: PWideChar; url: PWideChar; req: HCkHttpRequest; http: HCkHttp; resp: HCkHttpResponse; begin // 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) then begin Memo1.Lines.Add(CkCert__lastErrorText(cert)); Exit; end; crypt := CkCrypt2_Create(); success := CkCrypt2_SetSigningCert(crypt,cert); if (success <> True) then begin Memo1.Lines.Add(CkCrypt2__lastErrorText(crypt)); Exit; end; // 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) then begin Memo1.Lines.Add(CkCrypt2__lastErrorText(crypt)); Exit; end; // 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) then begin Memo1.Lines.Add(CkHttp__lastErrorText(http)); Exit; end; Memo1.Lines.Add('Response status code: ' + IntToStr(CkHttpResponse_getStatusCode(resp))); Memo1.Lines.Add('Response body:'); Memo1.Lines.Add(CkHttpResponse__bodyStr(resp)); CkHttpResponse_Dispose(resp); CkJsonObject_Dispose(json); CkCert_Dispose(cert); CkCrypt2_Dispose(crypt); CkHttpRequest_Dispose(req); CkHttp_Dispose(http); end; |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.