descom/aws-sns-notification

用于让 Laravel 接收 AWS SNS 通知的包

1.1.0 2024-04-18 14:54 UTC

This package is auto-updated.

Last update: 2024-09-18 15:50:29 UTC


README

tests analyze style

安装

composer require descom/aws-sns-notifications

使用方法

创建一个订阅 HTTPS 以向一个主题发送 SNS

https://:8000/aws/sns/webhook

捕获事件

TopicSubscriptionRequest

use Descom\AwsSnsNotification\Events\TopicSubscriptionRequest;
use Illuminate\Support\Facades\Http;

class SnsSubscriptionConfirmation
{
    public function handle(TopicSubscriptionRequest $event): void
    {
        logger()->info('SNS subscription request', [
            'topic' => $event->topicArn(),
        ]);

        // Confirm the subscription by sending a GET request to the SubscribeURL

        Http::get($event->subscribeUrl());
    }
}

TopicNotification

use Descom\AwsSnsNotification\Events\TopicNotification;
use Illuminate\Support\Facades\Http;

class SnsNotificationLogger
{
    public function handle(TopicNotification $event): void
    {
        logger()->info('SNS Notification received', [
            'topic' => $event->topicArn(),
            'subject' => $event->subject(),
            'message' => $event->toJson(),
        ]);
    }
}