accessgrid/accessgrid-php
Composer 安装命令:
composer require accessgrid/accessgrid-php
包简介
Official PHP SDK for AccessGrid API
README 文档
README
Official PHP SDK for the AccessGrid API.
Installation
Install via Composer:
composer require accessgrid/accessgrid-php
Requirements
- PHP 7.4 or higher
- cURL extension
- JSON extension
- Hash extension
Quick Start
<?php require_once 'vendor/autoload.php'; use AccessGrid\AccessGridClient; // Initialize the client $client = new AccessGridClient('your-account-id', 'your-secret-key'); // Issue a new access card $card = $client->getAccessCards()->issue([ 'template_id' => 'your-template-id', 'full_name' => 'John Doe', 'expiration_date' => '2024-12-31' ]); echo "Card issued: " . $card->id . "\n"; // Get a specific card $card = $client->getAccessCards()->get('0xc4rd1d'); echo "Card ID: " . $card->id . "\n"; echo "State: " . $card->state . "\n"; echo "Full Name: " . $card->full_name . "\n"; echo "Install URL: " . $card->install_url . "\n"; echo "Expiration Date: " . $card->expiration_date . "\n"; echo "Card Number: " . $card->card_number . "\n"; echo "Site Code: " . $card->site_code . "\n"; echo "Devices: " . count($card->devices) . "\n"; echo "Metadata: " . json_encode($card->metadata) . "\n"; // List cards for a template $cards = $client->getAccessCards()->list('your-template-id'); foreach ($cards as $card) { echo $card . "\n"; } // Suspend a card $suspendedCard = $client->getAccessCards()->suspend($card->id); echo "Card suspended: " . $suspendedCard->state . "\n";
API Reference
AccessGridClient
The main client class for interacting with the AccessGrid API.
Constructor
new AccessGridClient(string $accountId, string $secretKey, string $baseUrl = 'https://api.accessgrid.com')
Access Cards Service
Access the access cards service via $client->getAccessCards().
Methods
issue(array $data): AccessCard- Issue a new access cardprovision(array $data): AccessCard- Alias for issue()get(string $cardId): AccessCard- Get details about a specific access cardupdate(string $cardId, array $data): AccessCard- Update an existing cardlist(string $templateId, ?string $state = null): AccessCard[]- List cards for a templatesuspend(string $cardId): AccessCard- Suspend a cardresume(string $cardId): AccessCard- Resume a suspended cardunlink(string $cardId): AccessCard- Unlink a carddelete(string $cardId): AccessCard- Delete a card
Console Service
Access the console service via $client->getConsole().
Methods
createTemplate(array $data): Template- Create a new card templateupdateTemplate(string $templateId, array $data): Template- Update a templatereadTemplate(string $templateId): Template- Get template detailsgetLogs(string $templateId, array $params = []): array- Get event logs
Error Handling
The SDK throws the following exceptions:
AccessGrid\Exceptions\AccessGridException- Base exception for all API errorsAccessGrid\Exceptions\AuthenticationException- Thrown for authentication failures
try { $card = $client->getAccessCards()->issue($data); } catch (AccessGrid\Exceptions\AuthenticationException $e) { echo "Authentication failed: " . $e->getMessage(); } catch (AccessGrid\Exceptions\AccessGridException $e) { echo "API error: " . $e->getMessage(); }
License
MIT License
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-11-25