EmailCertif.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. namespace App\Mail;
  3. use Illuminate\Bus\Queueable;
  4. use Illuminate\Mail\Mailable;
  5. use Illuminate\Queue\SerializesModels;
  6. use App\Tools\RedisClusters;
  7. use Illuminate\Support\Facades\Log;
  8. class EmailCertif extends Mailable
  9. {
  10. use Queueable, SerializesModels;
  11. protected $uuid;
  12. protected $lang;
  13. /**
  14. * Create a new message instance.
  15. *
  16. * @return void
  17. */
  18. public function __construct(string $uuid, string $subject = 'wikipali email certification', string $lang = 'en-US')
  19. {
  20. //
  21. $this->uuid = $uuid;
  22. $this->lang = $lang;
  23. $this->subject($subject);
  24. }
  25. /**
  26. * Build the message.
  27. *
  28. * @return $this
  29. */
  30. public function build()
  31. {
  32. // 生成一个介于 1000 到 9999 之间的随机整数
  33. $randomNumber = random_int(1000, 9999);
  34. $key = "/email/certification/" . $this->uuid;
  35. Log::debug('email certification', ['key' => $key, 'value' => $randomNumber]);
  36. RedisClusters::put($key, $randomNumber, 30 * 60);
  37. return $this->view('emails.certification.' . $this->lang)
  38. ->with([
  39. 'code' => $randomNumber,
  40. ]);
  41. }
  42. }