EmailCertif.php 1.0 KB

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