sanakey / laravel-mnotify
通过 Mnotify SMS API 发送 Laravel 通知
dev-main
2020-12-28 18:46 UTC
Requires
- php: ^7.2|8.0
Requires (Dev)
- orchestra/testbench: 4.x-dev
- phpunit/phpunit: 8.4
This package is auto-updated.
Last update: 2024-09-29 02:54:58 UTC
README
通过 Mnotify SMS API 发送 Laravel 通知
安装
您可以通过 composer 安装此包
composer require sanakey/laravel-mnotify
首先,您必须安装服务提供者(对于 Laravel >= 5.5 可跳过)
// config/app.php 'providers' => [ ... Sanakey\\Mnotify\\MnotifyServiceProvider::class, ],
为了使您的通知知道您针对哪个电话号码,请将 routeNotificationForMnotify 方法添加到您的 Notifiable 模型中。
class User extends Model { public function routeNotificationForMnotify() { return $this->contact; // returns a contact number eg 0301045697 } }
您可以使用以下命令发布配置文件
php artisan vendor:publish --tag=mnotify-config
或
php artisan vendor:publish --provider="Sanakey\Mnotify\MnotifyServiceProvider" --tag="mnotify-config"
添加您的 mnotify API 密钥。
在您的 .env 文件中设置您的 mnotify API 密钥。
MNOTIFY_SMS_API_KEY=your mnotify SMS API key
MNOTIFY_APIV2_KEY=your mnotify API V2 key
或
将您的 Mnotify SMS API 密钥和 API V2 密钥添加到您的 config/mnotify.php
文件中。
// config/services.php ... 'sms_api_key' => env('MNOTIFY_SMS_API_KEY'), 'api_v2_key' => env('MNOTIFY_APIV2_KEY'), ...
有关 SMS API 密钥,请访问 SMS API
有关 API V2 密钥,请访问 API v2.0
使用方法
现在您可以在通知中的 via()
方法内部使用该通道,以及使用 mnotify API 发送短信通知。
use Illuminate\Notifications\Notification; use Sanakey\Mnotify\Message; class SMSNotification extends Notification { public function via($notifiable) { return ['mnotify']; } public function toMnotify($notifiable) { return (new Message) ->sender_id('Sender ID') ->title('Approved') ->message('Your account was approved!'); } }
检查余额
要检查您的短信余额,请使用 SMSAPI 对象上的 checkBalance()
方法。
use Sanakey\Mnotify\SMSAPI; $api = new SMSAPI(); $balance =$api->checkBalance();
许可证
MIT 许可证(MIT)。有关更多信息,请参阅 许可证文件。