EmailCertif.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace App\Mail;
  3. use App\Facades\RedisCache;
  4. use Illuminate\Bus\Queueable;
  5. use Illuminate\Mail\Mailable;
  6. use Illuminate\Queue\SerializesModels;
  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. // 存成字符串:GET /v2/email-certification/{id} 一直返回 "1234",v4 注册页用 === 比对表单里的字符串
  35. RedisCache::put($key, (string) $randomNumber, 30 * 60);
  36. return $this->view('emails.certification.'.$this->lang)
  37. ->with([
  38. 'code' => $randomNumber,
  39. ]);
  40. }
  41. }