承接 hachetaustralia/smsbroadcast 相关项目开发

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

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

hachetaustralia/smsbroadcast

Composer 安装命令:

composer require hachetaustralia/smsbroadcast

包简介

SMS Broadcast notification channel for Laravel 8

README 文档

README

Latest Version on Packagist Software License Total Downloads

This package makes it easy to send SMS Broadcast SMS notifications with Laravel 8

Contents

Requirements

  • Sign up for a free SMS Broadcast account

Installation

You can install the package via composer:

composer require hachetaustralia/smsbroadcast

for Laravel 6 and 7, please use the 2.x version of this package. for Laravel 5.8 or lower, please use the 1.x version of this package.

Setting up your SMSBroadcast account

Add the environment variables to your config/services.php:

// config/services.php
...
'smsbroadcast' => [
    'username' => env('SMSBROADCAST_USERNAME'),
    'password' => env('SMSBROADCAST_PASSWORD'),
    'from' => env('SMSBROADCAST_FROM'),
    'sandbox' => env('SMSBROADCAST_SANDBOX'),
],
...

Add your SMS Broadcast username and password as well as the default from number/alphanumeric code to your .env:

// .env
...
SMSBROADCAST_USERNAME=
SMSBROADCAST_PASSWORD=
SMSBROADCAST_FROM=
SMSBROADCAST_SANDBOX=false
],
...

Notice: The from can contain a maximum of 11 alphanumeric characters. You can also specify sandbox to true for testing (no post requests are made).

Setup your route on your notifiable model such as your User with the default destination for that model (single number or array of numbers).

namespace App;

use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    use Notifiable;

    public function routeNotificationForSmsBroadcast()
    {
        return $this->mobile;
    }
}
namespace App;

use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    use Notifiable;

    public function routeNotificationForSmsBroadcast()
    {
        return [ $this->mobile_primary, $this->mobile_secondary ];
    }
}

Using a Custom Logging Channel

Debug logs will automatically use your default logging channel, however you can specify a custom logging channel by adding the following to your config/services.php file:

// config/services.php
...
'smsbroadcast' => [
    'logging_channel' => env('SMSBROADCAST_LOGGING_CHANNEL'),
]
...

And the following to your .env file

// .env
...
SMSBROADCAST_LOGGING_CHANNEL=
...

Usage

Now you can use the channel in your via() method inside the notification:

use NotificationChannels\SMSBroadcast\SMSBroadcastChannel;
use NotificationChannels\SMSBroadcast\SMSBroadcastMessage;
use Illuminate\Notifications\Notification;

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

    public function toSMSBroadcast($notifiable)
    {
        return (new SMSBroadcastMessage("Your {$notifiable->service} was ordered!"));
    }
}

Available methods

Additionally you can add or change recipients (single value or array)

return (new SMSBroadcastMessage("Your {$notifiable->service} was ordered!"))->setRecipients($recipients);

In order to handle a status report you can also set a reference

return (new SMSBroadcastMessage("Your {$notifiable->service} was ordered!"))->setReference($id);

Maximum message splits are supported as well to determine the maximum number of SMS message credits to use per recipient. This defaults to 1.

return (new SMSBroadcastMessage("Your {$notifiable->service} was ordered!"))->setMaxSplit(2);

You can also delay message sending by a specified number of minutes

return (new SMSBroadcastMessage("Your {$notifiable->service} is ready to go!"))->setDelay(10);

Setting a private reference will not transmit to SMS Broadcast and be available should you need it on the MessageWasSent event as a property of the SMSBroadcastMessage. This is useful if you want to set something like a foreign key that you can utilise on a listener listening to the MessageWasSent event.

return (new SMSBroadcastMessage("Your {$notifiable->service} is ready to go!"))->setPrivateReference(12345);

If you wish to use SMS Broadcast's default two-way SMS number as the from number, simply setNoFrom() on the message instance

return (new SMSBroadcastMessage("Your {$notifiable->service} is ready to go!"))->setNoFrom();

Available events

SMS Broadcast Notification channel comes with handy events which provides the required information about the SMS messages.

  1. Message Was Sent (NotificationChannels\SMSBroadcast\Events\MessageWasSent)

Example:

namespace App\Listeners;

use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use NotificationChannels\SMSBroadcast\Events\MessageWasSent;

class SentMessageHandler
{
    /**
     * Handle the event.
     *
     * @param  MessageWasSent  $event
     * @return void
     */
    public function handle(MessageWasSent $event)
    {
        $response = $event->response;
        $message = $event->message;
    }
}

Changelog

Please see CHANGELOG for more information what has changed recently.

Testing

$ composer test

Security

If you discover any security related issues, please email support@hachet.com.au instead of using the issue tracker.

Contributing

Please see CONTRIBUTING for details.

Credits

License

The NoHarm Licence. Please see License File for more information.

hachetaustralia/smsbroadcast 适用场景与选型建议

hachetaustralia/smsbroadcast 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 10.19k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2018 年 08 月 11 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 hachetaustralia/smsbroadcast 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-08-11