From fbd4df6d4a3e66e472f88803b7b8890f86d2106d Mon Sep 17 00:00:00 2001 From: Anyon Date: Wed, 25 Sep 2019 15:08:53 +0800 Subject: [PATCH] Update CaptchaService.php --- application/admin/service/CaptchaService.php | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/application/admin/service/CaptchaService.php b/application/admin/service/CaptchaService.php index f8bd8e6d3..72f253608 100644 --- a/application/admin/service/CaptchaService.php +++ b/application/admin/service/CaptchaService.php @@ -44,18 +44,17 @@ class CaptchaService { // 动态配置属性 foreach ($config as $k => $v) if (isset($this->$k)) $this->$k = $v; - // 设置字体文件路径 - $this->font = __DIR__ . '/font/icon.ttf'; // 生成验证码序号 $this->uniqid = uniqid('captcha'); // 生成验证码字符串 - $_len = strlen($this->charset) - 1; + $length = strlen($this->charset) - 1; for ($i = 0; $i < $this->codelen; $i++) { - $this->code .= $this->charset[mt_rand(0, $_len)]; + $this->code .= $this->charset[mt_rand(0, $length)]; } // 缓存验证码字符串 Cache::tag('captcha')->set($this->uniqid, $this->code, 360); - p([$this->uniqid, $this->code]); + // 设置字体文件路径 + $this->font = __DIR__ . '/font/icon.ttf'; } /** @@ -137,8 +136,8 @@ class CaptchaService public static function check($code, $uniqid = null) { $_uni = is_string($uniqid) ? $uniqid : input('uniqid', '-'); - $_ver = Cache::tag('captcha')->get($_uni); - if (is_string($_ver) && strtolower($_ver) === strtolower($code)) { + $_val = Cache::tag('captcha')->get($_uni); + if (is_string($_val) && strtolower($_val) === strtolower($code)) { Cache::tag('captcha')->rm($_uni); return true; } else return false;