Skip to content

Commit

Permalink
增加TP5.1支持
Browse files Browse the repository at this point in the history
  • Loading branch information
liu21st committed Sep 15, 2017
1 parent 9572406 commit 3a08ebe
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 14 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# think-captcha
thinkphp5 验证码类库
thinkphp5.1 验证码类库

## 安装
> composer require topthink/think-captcha
Expand Down
2 changes: 1 addition & 1 deletion src/Captcha.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace think\captcha;

use think\Session;
use think\facade\Session;

class Captcha
{
Expand Down
6 changes: 3 additions & 3 deletions src/CaptchaController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@

namespace think\captcha;

use think\Config;
use think\facade\Config;

class CaptchaController
{
public function index($id = "")
{
$captcha = new Captcha((array)Config::get('captcha'));
$captcha = new Captcha((array) Config::pull('captcha'));
return $captcha->entry($id);
}
}
}
14 changes: 5 additions & 9 deletions src/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@
// | Author: yunwuxin <[email protected]>
// +----------------------------------------------------------------------

\think\Route::get('captcha/[:id]', "\\think\\captcha\\CaptchaController@index");
Route::get('captcha/[:id]', "\\think\\captcha\\CaptchaController@index");

\think\Validate::extend('captcha', function ($value, $id = '') {
Validate::extend('captcha', function ($value, $id = '') {
return captcha_check($value, $id);
});

\think\Validate::setTypeMsg('captcha', ':attribute错误!');

Validate::setTypeMsg('captcha', ':attribute错误!');

/**
* @param string $id
Expand All @@ -29,17 +28,15 @@ function captcha($id = '', $config = [])
return $captcha->entry($id);
}


/**
* @param $id
* @return string
*/
function captcha_src($id = '')
{
return \think\Url::build('/captcha' . ($id ? "/{$id}" : ''));
return Url::build('/captcha' . ($id ? "/{$id}" : ''));
}


/**
* @param $id
* @return mixed
Expand All @@ -49,7 +46,6 @@ function captcha_img($id = '')
return '<img src="' . captcha_src($id) . '" alt="captcha" />';
}


/**
* @param $value
* @param string $id
Expand All @@ -58,6 +54,6 @@ function captcha_img($id = '')
*/
function captcha_check($value, $id = '')
{
$captcha = new \think\captcha\Captcha((array)\think\Config::get('captcha'));
$captcha = new \think\captcha\Captcha((array) Config::pull('captcha'));
return $captcha->check($value, $id);
}

0 comments on commit 3a08ebe

Please sign in to comment.