1. Go to this page and download the library: Download serjazz/diadoc-php-openapi 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/ */
serjazz / diadoc-php-openapi example snippets
declare(strict_types=1);
lientId = 'ваш-client_id';
$clientSecret = 'ваш-client_secret';
$redirectUri = 'https://ваше-приложение/oauth/callback';
$api = new DiadocApi(
$clientId,
$clientSecret,
'https://diadoc-api.kontur.ru/' // или тестовый URL
);
// 1) Получить URL входа и отправить пользователя в браузер:
$loginUrl = $api->buildAuthorizationUrl($redirectUri, 'state-value', null);
// 2) В обработчике callback после редиректа с ?code=...:
// $api->exchangeAuthorizationCode($_GET['code'], $redirectUri);
// 3) Или восстановить ранее сохраненную сессию:
// $api->setOAuthSession($accessToken, $refreshToken, $expiresAtUnix);
$orgList = $api->getMyOrganizations();
echo $orgList->getOrganizations()[0]->getOrgId();
$api = new DiadocApi($ddAuth, '', $diadocUrl);
$api->setAuthMode(DiadocApi::AUTH_MODE_AUTHENTICATE_V3);
$api->authenticateLoginV3($login, $password);
// или $api->setLegacyToken($готовыйТокен);
bash
docker compose run --rm cli php -r "
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.