修复手动验证方式验证的时候captcha相关配置项修改不生效的bug,同时规范了验证失败时的提示文本!

This commit is contained in:
舒博
2016-12-28 16:10:59 +08:00
committed by 云无心
parent dd0e3cdbf2
commit 9572406f5e

View File

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