minkbear/webhook

Webhook 通知驱动

1.2.0 2018-05-07 18:04 UTC

This package is auto-updated.

Last update: 2024-09-24 20:19:56 UTC


README

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

此包使您能够通过 Laravel 5.3 通知系统轻松发送 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');
    }
}

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

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

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

可用方法

  • data(''):接受用于 Webhook 体的可 JSON 编码值。
  • userAgent(''):接受用于 Webhook 用户代理的字符串值。
  • header($name, $value):设置要随 POST Webhook 一起发送的附加头信息。

变更日志

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

测试

$ composer test

安全性

如果您发现任何与安全性相关的问题,请通过电子邮件 m.pociot@gmail.com 而不是使用问题跟踪器。

贡献

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

鸣谢

许可

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