а-мазалов / a1-通知频道
A1运营商短信通知频道(欢迎)
v1.0.3
2021-03-19 08:01 UTC
Requires
- php: ^7.3|^8.0
Requires (Dev)
- guzzlehttp/guzzle: ^7.2
- orchestra/testbench: ^6.0
- phpunit/phpunit: ^8.0
README
此包添加了通过A1运营商(Velcome)发送短信通知的功能
安装
通过composer安装
composer require a-mazalov/a1-notification-channel
然后需要指定访问数据。
配置
php artisan vendor:publish --provider="A1\Channel\A1ServiceProvider" --tag="config"
配置文件
// config/a1.php return [ "api_key" => env('A1_API_KEY', null), "api_login" => env('A1_API_LOGIN', null), "api_scheme" => env('A1_API_SCHEME', 'http'), "api_endpoint" => env('A1_API_ENDPOINT', 'http://smart-sender.a1.by/api/'), ];
可用的ENV变量
A1_API_KEY= A1_API_LOGIN= A1_API_SCHEME=http A1_API_ENDPOINT=http://smart-sender.a1.by/api/
在Lumen中安装
注册提供者
// bootstrap/app.php $app->register(A1\Channel\A1ServiceProvider::class); // Опционально регистрация фасада $app->withFacades(true, [ // ... 'A1\Channel\A1Facade' => 'A1Client', ]);
使用
通知渠道示例
namespace App\Notifications; use A1\Channel\A1Message; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Notifications\Messages\MailMessage; use Illuminate\Notifications\Notification; class TestNotification extends Notification { use Queueable; public $message; public function __construct($message) { $this->message = $message; } public function via($notifiable) { return ['a1']; } // .. public function toA1($notifiable) { return (new A1Message) ->content($this->message); } }
从模型获取电话号码
// App\Models\v1\Employee // Так же необходимо добавить трейт для уведомлений use Notifiable; public function routeNotificationForA1() { return $this->mtel ? '375' . $this->mtel : null; }
通知用户
$user->notify(new Notification())
通过门面直接发送短信
// A1\Channel\A1Client; A1Client::sendSms('375290001122', 'Текст сообщения');
测试
composer test
变更日志
有关最近更改的更多信息,请参阅变更日志。
贡献
有关详细信息,请参阅贡献指南。
致谢
许可
MIT许可(MIT)。有关更多信息,请参阅许可文件。