CaptchaService.php 591 B

123456789101112131415161718192021222324252627
  1. <?php
  2. namespace App\Modules\Mini\Services;
  3. use App\Base\BaseService;
  4. use Illuminate\Support\Facades\Cache;
  5. class CaptchaService extends BaseService
  6. {
  7. public function createCaptcha($email)
  8. {
  9. return Cache::remember($this->cacheKey($email), 10 * 60, function () use ($email) {
  10. return mt_rand(100000, 999999);
  11. });
  12. }
  13. public function cacheKey($email): string
  14. {
  15. return "email:captcha" . $email;
  16. }
  17. public function checkCaptcha($email, $captcha): bool
  18. {
  19. return Cache::get($this->cacheKey($email)) == $captcha;
  20. }
  21. }