定制 accessgrid/accessgrid-php 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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 card
  • provision(array $data): AccessCard - Alias for issue()
  • get(string $cardId): AccessCard - Get details about a specific access card
  • update(string $cardId, array $data): AccessCard - Update an existing card
  • list(string $templateId, ?string $state = null): AccessCard[] - List cards for a template
  • suspend(string $cardId): AccessCard - Suspend a card
  • resume(string $cardId): AccessCard - Resume a suspended card
  • unlink(string $cardId): AccessCard - Unlink a card
  • delete(string $cardId): AccessCard - Delete a card

Console Service

Access the console service via $client->getConsole().

Methods

  • createTemplate(array $data): Template - Create a new card template
  • updateTemplate(string $templateId, array $data): Template - Update a template
  • readTemplate(string $templateId): Template - Get template details
  • getLogs(string $templateId, array $params = []): array - Get event logs

Error Handling

The SDK throws the following exceptions:

  • AccessGrid\Exceptions\AccessGridException - Base exception for all API errors
  • AccessGrid\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

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-11-25