recca0120 / twsms
v1.0.5
2020-05-14 16:33 UTC
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
此包使得使用 [twsms] 在 Laravel 5.3+ 发送通知变得简单。
内容
安装
您可以通过 composer 安装此包
composer require taiwan-sms/twsms illuminate/notifications php-http/guzzle6-adapter
然后您必须安装服务提供者
// config/app.php 'providers' => [ ... TaiwanSms\TwSMS\TwSMSServiceProvider::class, ],
设置 TwSMS 服务
将您的 TwSMS 登录、密钥(哈希密码)和默认发送者名称(或电话号码)添加到您的 config/services.php
// config/services.php ... 'twsms' => [ 'username' => env('SERVICES_TWSMS_USERNAME'), 'password' => env('SERVICES_TWSMS_PASSWORD'), ], ...
使用方法
您可以在通知内的 via()
方法中使用该频道
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!"); } }
在您的可通知模型中,请确保包含一个 routeNotificationForTwSMS() 方法,该方法返回电话号码。
public function routeNotificationForTwSMS() { return $this->phone; }
可用方法
content()
: 设置通知消息的内容。
sendTime()
: 设置通知消息的发送时间。
变更日志
有关最近更改的更多信息,请参阅 CHANGELOG。
测试
$ composer test
安全
如果您发现任何与安全相关的问题,请通过电子邮件 recca0120@gmail.com 而不是使用问题跟踪器。
贡献
有关详细信息,请参阅 CONTRIBUTING。
致谢
许可
MIT 许可证 (MIT)。有关更多信息,请参阅 许可文件。
仅 API
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', ]; */