terpise / laravel-webhook
Laravel webhook
1.0.9
2023-08-15 10:29 UTC
Requires
- php: ^8.1
- illuminate/contracts: ^9.0
Requires (Dev)
- nesbot/carbon: ^2.68.1
- nunomaduro/collision: 6.0
- orchestra/testbench: ^7.25
- pestphp/pest: ^1.22
- pestphp/pest-plugin-laravel: 1.4
- phpstan/phpstan: ^1.4.7
- phpunit/phpunit: ^9.6
README
webhook 是一种让应用程序向另一个应用程序提供特定事件信息的方式。这两个应用程序之间通过简单的 HTTP 请求进行通信。
安装
您可以通过 composer 安装此包
composer require terpise/laravel-webhook
您可以使用以下命令发布配置文件
php artisan vendor:publish --tag=webhook-config
您可以使用以下命令发布迁移文件
php artisan vendor:publish --tag=webhook-migrations
运行迁移
php artisan migrate
您可以使用以下命令创建客户端
php artisan webhook:make
php artisan queue:work
客户端
设置回调
Route::get('callback', [WebhookClientController::class, 'verify'])->middleware(VerifyToken::class); Route::post('callback', [WebhookClientController::class, 'callback'])->middleware(VerifyToken::class); // verify use callback authentication when registering // callback method you can get data from webhook // middleware for checking the authenticity of the callback, use 'verify_token' public function verify(Request $request) { return new Response(['challenge' => $request->get('challenge')]); }
创建订阅
$ curl -X POST https://www.domain.com/webhooks/subscribe \ -F client_id=10 \ -F client_secret=7b2946535949ae70f015d696d8ac602830ece412 \ -F callback_url=https://www.domain-client.com/callback \ -F verify_token=5359435949ae70f015d694656d8ac6
查看订阅
$ curl -X GET https://www.domain.com/webhooks/subscribe \ -F client_id=10 \ -F client_secret=7b2946535949ae70f015d696d8ac602830ece412
取消订阅
$ curl -X POST https://www.domain.com/webhooks/unsubscribe \ -F client_id=10 \ -F client_secret=7b2946535949ae70f015d696d8ac602830ece412
使用
WebhookEvent::dispatch([ "event_time" => now(), "event_type" => 'create', "object_id" => 888888, "object_type" => "users", ]);
变更日志
有关最近更改的更多信息,请参阅 变更日志。
贡献
有关详细信息,请参阅 贡献指南。
安全漏洞
有关如何报告安全漏洞,请查看 我们的安全策略。
致谢
许可证
MIT 许可证(MIT)。有关更多信息,请参阅 许可证文件。