noplanman / service-webhook-handler
处理来自各种服务的 Webhooks 的库。
1.0.0
2022-05-27 22:46 UTC
Requires
- php: ^8.0
- ext-curl: *
- ext-json: *
- ext-openssl: *
- cache/void-adapter: ^1.0
- psr/simple-cache: ^1.0|^2.0|^3.0
Requires (Dev)
- ext-memcached: *
- ext-redis: *
- cache/filesystem-adapter: ^1.0
- cache/memcached-adapter: ^1.0
- cache/redis-adapter: ^1.0
- matthiasmullie/scrapbook: ^1.4
- nyholm/psr7: ^1.1
- php-http/curl-client: ^2.0
- php-http/mock-client: ^1.3
- phpunit/phpunit: ^9.5
Suggests
- cache/filesystem-adapter: Cache to files
- cache/memcached-adapter: Cache to memcache
- cache/redis-adapter: Cache to redis
This package is auto-updated.
Last update: 2024-09-05 01:00:41 UTC
README
PHP 库,用于处理来自各种服务的 Webhooks。
要求
通过 Composer 快速安装
此命令将使用 Guzzle HTTP 客户端快速启动。
composer require noplanman/service-webhook-handler:^1.0 guzzlehttp/guzzle:^7.4.3 guzzlehttp/psr7:^2.2
HTTP 客户端
您可以使用以下方式显式设置 HTTP 客户端:
use NPM\ServiceWebhookHandler\Utils;
// Example with Guzzle ($ composer require guzzlehttp/guzzle:^7.4.3 guzzlehttp/psr7:^2.2)
use GuzzleHttp\Client;
Utils::setClient(new Client());
use NPM\ServiceWebhookHandler\Utils;
// Example with HTTPlug with cURL ($ composer require php-http/curl-client:^2.0 nyholm/psr7:^1.1)
use Http\Client\Curl\Client;
Utils::setClient(new Client());
缓存
要启用缓存,请添加任何 PSR-16 兼容适配器 并设置缓存提供程序
use NPM\ServiceWebhookHandler\Utils;
// Example with redis ($ composer require cache/redis-adapter)
use Cache\Adapter\Redis\RedisCachePool;
$client = new Redis();
$client->connect('127.0.0.1', 6379);
Utils::setCache(new RedisCachePool($client));
use NPM\ServiceWebhookHandler\Utils;
// Example with memcached ($ composer require cache/memcached-adapter)
use Cache\Adapter\Memcached\MemcachedCachePool;
$client = new Memcached();
$client->addServer('localhost', 11211);
Utils::setCache(new MemcachedCachePool($client));
用法
到目前为止,为以下提供了一些基本功能:
GitHub
use NPM\ServiceWebhookHandler\Handlers\GitHubHandler;
$handler = new GitHubHandler('webhook_secret');
if ($handler->validate()) {
// All good, use the received data!
$data = $handler->getData();
}
GitLab
use NPM\ServiceWebhookHandler\Handlers\GitLabHandler;
$handler = new GitLabHandler('webhook_secret');
if ($handler->validate()) {
// All good, use the received data!
$data = $handler->getData();
}
Travis CI
use NPM\ServiceWebhookHandler\Handlers\TravisCIHandler;
$handler = new TravisCIHandler();
if ($handler->validate()) {
// All good, use the received data!
$data = $handler->getData();
}
Telegram 登录
use NPM\ServiceWebhookHandler\Handlers\TelegramLoginHandler;
$handler = new TelegramLoginHandler('123:BOT_API_KEY');
if ($handler->validate()) {
// All good, use the received data!
$data = $handler->getData();
}