fisafe / api-client
此包的最新版本(0.0.8)没有可用的许可证信息。
`Fisafe Api Client` 是一个强大的 PHP 客户端,旨在与 `fisafe.cloud` API 无缝集成。
0.0.8
2023-09-12 11:52 UTC
Requires
- guzzlehttp/guzzle: ^7.5
README
Fisafe Api Client
是一个强大的 PHP 客户端,旨在与 fisafe.cloud
API 无缝集成。本 README 提供了设置和使用客户端的简要指南。
安装
要安装 Fisafe Api Client,请使用 Composer
composer require fisafe/api-client
确保您已安装并自动加载了必要的依赖项。
初始化
首先,包含所需的文件并使用必要的类
<?php use Fisafe\ApiClient; require('vendor/autoload.php');
通过传递所需的端点初始化客户端
$fisafeClient = new ApiClient('https://myaddress.fisafe.cloud');
身份验证
使用您的 fisafe.cloud
凭证对客户端实例进行身份验证
$fisafeClient->authenticate('your_username', 'your_password');
使用方法
创建用户
$user = $fisafeClient->createUser('my-user-identifier'); echo "User created with ID: {$user->id}" . PHP_EOL;
为用户创建标识符
您可以将用户与“pin”、“rfid-tag”或“license-plate”等标识符相关联
$identifierType = 'rfid-tag'; // Choose from 'pin', 'rfid-tag', or 'licence-plate' $identifierValue = '121212121'; $identifier = $fisafeClient->createIdentifer($user->id, $identifierValue, $identifierType); echo "Identifier {$identifierValue} of type {$identifierType} created for User ID: {$user->id}" . PHP_EOL;
列出用户
检索具有特定标识符的用户列表
$filteredUsers = $fisafeClient->listUsers(['identifier' => 'my-user-identifier']); echo "List of users with identifier 'my-user-identifier':" . PHP_EOL; var_dump($filteredUsers);
授予用户访问权限(假设存在函数和上下文逻辑)
$contextId = 12345; // Example context ID $fromDate = new DateTime('now'); $toDate = new DateTime('+1 month'); $access = $fisafeClient->createGrantedAccess($contextId, $user->id, $fromDate, $toDate); echo "Access granted to context {$contextId} from {$fromDate->format('Y-m-d')} to {$toDate->format('Y-m-d')}" . PHP_EOL;
结论
Fisafe Api Client
提供了一种简化的方法来与 fisafe.cloud
API 交互,简化了用户、标识符和访问权限的管理。有关更详细的信息,请参阅完整文档或官方 API 文档。
注意:在生产代码中,始终适当处理异常并检查返回值。