PHP code example of apihub-cdc / rc-client-php

1. Go to this page and download the library: Download apihub-cdc/rc-client-php 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/ */

    

apihub-cdc / rc-client-php example snippets


$password = getenv('KEY_PASSWORD');
$this->signer = new \RcClientPhp\Client\Interceptor\KeyHandler(
    "/example/route/keypair.p12",
    "/example/route/cdc_cert.pem",
    $password
);

 protected $host = 'the_url';
 


public function setUp()
{
    $config = new \RcClientPhp\Client\Configuration();
    $config->setHost('the_url');
    $password = getenv('KEY_PASSWORD');
    $this->signer = new \RcClientPhp\Client\Interceptor\KeyHandler(null, null, $password);
    $events = new \RcClientPhp\Client\Interceptor\MiddlewareEvents($this->signer);
    $handler = \GuzzleHttp\HandlerStack::create();
    $handler->push($events->add_signature_header('x-signature'));
    $handler->push($events->verify_signature_header('x-signature'));
    $client = new \GuzzleHttp\Client(['handler' => $handler]);
    $this->apiInstance = new \RcClientPhp\Client\Api\ReporteDeCrditoApi($client, $config);
    $this->x_api_key = "your_api_key";
    $this->username = "your_username";
    $this->password = "your_password";
}    



public function testGetReporte()
    {


        $request = new \RcClientPhp\Client\Model\PersonaPeticion();
        $request->setPrimerNombre("XXXX");
        $request->setApellidoPaterno("XXXX");
        $request->setApellidoMaterno("XXXXX");
        $request->setFechaNacimiento("yyyy-mm-dd");
        $request->setRfc("XXXXXX");
        $request->setNacionalidad("XX");
        $dom = new \RcClientPhp\Client\Model\DomicilioPeticion();
        $dom->setDireccion("XXXXXX");
        $dom->setColoniaPoblacion("XXXXXX");
        $dom->setDelegacionMunicipio("XXXXX");
        $dom->setCiudad("XXXXXXXX");
        $dom->setEstado("XXX");
        $dom->setCP("XXXXX");
        $dom->setFechaResidencia("yyyy-mm-dd");
        $dom->setNumeroTelefono("XXXXXXX");
        $dom->setTipoDomicilio("X");
        $dom->setTipoAsentamiento("XX");

        $request->setDomicilio($dom);

        try {
            $result = $this->apiInstance->getReporte($this->x_api_key, $this->username, $this->password, $request);
            $this->assertTrue($result->getFolioConsulta()!==null);
            echo "testGetReporte finished\n";
            return $result->getFolioConsulta();
        } catch (Exception $e) {
            echo 'Exception when calling ReporteDeCrditoApi->getReporte: ', $e->getMessage(), PHP_EOL;
        }
    }
sh
#ejemplo con php en versión 7.3 para otra versión colocar php{version}-curl
apt-get install php7.3-curl
apt-get install php7.3-mbstring
sh
export KEY_PASSWORD=your_password
sh
export PRIVATE_KEY_FILE=pri_key.pem
export CERTIFICATE_FILE=certificate.pem
export SUBJECT=/C=MX/ST=MX/L=MX/O=CDC/CN=CDC
export PKCS12_FILE=keypair.p12
export ALIAS=circulo_de_credito