timothydc / exact-online-base-client
Exact Online 基础客户端
v1.0.0
2023-11-13 12:24 UTC
Requires
- php: ^8.0
- ext-json: *
- monolog/monolog: ^1.26|^2.2
- picqer/exact-php-client: ^4.2
- symfony/filesystem: ^4.4|^5.4|^6.3
- symfony/lock: ^4.4|^5.4|^6.3
Requires (Dev)
- symplify/easy-coding-standard: 11.1.12
README
此包为Exact Online API提供了一个包装器。
用法
基本配置如下
use TimothyDC\ExactOnline\BaseClient\ExactOnlineClient; use TimothyDC\ExactOnline\BaseClient\ClientConfiguration; use TimothyDC\ExactOnline\BaseClient\Authentication\TokenVault; use Psr\Log\LogLevel; $clientConfiguration = new ClientConfiguration( 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', // client ID 'yyyy', // client secret 'zzzz', // webhook secret 'your-public-callback-url', // redirect URL - should be _exactly_ the same as the URL defined in the EOL app center 'https://start.exactonline.be' // API base URL. Note the ".be" for Belgium ); $tokenVault = new TokenVault(); $tokenVault->setStoragePath('path/to/tokens.json'); $client = new ExactOnlineClient($clientConfiguration, $tokenVault); $client->setLogger($this->logger); // optional logging $client->setDefaultLogLevel(LogLevel::ERROR); // optional log level
授权
如果您想启动新的认证过程,请调用
$client->startAuthorization();
在认证过程中,EOL将重定向您到回调URL。在那里您需要执行以下操作
$client->completeAuthorization('code-from-query-parameters');
现在您的$eolClient
对象已准备好发送API请求
use Picqer\Financials\Exact\Item; $items = (new Item($client->getConnection()))->get();
断开连接
如果您想断开连接并删除访问令牌,请调用客户端上的断开连接函数。
$client->disconnect();
国际化
如果您想以不同语言检索语言相关的字段(例如,项目描述和项目长描述),请使用带有语言参数的连接。
use Picqer\Financials\Exact\Item; $items = (new Item($client->getConnection('FR-BE')))->get();
请参阅Support\ExactLocale.php
文件。更多信息请参阅https://start.exactonline.nl/docs/HlpRestAPIResourcesDetails.aspx?name=LogisticsItems#goodToKnow
自定义
存储驱动程序
默认情况下,令牌将被保存在本地磁盘上的json文件中。
要创建自定义驱动程序,创建一个继承自TokenVaultInterface
接口的自定义Vault类。
use TimothyDC\ExactOnline\BaseClient\Interfaces\AccessTokenInterface; use TimothyDC\ExactOnline\BaseClient\Interfaces\TokenVaultInterface; class TokenVault implements TokenVaultInterface { public function makeToken(?string $accesToken, ?string $refreshToken, int $expiresAt): AccessTokenInterface { } public function store(AccessTokenInterface $accessToken): void { } public function retrieve(): AccessTokenInterface { } public function clear(): void { } }
以及一个继承自AccessTokenInterface
接口的自定义Token类。
use TimothyDC\ExactOnline\BaseClient\Interfaces\AccessTokenInterface; class Token implements AccessTokenInterface { public function getAccessToken(): ?string { } public function getRefreshToken(): ?string { } public function getExpiresAt(): int { } }