1. Go to this page and download the library: Download azumamagus/get-cnpj library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
namespace App\Http\Controllers;
use GetCNPJ\CnpjClient;
use Illuminate\Http\JsonResponse;
final class EmpresaController extends Controller
{
public function show(string $cnpj, CnpjClient $client): JsonResponse
{
return response()->json($client->get($cnpj));
}
}
$client = app(\GetCNPJ\CnpjClient::class);
use GetCNPJ\Integrations\Laravel\Facades\GetCNPJ;
use GetCNPJ\ProviderType;
$result = GetCNPJ::get('03.312.791/0001-83');
$brasilApi = GetCNPJ::getFromProvider(
'03312791000183',
ProviderType::BrasilAPI,
);
namespace App\Controllers;
use CodeIgniter\HTTP\ResponseInterface;
final class Empresa extends BaseController
{
public function show(string $cnpj): ResponseInterface
{
$result = service('getCnpj')->get($cnpj);
return $this->response->setJSON($result);
}
}
$client = single_service('getCnpj');
$client = \GetCNPJ\Config\Services::getCnpj();
use GetCNPJ\CnpjClient;
use GetCNPJ\ProviderType;
$client = new CnpjClient();
$result = $client->getFromProvider(
'03312791000183',
ProviderType::BrasilAPI,
);
use GetCNPJ\CnpjClient;
use GetCNPJ\CnpjClientOptions;
$options = new CnpjClientOptions(
timeout: 60,
maxRequestsPerMinute: 5,
enableCnpjWs: true,
enableReceitaWs: true,
enableBrasilApi: true,
enableCnpja: false,
);
$client = new CnpjClient(options: $options);
use GetCNPJ\CnpjClient;
use GuzzleHttp\Client;
$http = new Client([
'timeout' => 15,
'proxy' => 'http://proxy.exemplo:8080',
'http_errors' => false,
]);
$client = new CnpjClient(httpClient: $http);