mirror of
https://gitee.com/fastadminnet/think-captcha.git
synced 2026-07-01 14:02:47 +08:00
修复手动验证方式验证的时候captcha相关配置项修改不生效的bug,同时规范了验证失败时的提示文本!
This commit is contained in:
@@ -11,49 +11,53 @@
|
||||
|
||||
\think\Route::get('captcha/[:id]', "\\think\\captcha\\CaptchaController@index");
|
||||
|
||||
\think\Validate::extend('captcha', function ($value, $id = "") {
|
||||
return captcha_check($value, $id, (array) \think\Config::get('captcha'));
|
||||
\think\Validate::extend('captcha', function ($value, $id = '') {
|
||||
return captcha_check($value, $id);
|
||||
});
|
||||
|
||||
\think\Validate::setTypeMsg('captcha', '验证码错误!');
|
||||
\think\Validate::setTypeMsg('captcha', ':attribute错误!');
|
||||
|
||||
|
||||
/**
|
||||
* @param string $id
|
||||
* @param array $config
|
||||
* @return \think\Response
|
||||
*/
|
||||
function captcha($id = "", $config = [])
|
||||
function captcha($id = '', $config = [])
|
||||
{
|
||||
$captcha = new \think\captcha\Captcha($config);
|
||||
return $captcha->entry($id);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $id
|
||||
* @return string
|
||||
*/
|
||||
function captcha_src($id = "")
|
||||
function captcha_src($id = '')
|
||||
{
|
||||
return \think\Url::build('/captcha' . ($id ? "/{$id}" : ''));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $id
|
||||
* @return mixed
|
||||
*/
|
||||
function captcha_img($id = "")
|
||||
function captcha_img($id = '')
|
||||
{
|
||||
return '<img src="' . captcha_src($id) . '" alt="captcha" />';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
* @param string $id
|
||||
* @param array $config
|
||||
* @return bool
|
||||
*/
|
||||
function captcha_check($value, $id = "", $config = [])
|
||||
function captcha_check($value, $id = '')
|
||||
{
|
||||
$captcha = new \think\captcha\Captcha($config);
|
||||
$captcha = new \think\captcha\Captcha((array)\think\Config::get('captcha'));
|
||||
return $captcha->check($value, $id);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user