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
(Swift 3,4,5...) 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.
func chilkatTest() { // 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", // } // var success: Bool let json = CkoJsonObject()! json.update("nuCPFCNPJ", value: "12668") json.update("filialCPFCNPJ", value: "1") json.update("ctrlCPFCNPJ", value: "59") json.update("cdTipoAcesso", value: "2") json.update("idProduto", value: "9") json.update("nuNegociacao", value: "262200000000005577") json.update("nuCliente", value: "SEU_NUM_CLIENTE") json.update("dtEmissaoTitulo", value: "21.09.2016") json.update("dtVencimentoTitulo", value: "21.09.2016") json.update("vlNominalTitulo", value: "888888") json.update("cdEspecieTitulo", value: "2") json.update("nomePagador", value: "NOME DO PAGADOR") json.update("logradouroPagador", value: "ENDERECO DO PAGADOR") json.update("nuLogradouroPagador", value: "1145") json.update("complementoLogradouroPagador", value: "APTO 34") json.update("cepPagador", value: "5588") json.update("complementoCepPagador", value: "1") json.update("bairroPagador", value: "BAIRRO PAGADOR") json.update("municipioPagador", value: "MUNICIPIO PAGADOR") json.update("ufPagador", value: "SP") json.update("cdIndCpfcnpjPagador", value: "2") json.update("nuCpfcnpjPagador", value: "12668000159") json.update("endEletronicoPagador", value: "PAGADOR@BRADESCO.COM.BR") json.update("nomeSacadorAvalista", value: "NOME SACADOR AVALISTA") json.update("logradouroSacadorAvalista", value: "ENDERECO SACADOR AVALISTA") json.update("nuLogradouroSacadorAvalista", value: "5555") json.update("complementoLogradouroSacadorAvalista", value: "BLOCO 23") json.update("cepSacadorAvalista", value: "6182") json.update("complementoCepSacadorAvalista", value: "160") json.update("bairroSacadorAvalista", value: "BAIRRO SACADOR AVALISTA") json.update("municipioSacadorAvalista", value: "MUNICIPIO SACADOR AVALISTA") json.update("ufSacadorAvalista", value: "SP") json.update("cdIndCpfcnpjSacadorAvalista", value: "2") json.update("nuCpfcnpjSacadorAvalista", value: "12668000159") json.update("endEletronicoSacadorAvalista", value: "SACADOR@BRADESCO.COM.BR") // Load out PFX file let cert = CkoCert()! success = cert.loadPfxFile("qa_data/pfx/cert_test123.pfx", password: "test123") if success != true { print("\(cert.lastErrorText!)") return } let crypt = CkoCrypt2()! success = crypt.setSigning(cert) if success != true { print("\(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 = true var sigBase64: String? = crypt.opaqueSignStringENC(json.emit()) if crypt.lastMethodSuccess != true { print("\(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). var url: String? = "https://cobranca.bradesconetempresa.b.br/ibpjregistrotitulows/registrotitulohomologacao" let req = CkoHttpRequest()! 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.loadBody(from: 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" let http = CkoHttp()! var resp: CkoHttpResponse? = http.synchronousRequest("cobranca.bradesconetempresa.b.br", port: 443, ssl: true, req: req) if http.lastMethodSuccess != true { print("\(http.lastErrorText!)") return } print("Response status code: \(resp!.statusCode.intValue)") print("Response body:") print("\(resp!.bodyStr!)") resp = nil } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.