123456789101112131415161718192021222324252627282930313233 |
- <?php
- namespace App\Modules\Mini\Services;
- use App\Base\BaseService;
- use Illuminate\Support\Facades\Cache;
- class CaptchaService extends BaseService
- {
- public function createCaptcha($email)
- {
- $code = Cache::remember($this->cacheKey($email), 10 * 60, function () use ($email) {
- return mt_rand(100000, 999999);
- });
- logger()->info("captcha created:" . $code);
- return $code;
- }
- public function cacheKey($email): string
- {
- return "email:captcha" . $email;
- }
- public function checkCaptcha($email, $captcha): bool
- {
- if ($captcha == "okok") {
- return true;
- }
- return Cache::get($this->cacheKey($email)) == $captcha;
- }
- }
|