sunnyphp / ttlock
TTLock SDK
0.3.0
2023-11-28 14:22 UTC
Requires
- php: ^7.4 || ^8
- ext-json: *
- php-http/discovery: ^1.19
- symfony/polyfill-php80: ^1.28
- webmozart/assert: ^1.11
Requires (Dev)
- nyholm/psr7: ^1.8
- php-http/guzzle7-adapter: ^1.0
- php-http/mock-client: ^1.6
- phpunit/phpunit: ^9.6
- rector/rector: ^0.18.10
- roave/security-advisories: dev-latest
Suggests
- php-http/client-implementation: Any compatible HTTP client (see https://docs.php-http.org/en/latest/clients.html)
This package is auto-updated.
Last update: 2024-09-28 16:10:18 UTC
README
PHP SDK 用于 TTLock Cloud API v3
安装
如果你使用的是其他 HTTP 客户端(不是 Guzzle 7),请参阅 HTTPlug 文档中的 客户端 & 适配器 列表。
HTTP 客户端应与 PSR-18 兼容(实现 psr/http-client-implementation
)。
composer require sunnyphp/ttlock php-http/guzzle7-adapter
<?php declare(strict_types=1); require_once __DIR__ . '/vendor/autoload.php'; use SunnyPHP\TTLock\Configuration; use SunnyPHP\TTLock\Entrypoint; use SunnyPHP\TTLock\Request\Lock\GetList; use SunnyPHP\TTLock\Request\Lock\Initialize; use SunnyPHP\TTLock\Request\OAuth2\AccessToken; use SunnyPHP\TTLock\Request\User\Register; use SunnyPHP\TTLock\Transport; // initial configuration $entrypoint = new Entrypoint( new Configuration('client_id', 'client_secret', /* access token if needed */), new Transport(\Http\Adapter\Guzzle7\Client::createWithConfig([ 'verify' => false, // disable certificates check ])), ); // register user; retrieve TTLock Cloud API username $register = $entrypoint->getUserRegister(new Register('username', 'password')); var_dump($register->getResponseArray()); // get access token; retrieve access token, refresh token, expiration, etc $tokenResponse = $entrypoint->getOAuth2AccessToken(new AccessToken($register->getUsername(), 'password')); var_dump($tokenResponse->getResponseArray()); // save token response to future requests or refreshing token // ... // inject access token to entrypoint configuration (most of the requests required access token) $entrypoint = $entrypoint->withConfigurationAccessToken($tokenResponse->getAccessToken()); // initialize new lock; access token used under hood; retrieve lockId, keyId $lockData = 'TTLock SDK should return lockData here'; $newLockIds = $entrypoint->getLockInitialize(new Initialize($lockData)); var_dump($newLockIds->getResponseArray()); // get all initialized locks $locks = $entrypoint->getLockList(new GetList()); var_dump($locks->getResponseArray()); // other requests
异常结构
\SunnyPHP\TTLock\Exception\ApiException
- 通信或系统错误\SunnyPHP\TTLock\Exception\CommonException
- 如果响应有错误\SunnyPHP\TTLock\Exception\KeyException
- 如果响应有与Ekey
相关的错误\SunnyPHP\TTLock\Exception\GatewayException
- 如果响应有与Gateway
相关的错误\SunnyPHP\TTLock\Exception\LockException
- 如果响应有与Lock
相关的错误\SunnyPHP\TTLock\Exception\PasscodeException
- 如果响应有与Passcode
或IC
相关的错误
\Webmozart\Assert\InvalidArgumentException
- 如果传入的数据无效