Skip to content

Commit

Permalink
Merge pull request #157 from toplan/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
toplan authored Jun 23, 2017
2 parents 04f4829 + de39e7a commit 9c84274
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,8 @@ SmsManager::storeRule('mobile', [
]);
```

> 存储的动态验证规则可通过访问`host/laravel-sms/info`查看。动态验证规则的名称最好不要和静态验证规则同名,因为静态验证规则的优先级更高。
> 存储的动态验证规则可通过访问`http[s]://your-domain/laravel-sms/info`查看。
> 动态验证规则的名称最好不要和静态验证规则同名,因为静态验证规则的优先级更高。
#### retrieveRule($field[, $name])

Expand Down Expand Up @@ -504,7 +505,7 @@ SmsManager::forgetRules('mobile');

#### input([$key][, $default])

获取客户端传递来的数据。客户端数据会自动注入到配置文件(`laravel-sms.php`)中闭包函数的第三个参数中
获取客户端传递来的数据。客户端数据会自动注入到配置文件(`laravel-sms.php`)中闭包函数的`$input`参数中
```php
$mobileRuleName = SmsManager::input('mobile_rule');
$all = SmsManager::input();
Expand Down
2 changes: 1 addition & 1 deletion src/Toplan/LaravelSms/SmsManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class SmsManager
{
const VERSION = '2.6.4';
const VERSION = '2.6.5';

const STATE_KEY = '_state';

Expand Down
14 changes: 9 additions & 5 deletions src/Toplan/LaravelSms/SmsManagerServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,25 +69,29 @@ protected function phpSms()
return true;
}
$data = $task->data ?: [];
$to = is_array($data['to']) ? json_encode($data['to']) : $data['to'];
$id = DB::table('laravel_sms')->insertGetId([
'to' => $data['to'] ?: '',
'to' => $to ?: '',
'temp_id' => json_encode($data['templates']),
'data' => json_encode($data['data']),
'content' => $data['content'] ?: '',
'voice_code' => $data['code'] ?: '',
'created_at' => date('Y-m-d H:i:s', time()),
]);
$data['smsId'] = $id;
$data['_sms_id'] = $id;
$task->data($data);
});

PhpSms::afterSend(function ($task, $result) {
if (!config('laravel-sms.dbLogs', false) || !isset($data['smsId'])) {
if (!config('laravel-sms.dbLogs', false)) {
return true;
}
$microTime = $result['time']['finished_at'];
$finishedAt = explode(' ', $microTime)[1];
$data = $task->data;
if (!isset($data['_sms_id'])) {
return true;
}

DB::beginTransaction();
$dbData = [];
Expand All @@ -96,10 +100,10 @@ protected function phpSms()
if ($result['success']) {
$dbData['sent_time'] = $finishedAt;
} else {
DB::table('laravel_sms')->where('id', $data['smsId'])->increment('fail_times');
DB::table('laravel_sms')->where('id', $data['_sms_id'])->increment('fail_times');
$dbData['last_fail_time'] = $finishedAt;
}
DB::table('laravel_sms')->where('id', $data['smsId'])->update($dbData);
DB::table('laravel_sms')->where('id', $data['_sms_id'])->update($dbData);
DB::commit();
});
}
Expand Down

0 comments on commit 9c84274

Please sign in to comment.