Alibaba Dayu SMS notifications channel for Laravel 5.4
This package makes it easy to send Dayu Sms notifications with Laravel 5.4., (*1)
Contents
Installation
You can install the package via composer:, (*2)
``` bash
composer require foolkaka/laravel-notification-channel-dayusms, (*3)
You must install the service provider:
```php
// config/app.php
'providers' => [
...
NotificationChannels\Dayusms\DayusmsServiceProvider::class,
],
Setting up your Dayu account
Add your Dayu Account App Key, App Secret, Sms Template Code (optional), Sign Name as sms_from(optional) to your config/services.php:, (*4)
// config/services.php
...
'dayu' => [
'app_key' => env('DAYU_APP_KEY'),
'app_secret' => env('DAYU_APP_SECRET'),
'format' => 'json',
'log_dir' => '/tmp',
'sms_from' => env('DAYU_SMS_SIGN_NAME'),
'sms_type' => 'normal',
'sms_template' => env('DAYU_SMS_TEMPLATE','SMS_9655108')
],
...
Usage
Now you can use the channel in your via() method inside the notification:, (*5)
``` php
use NotificationChannels\Dayusms\DayusmsChannel;
use NotificationChannels\Dayusms\DayusmsMessage;
use Illuminate\Notifications\Notification;, (*6)
class ValentineDateApproved extends Notification
{
public function via($notifiable)
{
return [DayusmsChannel::class];
}, (*7)
public function toDayusms($notifiable)
{
return (new DayusmsMessage())
->content('{"level":"P0", "service":"'.$notifiable->service.'", "info":"502"}');
}
}, (*8)
In order to let your Notification know which phone number you are sending to, add the `routeNotificationForDayusms` method to your Notifiable model e.g your User Model
```php
public function routeNotificationForDayusms()
{
// where `phone` is a field in your users table;
// can set multiple phones as string which separated by comma `,` .
return $this->phone;
}
Available Message methods
SmsMessage
-
from(''): Accepts a sign name to use as the notification sender.
-
content(''): Accepts a json string value for the notification body.
-
content([]): Accepts a array value for the notification body.
-
type(''): Accepts a string value for sms type.
-
template(''): Accepts a string value for sms template.
-
extend(''): Accepts a string value for sms callback using.
Changelog
Please see CHANGELOG for more information what has changed recently., (*9)
Testing
bash
$ composer test, (*10)
Security
If you discover any security related issues, please email hfex@huami.com instead of using the issue tracker., (*11)
License
The MIT License (MIT). Please see License File for more information., (*12)