Webhook 通知驱动程序

2.6.0 2024-03-14 01:48 UTC

This package is auto-updated.

Last update: 2024-09-14 03:07:15 UTC


README

Latest Version on Packagist Software License Build Status StyleCI SensioLabsInsight Quality Score Code Coverage Total Downloads

此包使得使用 Laravel 通知系统发送 Webhook 变得容易。

兼容性

内容

安装

您可以通过 composer 安装此包

composer require laravel-notification-channels/webhook

用法

现在您可以在通知中的 via() 方法中使用此通道

use NotificationChannels\Webhook\WebhookChannel;
use NotificationChannels\Webhook\WebhookMessage;
use Illuminate\Notifications\Notification;

class ProjectCreated extends Notification
{
    public function via($notifiable)
    {
        return [WebhookChannel::class];
    }

    public function toWebhook($notifiable)
    {
        return WebhookMessage::create()
            ->data([
               'payload' => [
                   'webhook' => 'data'
               ]
            ])
            ->userAgent("Custom-User-Agent")
            ->header('X-Custom', 'Custom-Header');
    }
}

为了让您的通知知道哪个 URL 应该接收 Webhook 数据,将 routeNotificationForWebhook 方法添加到您的可通知模型中。

此方法需要返回通知 Webhook 将接收 POST 请求的 URL。

public function routeNotificationForWebhook()
{
    return 'http://requestb.in/1234x';
}

可用方法

  • data(''):接受一个可 JSON 编码的值作为 Webhook 体。
  • query(''):接受一个查询字符串值的关联数组以添加到请求中。
  • userAgent(''):接受一个字符串值作为 Webhook 用户代理。
  • header($name, $value):设置要随 POST Webhook 一起发送的附加头信息。
  • verify():启用 SSL 证书验证或提供 CA 套件路径

变更日志

有关最近更改的更多信息,请参阅 变更日志

测试

$ composer test

安全

如果您发现任何安全问题,请通过电子邮件发送至 atymicq@gmail.com,而不是使用问题跟踪器。

贡献

有关详细信息,请参阅 贡献指南

鸣谢

许可

MIT 许可证 (MIT)。有关更多信息,请参阅 许可文件