PHP code example of justcommunication-ru / jcfias-api-php-sdk

1. Go to this page and download the library: Download justcommunication-ru/jcfias-api-php-sdk 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/ */

    

justcommunication-ru / jcfias-api-php-sdk example snippets


$client = new JcFIASClient('login', 'token');

$token = JcFIASClient::getToken($login, $password);

$defaultParams = [
    'assumptions' => false, // ответ с результатами, которые не были найдены в ФИАС
    'autocomplete' => false, // искаться результаты не по точному совпадению, а со *
    'house_number_not_exact' => false
];

/** @var SearchResponse $response */
$response = $client->sendSearchRequest(new SearchRequest('владивосток', ['assumptions' => true]));

$defaultParams = [
    'assumptions' => false, // ответ с результатами, которые не были найдены в ФИАС
];

/** @var SearchBatchResponse $response */
$response = $client->sendSearchBatchRequest(new SearchBatchRequest(['владивосток', 'москва минская']));

/** @var RegionsResponse $response */
$response = $client->sendRegionsRequest(new RegionsRequest());

/** @var TownsResponse $response */
$response = $client->sendTownsRequest(new TownsRequest());

function generateWsseHeader($username, $token): string
{
    $nonce = hash('sha512', uniqid(true));
    $created = date('c');
    $digest = base64_encode(sha1(base64_decode($nonce) . $created . $token, true));

    return sprintf('UsernameToken Username="%s", PasswordDigest="%s", Nonce="%s", Created="%s"',
        $username,
        $digest,
        $nonce,
        $created
    );
}