承接 andreshg112/aws-sns 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

andreshg112/aws-sns

Composer 安装命令:

composer require andreshg112/aws-sns

包简介

Amazon SNS Notifications Channel for Laravel 6

README 文档

README

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

This package makes it easy to send notifications using Amazon SNS with Laravel 5.3.

Contents

Installation

Can to install with commands:

composer require lab123/aws-sns:dev-master

Or editing the composer.json file:

"require": {
	"lab123/aws-sns": "dev-master"
}

You must install the service provider.

Laravel 5.x

configure in config/app.php:

'providers' => [
    ...
    Lab123\AwsSns\AwsSnsServiceProvider::class,
]

Lumen 5.x

configure in bootstrap/app.php:

$app->register(\Lab123\AwsSns\AwsSnsLumenServiceProvider::class);

** Note: ** You go need make a wrapper Laravel Notification or use a package how Lumen Notification

Setting up the AwsSns service

Follow the Amazon Console generate the APIKEY and API SECRET, which is connecting both.

Create a new sns section inside config/services.php:

...
'sns' => [
    'key' => env('SNS_KEY'),
    'secret' => env('SNS_SECRET'),
    'region' => env('SNS_REGION', 'us-east-1')
],
...

Next we need to add this keys to our Laravel environment. Edit file .env to config the keys:

...
SNS_KEY=YOUR_KEY
SNS_SECRET=YOUR_SECRET
SNS_REGION=YOUR_REGION
...

Default Configurations SMS (OPTIONAL)

You also can config defaults attributes for sending SMS running php artisan vendor:publish --provider="Lab123\AwsSns\AwsSnsServiceProvider" or creating file config/aws-sns.php:

return [

    'sms' => [
        'monthlySpendLimit' => env('SNS_SMS_MONTHLY_LIMIT'),
        'deliveryStatusIAMRole' => env('SNS_SMS_DELIVERY_STATUS_IAM_ROLE'),
        'deliveryStatusSuccessSamplingRate' => env('SNS_SMS_DELIVERY_STATUS'),
        'defaultSenderID' => env('SNS_SMS_SENDER'),
        'defaultSMSType' => env('SNS_SMS_TYPE'),
        'usageReportS3Bucket' => env('SNS_SMS_REPORT_S3')
    ]
]

And now you can set your default configuration for SMS in .env

** Note: ** More information how they work the settings at http://docs.aws.amazon.com/en/sns/latest/api/API_SetSMSAttributes.html

Usage

Sending SMS

To send sms without the need to create a topic, leave the function via as follows:

// Notifications/Welcome.php
/**
 * Get the notification channels.
 *
 * @param mixed $notifiable
 * @return array|string
 */
public function via($notifiable)
{
    return [
        AwsSnsSmsChannel::class
    ];
}

Add function toAwsSnsSms() expected by class AwsSnsSmsChannel to send notification:

// Notifications/Welcome.php
/**
 * Get the AWS SNS SMS Message representation of the notification.
 *
 * @param mixed $notifiable
 * @return \Lab123\AwsSns\Messages\AwsSnsMessage
 */
public function toAwsSnsSms($notifiable)
{
    return (new AwsSnsMessage())->message('Message Here')->phoneNumber('+5511999999999');
}

You also can ignore the ->phoneNumber() in your notification and use function routeNotificationForAwsSnsSms in your Model Notifiable:

// Models/User.php
/**
 * Route notifications for the Aws SNS SMS channel.
 *
 * @return string
 */
public function routeNotificationForAwsSnsSms()
{
    return $this->phone_number;
}

**Note.: ** The expected number use the standards-based international E.123

eg.: +5511999999999

Sending Topic

To send notification to a topic, leave the function via as follows:

// Notifications/Welcome.php
/**
 * Get the notification channels.
 *
 * @param mixed $notifiable
 * @return array|string
 */
public function via($notifiable)
{
    return [
        AwsSnsTopicChannel::class
    ];
}

Add function toAwsSnsTopic() expected by class AwsSnsTopicChannel to send notification:

// Notifications/Welcome.php
/**
 * Get the AWS SNS Topic Message representation of the notification.
 *
 * @param mixed $notifiable
 * @return \Lab123\AwsSns\Messages\AwsSnsMessage
 */
public function toAwsSnsTopic($notifiable)
{
    return (new AwsSnsMessage())->message('Message Here')->topicArn('arn:aws:sns:us-east-1:000000000000:name-topic');
}

You also can ignore the ->topicArn() in your notification and use function routeNotificationForAwsSnsTopic in your Model Notifiable:

// Models/User.php
/**
 * Route notifications for the Aws SNS Topic channel.
 *
 * @return string
 */
public function routeNotificationForAwsSnsTopic()
{
    return $this->topicArn;
}

Available methods

  • topicArn($topicArn): Your Topic Arn from Amazon SNS;
  • phoneNumber($phoneNumber): Phone number to send notification;
  • message($message): Message to be sent;

Changelog

Please see CHANGELOG for more information what has changed recently.

Testing

$ composer test

Security

If you discover any security related issues, please email jean.pierre@lab123.com.br instead of using the issue tracker.

Contributing

Please see CONTRIBUTING for details.

Credits

License

The MIT License (MIT). Please see License File for more information.

andreshg112/aws-sns 适用场景与选型建议

andreshg112/aws-sns 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7 次下载、GitHub Stars 达 2, 最近一次更新时间为 2023 年 09 月 25 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 andreshg112/aws-sns 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 andreshg112/aws-sns 我们能提供哪些服务?
定制开发 / 二次开发

基于 andreshg112/aws-sns 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 7
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 20
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 0
  • Forks: 9
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-09-25