arhinful / laravel-mnotify
laravel 包用于 mnotify.net
v1.0
2023-01-31 11:29 UTC
This package is auto-updated.
Last update: 2024-09-04 00:01:08 UTC
README
此包允许您轻松使用 Mnotify.net API 向用户发送短信和电话通知。
安装
使用 composer 安装
composer require arhinful/laravel-mnotify
使用/示例
您的接收者必须是数组,例如:['054....'], ['050...', '026...'],在您的 .env 文件中设置这些键
MNOTIFY_KEY=jie.....
MNOTIFY_SENDER_ID="TreySoft CA"
确保 MNOTIFY_SENDER_ID 的值已在您的 mnotify.net 控制台中设置
发送快速短信
use Arhinful\LaravelMnotify\MNotify; <?php namespace App\Http\Controllers; use Arhinful\LaravelMnotify\MNotify; use Illuminate\Http\Request; class UserNotificationController extends Controller { public function sendQuickReminder(){ $notify = new MNotify(); // list of receivers, can be array (multiple receivers) or string (single receiver) $receivers = ['0542092800', '0507455860']; // or $receivers = '0507455860'; // message to send, must be string $message = "Hello users, a quick reminder, we have a scheduled meeting at 2:00 PM today."; $notify->sendQuickSMS($receivers, $message); } }
从模板发送快速短信
$notify = new MNotify(); $receivers = ['0542092800', '0507455860']; $message_template_id = 1; $notify->sendQuickSMSFromTemplate($receivers, $message_template_id);
使用通知通道
namespace App\Notifications; use Arhinful\LaravelMnotify\NotificationDriver\MNotifyMessage; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Notifications\Notification; class TestNotification extends Notification { use Queueable; public function via($notifiable) { return [MNotifyChannel::class]; } public function toMNotify($notifiable) { return (new MNotifyMessage())->message("Hello User: $notifiable->name"); } }
在您的模型中
use Illuminate\Database\Eloquent\Model; class EmailController extends Model { // optional, but mobile number must exist among user's attributes if this method doesn't exist public function routeNotificationForMNotify() : string{ return '0257906340'; } }
在您的控制器中
namespace App\Http\Controllers\EmailController; use App\Models\User; use App\Notifications\TestNotification; class EmailController extends controller { public function notifyUserAction() { $user = \App\Models\User::first(); $user->notify(new TestNotification()); return "Message Sent"; } }