This package makes it easy to send notifications using [twsms] with Laravel 5.3+.
You can install the package via composer:
composer require taiwan-sms/twsms illuminate/notifications php-http/guzzle6-adapter
Then you must install the service provider:
// config/app.php
'providers' => [
...
TaiwanSms\TwSMS\TwSMSServiceProvider::class,
],
Add your TwSMS login, secret key (hashed password) and default sender name (or phone number) to
your config/services.php
:
// config/services.php
...
'twsms' => [
'username' => env('SERVICES_TWSMS_USERNAME'),
'password' => env('SERVICES_TWSMS_PASSWORD'),
],
...
You can use the channel in your via()
method inside the notification:
use TaiwanSms\TwSMS\TwSMSMessage;
use TaiwanSms\TwSMS\TwSMSChannel;
use Illuminate\Notifications\Notification;
class AccountApproved extends Notification
{
public function via($notifiable)
{
return [TwSMSChannel::class];
}
public function toTwSMS($notifiable)
{
return TwSMSMessage::create("Task #{$notifiable->id} is complete!");
}
}
In your notifiable model, make sure to include a routeNotificationForTwSMS() method, which return the phone number.
public function routeNotificationForTwSMS()
{
return $this->phone;
}
content()
: Sets a content of the notification message.
sendTime()
: Set send time of the notification message.
Please see CHANGELOG for more information what has changed recently.
$ composer test
If you discover any security related issues, please email recca0120@gmail.com instead of using the issue tracker.
Please see CONTRIBUTING for details.
The MIT License (MIT). Please see License File for more information.
composer require taiwan-sms/twsms php-http/guzzle6-adapter
require __DIR__.'/vendor/autoload.php';
use TaiwanSms\TwSMS\Client;
$userId = 'xxx';
$password = 'xxx';
$client = new Client($userId, $password);
var_dump($client->credit()); // 取得額度
var_dump($client->send([
'to' => '09xxxxxxxx',
'text' => 'test message',
]));
/*
return [
'code' => '00000',
'text' => 'Success',
'msgid' => '265078525',
];
*/