-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
10 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# think-captcha | ||
thinkphp5 验证码类库 | ||
thinkphp5.1 验证码类库 | ||
|
||
## 安装 | ||
> composer require topthink/think-captcha | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ | |
|
||
namespace think\captcha; | ||
|
||
use think\Session; | ||
use think\facade\Session; | ||
|
||
class Captcha | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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 | ||
|
@@ -49,7 +46,6 @@ function captcha_img($id = '') | |
return '<img src="' . captcha_src($id) . '" alt="captcha" />'; | ||
} | ||
|
||
|
||
/** | ||
* @param $value | ||
* @param string $id | ||
|
@@ -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); | ||
} |