Email.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace app\expand\controller;
  3. use app\common\service\HelperService;
  4. use app\common\service\MailService;
  5. use think\Validate;
  6. /**
  7. * 邮件相关
  8. * Class Email
  9. * @package app\expand\controller
  10. */
  11. class Email extends BaseAuth
  12. {
  13. private $_baiDuAccount = null;
  14. public function __construct(){
  15. parent::__construct();
  16. $this->_baiDuAccount = $this->getKey($this->_apiCode);
  17. //验证是否具有访问这个接口的权限
  18. if(!isset($this->_baiDuAccount['email_auth'])){
  19. HelperService::returnJson(['code'=>400,'msg'=>'email interface unauthorized access','data'=>[]]);
  20. }
  21. }
  22. /**
  23. * 发送邮件
  24. */
  25. public function sendMail(){
  26. $params = $this->_params;
  27. $rule = [
  28. 'send_name|发送者姓名'=>'require',
  29. 'theme_name|主题'=>'require',
  30. 'content|内容'=>'require',
  31. 'reply_mail|回复致xx邮箱'=>'require',
  32. 'to_mail|发送致xx邮箱'=>'require',
  33. ];
  34. $validate = new Validate($rule);
  35. if(!$validate->check($params)){
  36. HelperService::returnJson(['code'=>400,'msg'=>$validate->getError(),'data'=>$params]);
  37. }
  38. $mailService = new MailService();
  39. $sendName = $params['send_name'];
  40. $themeName = $params['theme_name'];
  41. $content = $params['content'];
  42. $replyMail = $params['reply_mail'];
  43. $toMail = $params['to_mail'];
  44. $result = $mailService->send($sendName,$themeName,$content,$replyMail,$toMail);
  45. if(!$result){
  46. HelperService::returnJson(['code'=>400,'msg'=>HelperService::$_httpErr,'data'=>[]]);
  47. }
  48. HelperService::returnJson(['code'=>200,'msg'=>'success','data'=>[]]);
  49. }
  50. }