config = $this->LoadConfig(); /** Parametros obrigatórios */ $this->urlToken = $this->config->{'app'}->{'ticket'}->{'url_token'}; $this->urlApi = $this->config->{'app'}->{'ticket'}->{'url_api_cobranca_bancaria'}; $this->clientId = $this->config->{'app'}->{'ticket'}->{'client_id'}; $this->cert_pem = $this->config->{'app'}->{'ticket'}->{'cert_pem'}; $this->cert_key = $this->config->{'app'}->{'ticket'}->{'cert_key'}; $this->cert_pass = $this->config->{'app'}->{'ticket'}->{'cert_pass'}; $this->numero_contrato = $this->config->{'app'}->{'ticket'}->{'numero_contrato'}; $this->modalidade = $this->config->{'app'}->{'ticket'}->{'modalidade'}; $this->numero_conta_corrente = $this->config->{'app'}->{'ticket'}->{'numeroContaCorrente'}; $this->especie_documento = $this->config->{'app'}->{'ticket'}->{'codigoEspecieDocumento'}; $this->numero_cpfcnpj = $this->config->{'app'}->{'ticket'}->{'numero_cpfcnpj'}; $this->nome = $this->config->{'app'}->{'ticket'}->{'nome'}; $this->instrucao1 = $this->config->{'app'}->{'ticket'}->{'instrucao1'}; $this->instrucao2 = $this->config->{'app'}->{'ticket'}->{'instrucao2'}; $this->multa = $this->config->{'app'}->{'ticket'}->{'multa'}; $this->mora = $this->config->{'app'}->{'ticket'}->{'mora'}; $this->prazo_boleto = $this->config->{'app'}->{'ticket'}->{'prazo_boleto'}; $this->scope = $this->config->{'app'}->{'ticket'}->{'scope'}; /** Pasta padrão de arquivos temporários */ $this->dir = 'temp/'; } /** * @author KÊNIO * @date 04/01/2024 * @description geração do access token */ public function accessToken(): void { /** Inicio do acesso ao endpoint */ $this->ch = curl_init(); curl_setopt_array($this->ch, [ CURLOPT_URL => $this->urlToken, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_RETURNTRANSFER => true, CURLOPT_CUSTOMREQUEST => "POST", CURLOPT_SSLCERT => $this->cert_pem, CURLOPT_SSLKEY => $this->cert_key, CURLOPT_SSLKEYPASSWD => $this->cert_pass, CURLOPT_HTTPHEADER => array( "Accept: application/json", "Content-Type: application/x-www-form-urlencoded"), CURLOPT_POSTFIELDS => "grant_type=client_credentials&client_id={$this->clientId}&scope={$this->scope}" ] ); /** Carrega o resultado */ $this->response = json_decode(curl_exec($this->ch)); /** Carrea as informações da requisição */ $this->info = curl_getinfo($this->ch); /** Caso a requisição não tenha sido positiva, informo o erro */ if($this->info['http_code'] != 200){ /** Adição de elemento de erro*/ array_push($this->errors, 'Status :: '.$this->info['http_code']); } /** Fecha a requisição anteriormente aberta */ curl_close($this->ch); } /** * @author KÊNIO * @date 04/01/2024 * @description Retorna o serviço a ser consumido */ public function sendService(string $escoposDaAPI, array $params, ? string $nameFile): void { /** Legenda * * cobranca_boletos_incluir: Incluir boletos * cobranca_boletos_listar_por_pagador: Serviço para listagem de boletos por pagador * */ /** Parametro de entrada */ $this->escoposDaAPI = $escoposDaAPI; $this->params = $params; $this->nameFile = $nameFile; /** Verifica qual serviço deve ser consumido */ switch($this->escoposDaAPI){ case 'consultar_boleto' : # Serviço para consultar boleto $this->ch = curl_init(); curl_setopt_array($this->ch, array( CURLOPT_URL => $this->urlApiCobrancaBancaria.'boletos'.$this->params, CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_SSLCERT => $this->pem, CURLOPT_SSLKEY => $this->key, CURLOPT_SSLKEYPASSWD => $this->pass, CURLOPT_HTTPHEADER => array( "Content-Type: application/json", "Authorization: Bearer ".$this->response->access_token, "Accept: application/json", "client_id: ".$this->clientId ), )); /** Envia a requisição */ $this->response = json_decode(curl_exec($this->ch)); /** Carrea as informações da requisição */ $this->info = curl_getinfo($this->ch); /** Verifica o status do retorno */ if($this->info['http_code'] != 200){ /** Adição de elemento de erro*/ array_push($this->errors, 'Status :: ('.$this->info['http_code'].') Nenhum boleto localizado para ser listado'); } break; } } /** *@author KÊNIO *@date 17/01/2024 12:53:28 *@description Método retorna o caminho que contém o arquivo PDF do boleto */ public function getAccessToken(): ? string { /** Retorno da informação */ return (string)$this->response->access_token; } /** *@author KÊNIO *@date 15/01/2024 12:53:28 *@description Método retorna o caminho que contém o arquivo PDF do boleto */ public function getFile(): ? string { /** Retorno da informação */ return (string)$this->dir.$this->nameFile; } /** *@author KÊNIO *@date 15/01/2024 12:53:28 *@description Método retorna resposta do serviço consumido */ public function getResponse(): ? string { /** Retorno da informação */ return json_encode($this->response, JSON_PRETTY_PRINT); } /** *@author KÊNIO *@date 15/01/2024 12:53:28 *@description Método retorna resposta do serviço consumido */ public function getResponseObject(): ? object { /** Retorno da informação */ return (object)$this->response; } /** * @author KÊNIO * @date 04/01/2024 * @description Retorna as inconsistências encontradas */ public function getErrors(): ?string { /** Verifico se deve informar os erros */ if (count($this->errors)) { /** Verifica a quantidade de erros para informar a legenda */ $this->info = count($this->errors) > 1 ? 'Os seguintes erros foram encontrados:' : 'O seguinte erro foi encontrado:'; /** Lista os erros */ foreach ($this->errors as $keyError => $error) { /** Monto a mensagem de erro */ $this->info .= '
' . ($keyError + 1) . ' - ' . $error; } /** Retorno os erros encontrados */ return (string)$this->info; } else { return false; } } /** Função para carregar as informações */ private function LoadConfig() { /** Carrego o arquivo de configuração */ return (object)json_decode(file_get_contents('config/config.json')); } public function __destruct() { } }