webhooker / webhooker-sdk
与 WebHooker.io API 通信的 SDK
0.4.0
2024-03-27 14:18 UTC
Requires
- php: >=5.5.0
- guzzlehttp/psr7: ^2.4
Requires (Dev)
- guzzlehttp/guzzle: ^7.8.1
- mockery/mockery: ^0.9.4
- phpunit/phpunit: ^9.0.0
- scrutinizer/ocular: ~1.1
- squizlabs/php_codesniffer: ~2.3
Suggests
- guzzlehttp/guzzle: To use as the HTTP library (^6.1)
This package is auto-updated.
Last update: 2024-08-27 15:34:20 UTC
README
与 WebHooker.io API 交互
安装
通过 Composer
composer require webhooker/webhooker-sdk
您还必须安装 Guzzle。默认情况下,该包仅与 Guzzle 6 兼容
composer require guzzlehttp/guzzle
用法
实例化
$webhooker = Webhooker\Webhooker::usingGuzzle('YOUR-API-KEY');
添加订阅者
$subscriber = $webhooker->addSubscriber('Their Name Here'); $subscriber->id;
为订阅者添加接收消息的端点
// you can use "jsonSubscription" or "xmlSubscription" $subscription = $webhooker->subscriber($id)->jsonSubscription($tenantKey, $deliveryUrl, $secret)->save(); $subscription = $webhooker->subscriber($id)->xmlSubscription($tenantKey, $deliveryUrl, $secret)->save(); // additional options for a subscription, e.g. Basic Auth, or "Legacy Payloads" $subscription = $webhooker->subscriber($id) ->jsonSubscription($tenantKey, $deliveryUrl, $secret) ->basicAuth($username, $password) ->legacyPayload('p_reply') ->save(); $subscription->id;
发送 JSON 消息
// $jsonData can be something JSON-able (array/object) or a pre-encoded JSON string $webhooker->notify('account-1', 'something.happened')->json($jsonData)->send();
或者,因为 JSON 非常常见,只需直接传递到 send()
方法
$webhooker->notify('account-1', 'something.happened')->send($jsonData);
发送 XML 消息
// $xmlData must be an XML string $webhooker->notify('account-1', 'something.happened')->xml($xmlData)->send();
发送 XML 和 JSON 消息
$webhooker->notify('account-1', 'something.happened')->xml($xmlData)->json($jsonData)->send();
变更日志
请参阅 CHANGELOG 了解最近更改的详细信息。
测试
composer test
贡献
请参阅 CONTRIBUTING 和 CONDUCT 了解详细信息。
安全
如果您发现任何与安全相关的问题,请通过电子邮件 dan@radweb.co.uk 而不是使用问题跟踪器。
许可
MIT 许可证 (MIT)。请参阅 许可文件 了解更多信息。