foolkaka / laravel-notification-dayu
Alibaba Dayu SMS Channel for Laravel 5.3
Requires
- php: >=5.6.4
- huami-cloud/taobao-php-sdk: 1.0.*
- illuminate/notifications: 5.4.*
- illuminate/support: 5.1.*|5.2.*|5.3.*|5.4.*
Requires (Dev)
- guzzlehttp/guzzle: ~6.0
- mockery/mockery: ^0.9.5
- orchestra/testbench: ^3.3@dev
- phpunit/phpunit: 4.*
This package is not auto-updated.
Last update: 2024-11-10 05:19:28 UTC
README
This package makes it easy to send Dayu Sms notifications with Laravel 5.4.
Contents
Installation
You can install the package via composer:
composer require foolkaka/laravel-notification-channel-dayusms
You must install the service provider:
// 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
:
// 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:
use NotificationChannels\Dayusms\DayusmsChannel; use NotificationChannels\Dayusms\DayusmsMessage; use Illuminate\Notifications\Notification; class ValentineDateApproved extends Notification { public function via($notifiable) { return [DayusmsChannel::class]; } public function toDayusms($notifiable) { return (new DayusmsMessage()) ->content('{"level":"P0", "service":"'.$notifiable->service.'", "info":"502"}'); } }
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
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.
Testing
$ composer test
Security
If you discover any security related issues, please email hfex@huami.com instead of using the issue tracker.
License
The MIT License (MIT). Please see License File for more information.