Skip to content

Commit

Permalink
add email api
Browse files Browse the repository at this point in the history
  • Loading branch information
yaoshanliang committed Mar 31, 2016
1 parent 0c43e10 commit 7d84504
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 34 deletions.
44 changes: 44 additions & 0 deletions app/Http/Controllers/Api/V1/EmailController.php
@@ -0,0 +1,44 @@
<?php

namespace App\Http\Controllers\Api\V1;

use App\Http\Controllers\Api\V1\ApiController;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use App\Http\Controllers\Controller;
use App\Services\Api;

use Queue;
use App\Jobs\Email;

class EmailController extends ApiController
{
/**
* 发送邮件
*
* @param Request $request:
* @return apiReturn
*/
public function postEmail(Request $request)
{
return Api::apiReturn(SUCCESS, '发送成功', $this->_send($request->email, $request->subject, $request->content));
}

/**
* 发送邮件
*
* @param string $email 收件箱, string $subject 主题, string $content 内容
* @return array
*/
public function _send($email, $subject, $content)
{
$this->apiValidate(compact('email', 'subject', 'content'), [
'email' => 'required|email',
'subject' => 'required',
'content' => 'required'
]);

Queue::push(new Email(parent::getAppId(), parent::getUserId(), $email, $subject, $content));
}

}
27 changes: 0 additions & 27 deletions app/Http/Controllers/Api/V1/LogController.php
Expand Up @@ -7,13 +7,9 @@
use Illuminate\Http\Response;
use App\Services\Api;

use Cache;
use Config;
use Queue;
use Validator;
use App\Jobs\AppLog;
use App\Jobs\SmsLog;
use App\Jobs\EmailLog;

class LogController extends ApiController
{
Expand Down Expand Up @@ -63,27 +59,4 @@ public function postSms(Request $request)

return Api::apiReturn(SUCCESS, '记录成功');
}


/**
* 邮件日志
*
* @param string $email 邮箱
* @param string $content 内容
* @return apiReturn
*/
public function postEmail(Request $request)
{
// 验证
$this->apiValidate($request->all(), [
'email' => 'required|email',
'subject' => 'required',
'content' => 'required'
]);

// 日志队列
Queue::push(new EmailLog(parent::getAppId(), parent::getUserId(), $request->email, $request->subject, $request->content));

return Api::apiReturn(SUCCESS, '记录成功');
}
}
1 change: 1 addition & 0 deletions app/Http/routes.php
Expand Up @@ -75,6 +75,7 @@
$api->post('log/email', 'LogController@postEmail');

$api->post('file/file', 'FileController@postFile');
$api->post('email', 'EmailController@postEmail');
});
$api->group([], function ($api) {
$api->post('oauth/accessToken', 'OauthController@getAccessToken');
Expand Down
2 changes: 1 addition & 1 deletion app/Jobs/EmailLog.php → app/Jobs/Email.php
Expand Up @@ -9,7 +9,7 @@
use Illuminate\Contracts\Queue\ShouldBeQueued;
use Mail;

class EmailLog extends Job implements SelfHandling, ShouldBeQueued
class Email extends Job implements SelfHandling, ShouldBeQueued
{

use InteractsWithQueue, SerializesModels;
Expand Down
12 changes: 6 additions & 6 deletions config/oauth2.php
Expand Up @@ -30,22 +30,22 @@
'grant_types' => [
'authorization_code' => [
'class' => '\League\OAuth2\Server\Grant\AuthCodeGrant',
'access_token_ttl' => 3600,
'auth_token_ttl' => 3600
'access_token_ttl' => 3600 * 2,
'auth_token_ttl' => 3600 * 2
],
'refresh_token' => [
'class' => '\League\OAuth2\Server\Grant\RefreshTokenGrant',
'access_token_ttl' => 3600,
'refresh_token_ttl' => 3600
'access_token_ttl' => 3600 * 2,
'refresh_token_ttl' => 3600 * 2
],
'password' => [
'class' => '\League\OAuth2\Server\Grant\PasswordGrant',
'callback' => '\App\Http\Controllers\Auth\AuthController@verifyPassword',
'access_token_ttl' => 3600
'access_token_ttl' => 3600 * 2
],
'client_credentials' => [
'class' => '\League\OAuth2\Server\Grant\ClientCredentialsGrant',
'access_token_ttl' => 3600
'access_token_ttl' => 3600 * 2
]
],

Expand Down

0 comments on commit 7d84504

Please sign in to comment.