cache->put($this->cacheKey($key), $phrase, $ttl); } /** * 校验验证码是否正确 * * @param string $key * @param string $phrase * @return bool */ public function testPhrase(string $key, string $phrase): bool { if ($phrase === '') { return false; } $value = (string) $this->cache->pull( $this->cacheKey($key) ); return strtolower($value) === strtolower($phrase); } /** * 校验验证码是否正确 * * @param string $key * @param string $phrase * @return void * * @throws \App\Exceptions\BizException */ public function validatePhrase(string $key, string $phrase): void { if (! $this->testPhrase($key, $phrase)) { throw new BizException(__('Invalid captcha')); } } /** * 生成验证码缓存的 key * * @param string $key * @return string */ protected function cacheKey(string $key): string { return $this->cachePrefix.$key; } }