diff --git a/src/helper.php b/src/helper.php index 488e5a5..914c749 100644 --- a/src/helper.php +++ b/src/helper.php @@ -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 '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); }