rene-roscher / clicksend-laravel
一个用于创建短信和语音通话的Laravel扩展包,使用ClickSend功能
1.0.1
2024-07-10 23:11 UTC
Requires
- php: >=8.2
- clicksend/clicksend-php: ^5.0
- illuminate/notifications: ~5.0 || ~6.0 || ~7.0 || ~8.0 || ~9.0 || ~10.0
- illuminate/support: ~5.0 || ~6.0 || ~7.0 || ~8.0 || ~9.0 || ~10.0
Requires (Dev)
- mockery/mockery: ^1.0
- phpunit/phpunit: ^9.0
README
此Laravel扩展包将ClickSend集成到Laravel应用中,用于发送短信和语音消息,利用ClickSend的通知功能。
安装
使用composer安装
composer require rene-roscher/clicksend-laravel
配置
在.env和config/services.php中添加ClickSend凭证
.env
CLICKSEND_USERNAME=username
CLICKSEND_PASSWORD=password
config/services.php
'clicksend' => [
'username' => env('CLICKSEND_USERNAME'),
'password' => env('CLICKSEND_PASSWORD'),
],
用法
短信和语音通知示例
简单创建一个新通知并使用首选类发送通知。
注意:确保将电话号码中的所有空格替换为空字符串。
class TestNotificationClickSend extends Notification { /** * Get the notification's delivery channels. * * @return array<int, string> */ public function via(object $notifiable): array { return ['clicksend-voice', 'clicksend-sms']; // All channels are automatically registered by default } /** * Get the mail representation of the notification. */ public function toClicksendVoice(object $notifiable) // Voice { return ClickSendVoiceMessage::create( message: 'Your Verification Code is: 1234 - I repeat: 1234 - Goodbye!', to: $notifiable->phone_number ); // Or return 'Your Verification Code is: 1234 - I repeat: 1234 - Goodbye!'; } public function toClicksendSms(object $notifiable) // SMS { // Default return ClickSendSmsMessage::create( message: 'Your Verification was approved. Thank you! 🎉', to: $notifiable->phone_number ); // Or a single message return 'Your Verification was approved. Thank you! 🎉'; // Or multiple messages at once return ClickSendSmsMessage::create( message: 'Your Verification was approved. Thank you! 🎉', to: $notifiable->phone_number )->addMessage( message: 'Welcome to our platform! 🎉', to: $notifiable->phone_number ); } }
许可
基于MIT许可。