bskl / laravel-mp-sms
Laravel 5 的 mesajpaneli.com Sms Api 集成。
dev-master
2018-05-06 20:09 UTC
Requires
- php: >=5.5.9
- illuminate/support: >=5.3
This package is not auto-updated.
Last update: 2024-09-24 20:55:26 UTC
README
安装
mesajpaneli.com 网站的非官方 Laravel 5 通知包。
使用 Composer 安装
composer require bskl/laravel-mp-sms
安装完成后,运行以下命令将 mp-sms.php 文件复制到 config 文件夹:
php artisan vendor:publish --provider="Bskl\MpSms\ServiceProvider"
使用 Laravel Notifications
namespace App\Notifications; use Bskl\MpSms\Channels\MpSmsChannel; use Bskl\MpSms\Channels\Messages\MpSmsMessage; use Illuminate\Notifications\Notification; class ExampleNotification extends Notification { /** * Notification via MpSmsChannel. */ public function via($notifiable) { return [MpSmsChannel::class]; } /** * Get the mesajpaneliapi representation of the notification. */ public function toMpSms($notifiable) { return (new MpSmsMessage) ->content("Mesaj içeriği"); } }
此外,您需要向 Notifiable 模型添加 routeNotificationForMpSms() 函数。
namespace App; use Illuminate\Notifications\Notifiable; use Illuminate\Foundation\Auth\User as Authenticatable; class User extends Authenticatable { use Notifiable; /** * Returns the user's phone number. */ public function routeNotificationForMpSms() { return $this->phone; // Örnek: 1234567890 } }
设置 MesajPaneli 账户
将您从 https://smsvitrini.com 获得的用户信息记录到 config/mp-sms.php 文件中。如果您想更方便,可以将这些信息记录到 .env 文件中。
return [ 'username' => env('MPSMS_USERNAME', 'username'), 'password' => env('MPSMS_PASSWORD', 'password'), 'from' => env('MPSMS_FROM', 'from'), ];
独立于 config 文件修改发送者地址
... public function toMpSms($notifiable) { return (new MpSmsMessage) ->content("Mesaj içeriği") ->from("Gönderici"); } }
记录短信发送报告
要记录短信发送报告,请使用 Laravel 的 mpsms 通道。您可以在 config/mp-sms.php 文件中使用 logging 区域记录短信发送报告,并使用 path 区域指定记录的文件路径。记录将使用 Laravel 队列以 2 分钟的延迟进行。
return [ 'logging' => true, 'channels' => [ 'mpsms' => [ 'driver' => 'daily', 'path' => storage_path('logs/mpsms.log'), 'level' => 'debug', 'days' => 7, ], ], ];
独立于 config 文件记录发送报告
... public function toMpSms($notifiable) { return (new MpSmsMessage) ->content("Mesaj içeriği") ->logging(false); } }
许可
MIT