PHP code example of ervinomueller / cpfcnpj-client

1. Go to this page and download the library: Download ervinomueller/cpfcnpj-client 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/ */

    

ervinomueller / cpfcnpj-client example snippets




namespace App\Services;

use CpfCnpj\Client\HttpClient;
use CpfCnpj\Validator\CpfValidator;

class CpfValidation
{
    private $httpClient;

    public function __construct()
    {
        $validator = new CpfValidator();
        $token = '5ae973d7a997af13f0aaf2bf60e65803';
        
        $this->httpClient = new HttpClient($validator, $token);
    }

    public function consult($cpf, $package)
    {
        $this->httpClient->setPackage($package);
        $result = $this->httpClient->get($cpf);

        var_dump($result);exit;
    }
}

$cpfValidation = new CpfValidation();
$cpfValidation->consult('06413137053', 1);


object(CpfCnpj\Responses\Cpf)[777]
  public 'status' => int 1
  public 'document' => string '064.131.370-53' (length=14)
  public 'name' => string 'Jose Maria' (length=10)
  public 'birthdate' => null
  public 'mother' => null
  public 'gender' => null
  public 'situation' => null
  public 'package' => int 1
  public 'balance' => int 123
  public 'query_id' => string '11bb22cc33dd44ee' (length=16)
  public 'query_time' => float 0.3