EmailService.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace App\Modules\Mini\Services;
  3. use App\Base\BaseService;
  4. use App\Exceptions\ClientException;
  5. use App\Mail\RegisterEmail;
  6. use Illuminate\Support\Facades\Cache;
  7. use Illuminate\Support\Facades\Mail;
  8. class EmailService extends BaseService
  9. {
  10. public function emailCaptcha($email, $source)
  11. {
  12. switch ($source) {
  13. case "register":
  14. return $this->register($email);
  15. case "forgetPassword":
  16. return $this->forgetPassword($email);
  17. default:
  18. throw new ClientException("source未匹配");
  19. }
  20. }
  21. public function register($email): bool
  22. {
  23. $captcha = Cache::remember("registerCaptcha" . $email, 10, function () {
  24. return rand(100000, 999999);
  25. });
  26. // try {
  27. Mail::to($email)->send(new RegisterEmail($captcha));
  28. // } catch (\Exception $e) {
  29. // logger()->error("邮件发送失败 ". $e->getMessage());
  30. // throw new ClientException("邮件发送失败,请稍后再试");
  31. // }
  32. return true;
  33. }
  34. public function forgetPassword($email): bool
  35. {
  36. }
  37. private function send($email, $source)
  38. {
  39. }
  40. }