Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

如何获取明文验证码? #17

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
}
],
"license": "Apache-2.0",
"require": {},
"require": {
"topthink/framework": "5.1.*"
},
"autoload": {
"psr-4": {
"think\\captcha\\": "src/"
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 <448901948@qq.com>
// +----------------------------------------------------------------------

\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);
}