Skip to content

Commit

Permalink
Merge pull request #156 from toplan/dev
Browse files Browse the repository at this point in the history
fix bug & update
  • Loading branch information
toplan authored Jun 19, 2017
2 parents 0a43bc9 + e554a73 commit 04f4829
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 14 deletions.
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

### 1. 关于2.0
`laravel-sms` 2.0是基于[toplan/phpsms](https://github.com/toplan/phpsms)开发的适用于`Laravel`框架的手机号验证解决方案。
相较于1.0版本,2.0是使用新思路重构的版本,并且升级备用代理器机制为代理器均衡调度机制。
`phpsms``laravel-sms`提供了全套的短信发送机制,而且`phpsms`也有自己的 service provider ,也就是说你完全可以在`Laravel`框架下无障碍的独立使用`phpsms`
这也是为什么使用`laravel-sms`会在项目中生成两个配置文件(`phpsms.php``laravel-sms.php`)的原因。

Expand Down Expand Up @@ -37,7 +36,7 @@
# 公告

- QQ群:159379848
- 旧版本更新到2.6.0+版本时,建议删除原有的`config/laravel-sms.php`文件和`laravel-sms.js`文件(如果有用到)
- 旧版本更新到2.6.4+版本时,建议更新原有的`config/laravel-sms.php``laravel-sms.js`文件(如果有用到)
- 如果是Laravel 5.1版本,则需要在`config/laravel-sms.php`文件中注释掉`middleware`
- 开发调试过程中,如果需要查看短信发送结果的详细信息,建议打开[数据库日志](#数据库日志)

Expand Down Expand Up @@ -160,9 +159,9 @@ php artisan vendor:publish --provider="Toplan\Sms\SmsManagerServiceProvider"

# 验证码模块

可以直接访问`host/laravel-sms/info`查看该模块是否可用,并可在该页面里观察验证码短信发送状态,方便你进行调试。
可以直接访问`http[s]://your-domain/laravel-sms/info`查看该模块是否启用,并可在该页面里观察验证码短信发送状态,方便你进行调试。

> 如果是api应用(无session)需要带上access token: host/laravel-sms/info?access_token=xxxx
> 如果是api应用(无session)需要在上述地址后面加上`?access_token=xxxx`
### 1. [服务器端]配置短信内容/模板

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.3';
const VERSION = '2.6.4';

const STATE_KEY = '_state';

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

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

DB::beginTransaction();
$dbData = [];
Expand All @@ -97,10 +96,10 @@ protected function phpSms()
if ($result['success']) {
$dbData['sent_time'] = $finishedAt;
} else {
DB::table('laravel_sms')->where('id', $smsId)->increment('fail_times');
DB::table('laravel_sms')->where('id', $data['smsId'])->increment('fail_times');
$dbData['last_fail_time'] = $finishedAt;
}
DB::table('laravel_sms')->where('id', $smsId)->update($dbData);
DB::table('laravel_sms')->where('id', $data['smsId'])->update($dbData);
DB::commit();
});
}
Expand Down
6 changes: 3 additions & 3 deletions src/config/laravel-sms.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
| 验证码短信通用内容
|--------------------------------------------------------------------------
|
| 如需缓存配置,则需使用 `SmsManger::closure($closure)` 方法进行配置
| 如需缓存配置,则需使用 `Toplan\Sms\SmsManger::closure($closure)` 方法进行配置
|
*/
'content' => function ($code, $minutes, $input) {
Expand All @@ -101,7 +101,7 @@
| return $input['isRegister'] ? 'registerTempId' : 'commonId';
| }
|
| 如需缓存配置,则需使用 `SmsManger::closure($closure)` 方法对匿名函数进行配置
| 如需缓存配置,则需使用 `Toplan\Sms\SmsManger::closure($closure)` 方法对匿名函数进行配置
|
*/
'templates' => [
Expand All @@ -125,7 +125,7 @@
| //不返回任何值,那么hello将会从模版数据中移除 :)
| }
|
| 如需缓存配置,则需使用 `SmsManger::closure($closure)` 方法对匿名函数进行配置
| 如需缓存配置,则需使用 `Toplan\Sms\SmsManger::closure($closure)` 方法对匿名函数进行配置
|
*/
'data' => [
Expand Down

0 comments on commit 04f4829

Please sign in to comment.