企微短剧业务系统

EmailQueue.php 1.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: shensong
  5. * Date: 2022/3/22
  6. * Time: 15:47
  7. */
  8. namespace App\Support;
  9. use App\RedisModel;
  10. class EmailQueue
  11. {
  12. const KEY = 'tbk_onlive_admin_email_queue_key';
  13. const DISABLE_EMAIL = [
  14. 'zhiyuan.chen@kuxuan-inc.com'
  15. ];
  16. public static function rPush($title, $content, $emails, $sender = '')
  17. {
  18. // 防止大量错误导致队列堆积
  19. if (RedisModel::lLen(self::KEY) > 1000) {
  20. return;
  21. }
  22. // 剔除已离职人员邮箱
  23. $sendEmails = [];
  24. if(is_array($emails)){
  25. foreach($emails as $email) {
  26. if(!in_array($email, self::DISABLE_EMAIL)) {
  27. $sendEmails[] = $email;
  28. }
  29. }
  30. }
  31. if(empty($sendEmails)) {
  32. return;
  33. }
  34. $emailData = json_encode([
  35. 'title' => $title,
  36. 'content' => $content,
  37. 'emails' => (array) $sendEmails,
  38. 'sender' => $sender
  39. ], JSON_UNESCAPED_UNICODE);
  40. RedisModel::rPush(self::KEY, $emailData);
  41. }
  42. }