recca0120 / twsms
台灣簡訊 twsms api client
Installs: 6 762
Dependents: 0
Suggesters: 0
Security: 0
Stars: 9
Watchers: 1
Forks: 2
Open Issues: 0
pkg:composer/recca0120/twsms
Requires
- php: >=5.5.9
- guzzlehttp/psr7: ^1.4
- nesbot/carbon: ^1.22|^2.0
- php-http/client-implementation: ^1.0|^2.0
- php-http/discovery: ^1.2
- php-http/httplug: ^1.1|^2.0
- php-http/message: ^1.5
Requires (Dev)
- illuminate/support: ^5.1
- mockery/mockery: ~0.9.4|~1.0
- php-http/guzzle6-adapter: ^1.1|^2.0
- phpunit/phpunit: ~4.8|~5.4|~6.1|~7.0
Suggests
- illuminate/notifications: If you need Laravel Notification
README
This package makes it easy to send notifications using [twsms] with Laravel 5.3+.
Contents
Installation
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, ],
Setting up the TwSMS service
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'), ], ...
Usage
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; }
Available methods
content(): Sets a content of the notification message.
sendTime(): Set send time of the notification 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 [email protected] 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.
API Only
composer require taiwan-sms/twsms php-http/guzzle6-adapter
How to use
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', ]; */