1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- <?php
- namespace app\expand\controller;
- use app\common\service\HelperService;
- use app\common\service\MailService;
- use think\Validate;
- /**
- * 邮件相关
- * Class Email
- * @package app\expand\controller
- */
- class Email extends BaseAuth
- {
- private $_baiDuAccount = null;
- public function __construct(){
- parent::__construct();
- $this->_baiDuAccount = $this->getKey($this->_apiCode);
- //验证是否具有访问这个接口的权限
- if(!isset($this->_baiDuAccount['email_auth'])){
- HelperService::returnJson(['code'=>400,'msg'=>'email interface unauthorized access','data'=>[]]);
- }
- }
- /**
- * 发送邮件
- */
- public function sendMail(){
- $params = $this->_params;
- $rule = [
- 'send_name|发送者姓名'=>'require',
- 'theme_name|主题'=>'require',
- 'content|内容'=>'require',
- 'reply_mail|回复致xx邮箱'=>'require',
- 'to_mail|发送致xx邮箱'=>'require',
- ];
- $validate = new Validate($rule);
- if(!$validate->check($params)){
- HelperService::returnJson(['code'=>400,'msg'=>$validate->getError(),'data'=>$params]);
- }
- $mailService = new MailService();
- $sendName = $params['send_name'];
- $themeName = $params['theme_name'];
- $content = $params['content'];
- $replyMail = $params['reply_mail'];
- $toMail = $params['to_mail'];
- $result = $mailService->send($sendName,$themeName,$content,$replyMail,$toMail);
- if(!$result){
- HelperService::returnJson(['code'=>400,'msg'=>HelperService::$_httpErr,'data'=>[]]);
- }
- HelperService::returnJson(['code'=>200,'msg'=>'success','data'=>[]]);
- }
- }
|