Swift
Swift
Banco Inter Obtendo uma lista de boletos
See more Banco Inter Examples
Get a list of tickets that match the search criteria.Chilkat Swift Downloads
func chilkatTest() {
var success: Bool = false
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let http = CkoHttp()!
// Implements the following CURL command:
// curl \
// -X GET \
// -H "Authorization: Bearer $TOKEN" \
// --cert <nome arquivo certificado>.crt \
// --key <nome arquivo chave privada>.key \
// --get \
// --data-urlencode "dataInicial=2022-04-01" \
// --data-urlencode "dataFinal=2022-04-03" \
// --data-urlencode "situacao=VENCIDO" \
// --data-urlencode "tipoOrdenacao=ASC" \
// --data-urlencode "itensPorPagina=10" \
// --data-urlencode "paginaAtual=2" \
// https://cdpj.partners.bancointer.com.br/cobranca/v2/boletos
// Use the following online tool to generate HTTP code from a CURL command
// Convert a cURL Command to HTTP Source Code
let cert = CkoCert()!
success = cert.load(fromFile: "<nome arquivo certificado>.crt")
if success == false {
print("\(cert.lastErrorText!)")
return
}
let bdPrivKey = CkoBinData()!
success = bdPrivKey.loadFile(path: "<nome arquivo chave privada>.key")
if success == false {
print("Failed to load key")
return
}
// Note: If your private key file requires a password, then set it here.
// Otherwise pass the empty string.
var privKeyPassword: String? = ""
let privKey = CkoPrivateKey()!
success = privKey.loadAnyFormat(privKeyData: bdPrivKey, password: privKeyPassword)
if success == false {
print("\(privKey.lastErrorText!)")
return
}
success = cert.setPrivateKey(privKey: privKey)
if success == false {
print("\(cert.lastErrorText!)")
return
}
http.setSslClientCert(cert: cert)
let queryParams = CkoJsonObject()!
queryParams.updateString(jsonPath: "dataInicial", value: "2022-04-01")
queryParams.updateString(jsonPath: "dataFinal", value: "2022-04-03")
queryParams.updateString(jsonPath: "situacao", value: "VENCIDO")
queryParams.updateString(jsonPath: "tipoOrdenacao", value: "ASC")
queryParams.updateInt(jsonPath: "itensPorPagina", value: 10)
queryParams.updateInt(jsonPath: "paginaAtual", value: 2)
// Adds the "Authorization: Bearer $TOKEN" header.
http.authToken = "$TOKEN"
let resp = CkoHttpResponse()!
success = http.httpParams(verb: "GET", url: "https://cdpj.partners.bancointer.com.br/cobranca/v2/boletos", json: queryParams, response: resp)
if success == false {
print("\(http.lastErrorText!)")
return
}
let sbResponseBody = CkoStringBuilder()!
resp.getBodySb(sb: sbResponseBody)
let jResp = CkoJsonObject()!
jResp.loadSb(sb: sbResponseBody)
jResp.emitCompact = false
print("Response Body:")
print("\(jResp.emit()!)")
var respStatusCode: Int = resp.statusCode.intValue
print("Response Status Code = \(respStatusCode)")
if respStatusCode >= 400 {
print("Response Header:")
print("\(resp.header!)")
print("Failed.")
return
}
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "totalPages": 1,
// "totalElements": 58,
// "last": true,
// "first": true,
// "size": 100,
// "numberOfElements": 58,
// "content": [
// {
// "nomeBeneficiario": "nome do beneficiario 1",
// "cnpjCpfBeneficiario": "CNPJ/CPF beneficiario 1"
// },
// {
// "nomeBeneficiario": "nome do beneficiario 2",
// "cnpjCpfBeneficiario": "CNPJ/CPF beneficiario 2"
// },
// {
// "nomeBeneficiario": "nome do beneficiario N",
// "cnpjCpfBeneficiario": "CNPJ/CPF beneficiario N"
// }
// ]
// }
// Sample code for parsing the JSON response...
// Use the following online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON
var nomeBeneficiario: String?
var cnpjCpfBeneficiario: String?
var totalPages: Int = jResp.int(of: "totalPages").intValue
var totalElements: Int = jResp.int(of: "totalElements").intValue
var last: Bool = jResp.bool(of: "last")
var first: Bool = jResp.bool(of: "first")
var size: Int = jResp.int(of: "size").intValue
var numberOfElements: Int = jResp.int(of: "numberOfElements").intValue
var i: Int = 0
var count_i: Int = jResp.size(ofArray: "content").intValue
while i < count_i {
jResp.i = i
nomeBeneficiario = jResp.string(of: "content[i].nomeBeneficiario")
cnpjCpfBeneficiario = jResp.string(of: "content[i].cnpjCpfBeneficiario")
i = i + 1
}
}