疯狂 / laravel-sms-sender
此包的最新版本(dev-dev)没有可用的许可证信息。
短信发送器
此包的规范仓库似乎已不存在,因此该包已被冻结。
dev-dev
2019-03-12 09:11 UTC
Requires
- php: ^7.2
This package is not auto-updated.
Last update: 2019-03-12 09:21:13 UTC
README
通过通知向电话号码发送短信
composer require crazzzzy/laravel-sms-send
将提供者添加到 config/app.php
CraZZzzY\SmsSender\SmsSenderServiceProvider::class,
控制器,示例
<?php
namespace App\Http\Controllers\API\Password\Reset;
use Notification;
use App\Models\User;
use App\Notifications\Sms;
use CraZZzzY\SmsSender\Helpers\SmsHelper;
use CraZZzzY\SmsSender\Helpers\ResponseStatusHelper;
use CraZZzzY\SmsSender\Http\Responses\API\StatusResponse;
use CraZZzzY\SmsSender\Http\Controllers\API\Password\Reset\Phone as ResetPhoneController;
class Phone extends ResetPhoneController
{
protected function reset(array $data) : StatusResponse
{
$user = User::where('phone_number', '=', $data['phone_number'])->first();
if (!($user instanceof User)) {
return new StatusResponse(ResponseStatusHelper::STATUS_ERROR, [
'message' => 'Phone not found.'
]);
}
// Create reset code.
$code = $this->createResetCode($user);
// Send your notification.
Notification::send($user, new Sms(SmsHelper::TYPE_RESET_CODE, $code->code));
return new StatusResponse(ResponseStatusHelper::STATUS_SUCCESS);
}
}
添加路由,示例
Route::group(['namespace' => 'Password', 'as' => 'api.'], function () {
Route::post('phone/password/reset/generate_code', 'Reset\Phone')->name('phone.password.reset.generate_code');
});
创建扩展的通知文件
不排队
// your-notification-class.php
use CraZZzzY\SmsSender\Notifications\SmsSend
class YourNotificationClass extends SmsSend
排队
// your-notification-class.php
use CraZZzzY\SmsSender\Notifications\SmsSendByQueue
class YourNotificationClass extends SmsSendByQueue
在服务中添加您的短信提供商设置。
Clickatell 示例
// config/services.php
...
'clickatell' => [
'user' => env('CLICKATELL_USER'),
'pass' => env('CLICKATELL_PASS'),
'api_id' => env('CLICKATELL_API_ID'),
],
在您的通知方法中添加您的短信提供商
Clickatell 示例
use NotificationChannels\Clickatell\ClickatellMessage;
use NotificationChannels\Clickatell\ClickatellChannel;
use CraZZzzY\SmsSender\Notifications\Traits\SmsSend as TraitSmsSend;
...
use TraitSmsSend;
public function via($notifiable)
{
return [ClickatellChannel::class];
}
public function toClickatell($notifiable)
{
return (new ClickatellMessage())
->content($this->getMessageByType())
;
}
在您的模型方法中为您的短信提供商获取电话字段
Clickatell 示例
public function routeNotificationForClickatell()
{
return [$this->(your-phone-field)];
}
如何使用
TYPE_MESSAGE
use CraZZzzY\SmsSender\Helpers\SmsHelper;
...
Notification::send($user, new YourNotificationClass(SmsHelper::TYPE_MESSAGE, 'your-message'));
TYPE_RESET_CODE
use CraZZzzY\SmsSender\Helpers\SmsHelper;
...
Notification::send($user, new YourNotificationClass(SmsHelper::TYPE_RESET_CODE));
TYPE_ACCOUNT_APPROVED
use CraZZzzY\SmsSender\Helpers\SmsHelper;
...
Notification::send($user, new YourNotificationClass(SmsHelper::TYPE_ACCOUNT_APPROVED));
TYPE_ORDER_APPROVED
use CraZZzzY\SmsSender\Helpers\SmsHelper;
...
Notification::send($user, new YourNotificationClass(SmsHelper::TYPE_ORDER_APPROVED, 'order-number'));
TYPE_ORDER_DECLINED
use CraZZzzY\SmsSender\Helpers\SmsHelper;
...
Notification::send($user, new YourNotificationClass(SmsHelper::TYPE_ORDER_DECLINED, 'order-number'));