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
(Objective-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.
#import <CkoJsonObject.h> #import <CkoCert.h> #import <CkoCrypt2.h> #import <NSString.h> #import <CkoHttpRequest.h> #import <CkoHttp.h> #import <CkoHttpResponse.h> // 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", // } // BOOL success; CkoJsonObject *json = [[CkoJsonObject alloc] init]; [json UpdateString: @"nuCPFCNPJ" value: @"12668"]; [json UpdateString: @"filialCPFCNPJ" value: @"1"]; [json UpdateString: @"ctrlCPFCNPJ" value: @"59"]; [json UpdateString: @"cdTipoAcesso" value: @"2"]; [json UpdateString: @"idProduto" value: @"9"]; [json UpdateString: @"nuNegociacao" value: @"262200000000005577"]; [json UpdateString: @"nuCliente" value: @"SEU_NUM_CLIENTE"]; [json UpdateString: @"dtEmissaoTitulo" value: @"21.09.2016"]; [json UpdateString: @"dtVencimentoTitulo" value: @"21.09.2016"]; [json UpdateString: @"vlNominalTitulo" value: @"888888"]; [json UpdateString: @"cdEspecieTitulo" value: @"2"]; [json UpdateString: @"nomePagador" value: @"NOME DO PAGADOR"]; [json UpdateString: @"logradouroPagador" value: @"ENDERECO DO PAGADOR"]; [json UpdateString: @"nuLogradouroPagador" value: @"1145"]; [json UpdateString: @"complementoLogradouroPagador" value: @"APTO 34"]; [json UpdateString: @"cepPagador" value: @"5588"]; [json UpdateString: @"complementoCepPagador" value: @"1"]; [json UpdateString: @"bairroPagador" value: @"BAIRRO PAGADOR"]; [json UpdateString: @"municipioPagador" value: @"MUNICIPIO PAGADOR"]; [json UpdateString: @"ufPagador" value: @"SP"]; [json UpdateString: @"cdIndCpfcnpjPagador" value: @"2"]; [json UpdateString: @"nuCpfcnpjPagador" value: @"12668000159"]; [json UpdateString: @"endEletronicoPagador" value: @"PAGADOR@BRADESCO.COM.BR"]; [json UpdateString: @"nomeSacadorAvalista" value: @"NOME SACADOR AVALISTA"]; [json UpdateString: @"logradouroSacadorAvalista" value: @"ENDERECO SACADOR AVALISTA"]; [json UpdateString: @"nuLogradouroSacadorAvalista" value: @"5555"]; [json UpdateString: @"complementoLogradouroSacadorAvalista" value: @"BLOCO 23"]; [json UpdateString: @"cepSacadorAvalista" value: @"6182"]; [json UpdateString: @"complementoCepSacadorAvalista" value: @"160"]; [json UpdateString: @"bairroSacadorAvalista" value: @"BAIRRO SACADOR AVALISTA"]; [json UpdateString: @"municipioSacadorAvalista" value: @"MUNICIPIO SACADOR AVALISTA"]; [json UpdateString: @"ufSacadorAvalista" value: @"SP"]; [json UpdateString: @"cdIndCpfcnpjSacadorAvalista" value: @"2"]; [json UpdateString: @"nuCpfcnpjSacadorAvalista" value: @"12668000159"]; [json UpdateString: @"endEletronicoSacadorAvalista" value: @"SACADOR@BRADESCO.COM.BR"]; // Load out PFX file CkoCert *cert = [[CkoCert alloc] init]; success = [cert LoadPfxFile: @"qa_data/pfx/cert_test123.pfx" password: @"test123"]; if (success != YES) { NSLog(@"%@",cert.LastErrorText); return; } CkoCrypt2 *crypt = [[CkoCrypt2 alloc] init]; success = [crypt SetSigningCert: cert]; if (success != YES) { NSLog(@"%@",crypt.LastErrorText); return; } // Use SHA-256 within the signing.. crypt.HashAlgorithm = @"sha256"; // IMPORTANT: This example requires Chilkat v9.5.0.77 or later. // Use no authenticated attributes crypt.SigningAttributes = @"{}"; json.EmitCompact = YES; NSString *sigBase64 = [crypt OpaqueSignStringENC: [json Emit]]; if (crypt.LastMethodSuccess != YES) { NSLog(@"%@",crypt.LastErrorText); 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). NSString *url = @"https://cobranca.bradesconetempresa.b.br/ibpjregistrotitulows/registrotitulohomologacao"; CkoHttpRequest *req = [[CkoHttpRequest alloc] init]; req.HttpVerb = @"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. req.ContentType = @"text/xml"; [req LoadBodyFromString: sigBase64 charset: @"utf-8"]; // We don't actually pass the URL, we set the path here, and the domain is passed below.. req.Path = @"/ibpjregistrotitulows/registrotitulohomologacao"; CkoHttp *http = [[CkoHttp alloc] init]; CkoHttpResponse *resp = [http SynchronousRequest: @"cobranca.bradesconetempresa.b.br" port: [NSNumber numberWithInt: 443] ssl: YES req: req]; if (http.LastMethodSuccess != YES) { NSLog(@"%@",http.LastErrorText); return; } NSLog(@"%@%d",@"Response status code: ",[resp.StatusCode intValue]); NSLog(@"%@",@"Response body:"); NSLog(@"%@",resp.BodyStr); |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.