承接 apinator/apinator-php 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

apinator/apinator-php

最新稳定版本:v1.0.2

Composer 安装命令:

composer require apinator/apinator-php

包简介

PHP server SDK for Apinator — trigger events, authenticate channels, verify webhooks

README 文档

README

Packagist Version License: MIT CI

PHP server SDK for Apinator — trigger real-time events, authenticate channels, and verify webhooks.

Features

  • Trigger events on public, private, and presence channels
  • Channel authentication (HMAC-SHA256)
  • Webhook signature verification
  • Channel introspection (list channels, get channel info)
  • Zero external dependencies — PHP 8.1+ stdlib only
  • Laravel integration guide included

Installation

composer require apinator/apinator-php

Quick Start

use Apinator\Apinator;

$client = new Apinator(
    appId: 'your-app-id',
    key: 'your-app-key',
    secret: 'your-app-secret',
    cluster: 'eu', // or 'us'
);

// Trigger an event
$client->trigger(
    name: 'new-message',
    data: json_encode(['text' => 'Hello!']),
    channel: 'chat-room',
);

Channel Authentication

For private and presence channels, your backend must provide an auth endpoint:

use Apinator\Apinator;

$client = new Apinator(
    appId: 'your-app-id',
    key: 'your-app-key',
    secret: 'your-app-secret',
    cluster: 'eu', // or 'us'
);

// In your auth route handler:
$socketId = $_POST['socket_id'];
$channelName = $_POST['channel_name'];

$auth = $client->authenticateChannel($socketId, $channelName);

header('Content-Type: application/json');
echo json_encode($auth);

For presence channels, include channel data:

$channelData = json_encode([
    'user_id' => $currentUser->id,
    'user_info' => ['name' => $currentUser->name],
]);

$auth = $client->authenticateChannel($socketId, $channelName, $channelData);

Webhook Verification

use Apinator\Apinator;

$client = new Apinator(
    appId: 'your-app-id',
    key: 'your-app-key',
    secret: 'your-webhook-secret',
    cluster: 'eu', // or 'us'
);

$headers = getallheaders();
$body = file_get_contents('php://input');

try {
    $client->verifyWebhook($headers, $body, maxAge: 300);
    // Webhook is valid — process the payload
    $payload = json_decode($body, true);
} catch (\Apinator\Errors\ValidationException $e) {
    http_response_code(401);
    echo 'Invalid webhook';
}

Channel Introspection

// List all channels
$channels = $client->getChannels();

// Filter by prefix
$presenceChannels = $client->getChannels(prefix: 'presence-');

// Get info about a specific channel
$info = $client->getChannel('presence-chat');

API Reference

See docs/api-reference.md for the full API.

Laravel Integration

See docs/laravel.md for a step-by-step Laravel integration guide.

Links

License

MIT — see LICENSE.

统计信息

  • 总下载量: 8
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 10
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-02-16