定制 sinemacula/laravel-aws-sns-listener 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

sinemacula/laravel-aws-sns-listener

Composer 安装命令:

composer require sinemacula/laravel-aws-sns-listener

包简介

Laravel package to handle AWS SNS notifications with seamless integration and event-driven architecture

README 文档

README

Latest Stable Version Build Status Maintainability Code Coverage Total Downloads

Laravel integration package for receiving AWS SNS webhooks with signature validation, typed payload mapping, and Laravel event dispatch.

What This Package Does

  • Registers an SNS webhook route in your Laravel app.
  • Validates incoming SNS signatures with AWS certificates.
  • Maps SNS payloads to typed message entities.
  • Handles subscription confirmation for expected topics.
  • Dispatches Laravel events for generic and provider-specific notifications.

Installation

composer require sinemacula/laravel-aws-sns-listener

The service provider is auto-discovered by Laravel.

Configuration

Publish the config file:

php artisan vendor:publish --provider="SineMacula\Aws\Sns\SnsServiceProvider"

Key options (config/aws.php):

  • aws.sns.route: webhook path for SNS callbacks (default: /hooks/sns).
  • aws.sns.topics: expected topic ARNs for subscription confirmation checks.

Environment examples:

AWS_SNS_ROUTE=/hooks/sns
AWS_SNS_TOPICS=arn:aws:sns:eu-west-1:123456789012:orders,arn:aws:sns:eu-west-1:123456789012:alerts

To disable auto route registration, set aws.sns.route to false in config.

Request Flow

  1. SNS posts to the configured route.
  2. VerifySnsSignature validates the message signature.
  3. MessageFactory maps the payload to a typed message.
  4. SnsController handles the message and dispatches events.

For SubscriptionConfirmation, the package confirms the subscription URL only when the topic is registered in aws.sns.topics.

Dispatched Events

  • SineMacula\Aws\Sns\Events\SubscriptionConfirmed
  • SineMacula\Aws\Sns\Events\NotificationReceived
  • SineMacula\Aws\Sns\Events\SNSNotificationReceived
  • SineMacula\Aws\Sns\Events\S3NotificationReceived
  • SineMacula\Aws\Sns\Events\SesNotificationReceived
  • SineMacula\Aws\Sns\Events\CloudWatchNotificationReceived

Each event carries a typed message object implementing the matching contract interface from SineMacula\Aws\Sns\Entities\Messages\Contracts.

Example Listener

<?php

namespace App\Listeners;

use SineMacula\Aws\Sns\Events\S3NotificationReceived;

final class HandleS3Notification
{
    public function handle(S3NotificationReceived $event): void
    {
        foreach ($event->getNotification()->getRecords() as $record) {
            // Process each S3 record.
        }
    }
}

Testing

composer test
composer test-coverage
composer check

Contributing

Contributions are welcome via GitHub pull requests.

Security

If you discover a security issue, please contact Sine Macula directly rather than opening a public issue.

License

Licensed under the Apache License, Version 2.0.

统计信息

  • 总下载量: 18.2k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 15
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2024-08-09

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固