premgthb / exabytes-sms
Laravel 包,用于通过 Exabytes API 生成 SMS
v1.0.6
2021-11-18 03:44 UTC
Requires
- php: ^7.4|^8.0
- guzzlehttp/guzzle: ^7.0
- illuminate/support: ^8.0
Requires (Dev)
- orchestra/testbench: ^6.0
- phpunit/phpunit: ^9.0
This package is auto-updated.
Last update: 2024-09-18 10:35:46 UTC
README
composer require premgthb/exabytes-sms
用法
发布配置文件
php artisan vendor:publish --provider="Premgthb\ExabytesSms\ExabytesServiceProvider"
`.env` 值
EXABYTES_SMS_USERNAME = Your account username EXABYTES_SMS_PASSWORD = Your account password
使用以下方式在你的 Laravel 应用程序中设置通知类:
php artisan make:notification ExabytesSmsNotification
然后按照以下代码复制
<?php namespace App\Notifications; use Illuminate\Bus\Queueable; use Illuminate\Notifications\Notification; use Premgthb\ExabytesSms\Notifications\ExabytesSmsChannel; class ExabytesSmsNotification extends Notification { use Queueable; public $content; public function __construct($message) { $this->message = $message; } /** * Get the notification's delivery channels. */ public function via($notifiable) { return [ExabytesSmsChannel::class]; } /** * Get SMS Message content */ public function toExabytes($notifiable) { return $this->message; } }
在你的 User.php 模型中
public function routeNotificationForExabytes() { return preg_replace('/\D+/', '', '6'.$this->mobile_number); }
最后,在你的控制器中使用以下代码片段来触发通知
Notification::route('exabytes', $mobileNumber)->notify(new ExabytesSmsNotification($yourMessage));
你已经准备好使用了!
附加
要生成四位数的 OTP 代码,在你的控制器中
use Exabytes; $otp = Exabytes::generateOtp();
发送不带队列的 SMS
$data = [ 'to' => $request->mobile_number , 'msg' => $request->message ] Exabytes::sendMessage($data);