EmailService.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <?php
  2. namespace App\Services\Common;
  3. use App\Jobs\EmailJob;
  4. use Illuminate\Support\Facades\Cache;
  5. /**
  6. * 邮件服务.
  7. * Class EMailService
  8. * @package App\Services\Common
  9. */
  10. class EmailService
  11. {
  12. /**
  13. *邮箱测试
  14. */
  15. const TEMPLATE_TEST="mail_test";
  16. /**
  17. *邮箱验证
  18. */
  19. const TEMPLATE_VALIDATION="mail_vaildation";
  20. /**
  21. *邮箱重置密码
  22. */
  23. const TEMPLATE_PASSWORD_RESET="mail_password_reset";
  24. /**
  25. * 发送简历到邮箱
  26. */
  27. const TEMPLATE_SEND_RESUME = 'mail_send_resume';
  28. /**
  29. * 发送自定义内容邮件
  30. */
  31. const TEMPLATE_SEND_CONTENT = 'mail_send_content';
  32. /**
  33. * 招聘会预订成功
  34. */
  35. const TEMPLATE_JOBFAIR_APPLY_OK = 'mail_jobfair_apply_ok';
  36. /**
  37. * 招聘会预定失败
  38. */
  39. const TEMPLATE_JOBFAIR_APPLY_ERROR = 'mail_jobfair_apply_error';
  40. /**
  41. * 邀请面试
  42. */
  43. const TEMPLATE_INVITE_INTERVIEWS = 'mail_invite';
  44. /**
  45. * 职位审核未通过
  46. */
  47. const TEMPLATE_MAIL_JOBSNOTALLOW = 'mail_jobsnotallow';
  48. /**
  49. * 职位审核通过
  50. */
  51. const TEMPLATE_MAIL_JOBSALLOW = 'mail_jobsallow';
  52. /**
  53. * @var array
  54. */
  55. protected $callback;
  56. /**
  57. * @var string
  58. */
  59. protected $authTag;
  60. protected $check_route;
  61. /**
  62. * SmsService constructor.
  63. */
  64. public function __construct()
  65. {
  66. $this->callback = [];
  67. $this->authTag='none';
  68. $this->check_route="email.check";
  69. }
  70. /**
  71. * 发送邮件
  72. * @param \Eloquent|string $email
  73. * @param string $templateId
  74. * @param array $titleParams
  75. * @param array $contentParams
  76. */
  77. public function sendMail($email, string $templateId, array $titleParams = [], array $contentParams = [])
  78. {
  79. $emailJob=new EmailJob($email, $templateId, $titleParams, $contentParams);
  80. $emailJob->setCallback($this->callback);
  81. dispatch($emailJob);
  82. }
  83. /**
  84. * 发送确认邮件
  85. * @param \Eloquent|string $email
  86. * @param string $templateId
  87. */
  88. public function sendAuthMail($email, string $templateId)
  89. {
  90. $emailJob=new EmailJob($email, $templateId, [], [], true);
  91. $emailJob->setCallback($this->callback);
  92. $emailJob->setTag($this->authTag);
  93. $emailJob->setCheckRoute($this->check_route);
  94. dispatch($emailJob);
  95. }
  96. /**
  97. * 根据邮箱code返回缓存信息,如果存在则包含email,邮件模板alias两个字段
  98. * @param string $code
  99. * @return null|array
  100. */
  101. public function checkAuthEmail(string $code)
  102. {
  103. $result=Cache::pull($code, null);
  104. return $result;
  105. }
  106. /**
  107. * 批量发送短信
  108. * @param array $mobiles
  109. * @param string $templateId
  110. * @param array $params
  111. */
  112. public function sendBatchSms(array $mobiles, string $templateId, array $params = [])
  113. {
  114. //
  115. }
  116. /**
  117. * @param string $obj
  118. * @param string $method
  119. * @param array $args
  120. * @return EmailService
  121. */
  122. public function setCallback(string $obj, string $method, array $args)
  123. {
  124. $this->callback[]=[$obj, $method];
  125. $this->callback[]=$args;
  126. return $this;
  127. }
  128. public function setAuthTag(string $tag)
  129. {
  130. $this->authTag=$tag;
  131. return $this;
  132. }
  133. /**
  134. * @param string $check_route
  135. * @return EmailService
  136. */
  137. public function setCheckRoute(string $check_route)
  138. {
  139. $this->check_route = $check_route;
  140. return $this;
  141. }
  142. }