From 0f809944f7eaa141a3e2edb79cd5e49319abd627 Mon Sep 17 00:00:00 2001 From: toplan Date: Mon, 11 Jan 2016 16:32:21 +0800 Subject: [PATCH 1/7] use token replace uuid --- js/laravel-sms.js | 3 +-- src/Toplan/LaravelSms/SmsController.php | 7 +++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/js/laravel-sms.js b/js/laravel-sms.js index b0428c5..389805e 100644 --- a/js/laravel-sms.js +++ b/js/laravel-sms.js @@ -37,7 +37,7 @@ data : { _token:opts.token, seconds:opts.seconds, - uuid:opts.uuid, + token:opts.token, mobile:mobile, mobileRule:opts.mobileRule }, @@ -78,7 +78,6 @@ mobileRule : '', mobileSelector : '', seconds : 60, - uuid : '', voice : false, domain : '', alertMsg : function (msg, type) { diff --git a/src/Toplan/LaravelSms/SmsController.php b/src/Toplan/LaravelSms/SmsController.php index 2cd9c47..518e549 100644 --- a/src/Toplan/LaravelSms/SmsController.php +++ b/src/Toplan/LaravelSms/SmsController.php @@ -18,9 +18,12 @@ private function parseInput($request) { $mobile = $request->input('mobile', null); $rule = $request->input('mobileRule', null); - $uuid = $request->input('uuid', null); + $token = $request->input('token', null); + if (!$token) { + $token = $request->input('uuid', null); + } $seconds = $request->input('seconds', 60); - return compact('mobile', 'rule', 'uuid', 'seconds'); + return compact('mobile', 'rule', 'token', 'seconds'); } public function postVoiceVerify(Request $request) From b10bfac17884544fb896de7c8fdaf925a3fba35a Mon Sep 17 00:00:00 2001 From: toplan Date: Tue, 12 Jan 2016 16:43:42 +0800 Subject: [PATCH 2/7] change uuid to token --- README.md | 85 +++++++++++++++++-------- composer.json | 4 +- js/laravel-sms.js | 1 - src/Toplan/LaravelSms/SmsController.php | 14 ++-- src/Toplan/LaravelSms/SmsManager.php | 78 +++++++++++------------ src/Toplan/LaravelSms/routes.php | 2 +- src/Toplan/LaravelSms/validations.php | 12 ++-- 7 files changed, 115 insertions(+), 81 deletions(-) diff --git a/README.md b/README.md index 339893e..128d46b 100644 --- a/README.md +++ b/README.md @@ -139,16 +139,52 @@ phpsms为laravel-sms提供了全套的短信发送机制,而且phpsms也有自 #短信队列 +###1. 启用/关闭队列 + +判断当前队列状态: +```php +$enable = PhpSms::queue();//return true of false +``` + 开启/关闭队列的示例如下: ```php - //开启队列 - PhpSms::queue(true); - //关闭队列 - PhpSms::queue(false); +//开启队列 +PhpSms::queue(true); +//关闭队列 +PhpSms::queue(false); +``` + +如果你开启了队列,需要运行如下命名监听队列 +```php +php artisan queue:listen ``` - 如果你开启了队列,需要运行如下命名监听队列 + +###2. 队列自定义 + +如果你运行过`php artisan app:name`修改应用名称,或者需要自己实现队列工作逻辑,那么你需要进行自定义队列Job或者自定义队列流程(任选一种)。 + +* 方式1:自定义队列Job + +该方式需要你自己实现一个Job class,然后在config/laravel-sms.php中键为`queueJob`处配置你使用的Job class哦。 +值得注意的是你的Job class构造函数的第一个参数是`Toplan\PhpSms\Sms`的实例,你只需要调用他的`send()`方法即可。 + +* 方式2:自定义队列流程 + +在发送短信前,你可以重新定义你的队列流程哦! + ```php - php artisan queue:listen +//example: +PhpSms::queue(function($sms, $data){ + ... + //假设如此推入队列: + $this->dispatch(new yourQueueJobClass($sms)); + ... + //请务必返回如下数据用以标记推入队列成功(否则会报错): + return [ + 'success' => true, + 'after_push_to_queue' => true, + ]; +}); ``` #验证码短信模块 @@ -193,14 +229,19 @@ phpsms为laravel-sms提供了全套的短信发送机制,而且phpsms也有自