Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
aic_duty_strategy
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
yinxiaoling
aic_duty_strategy
Commits
6eed3133
Commit
6eed3133
authored
May 11, 2020
by
yinxiaoling
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
接口验证中间件
parent
623243e9
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
35 additions
and
15 deletions
+35
-15
InfoController.php
app/Http/Controllers/strategy/InfoController.php
+14
-0
CheckApiKey.php
app/Http/Middleware/CheckApiKey.php
+17
-10
DatabaseSeeder.php
database/seeds/DatabaseSeeder.php
+1
-1
api.php
routes/api.php
+3
-4
No files found.
app/Http/Controllers/strategy/InfoController.php
0 → 100644
View file @
6eed3133
<?php
namespace
App\Http\Controllers\strategy
;
use
Illuminate\Http\Request
;
use
App\Http\Controllers\Controller
;
use
App\Http\Controllers\BaseController
;
class
InfoController
extends
BaseController
{
public
function
strategyLists
(
Request
$request
){
dd
(
'策略列表数据'
);
}
}
app/Http/Middleware/CheckApiKey.php
View file @
6eed3133
...
...
@@ -6,8 +6,11 @@ use Closure;
use
App\Http\models\users
;
use
Illuminate\Support\Facades\Log
;
use
App\User
;
use
Illuminate\Support\Facades\DB
;
use
App\Http\Controllers\Tool
;
class
CheckApiKey
{
use
Tool
;
/**
* Handle an incoming request.
*
...
...
@@ -18,7 +21,14 @@ class CheckApiKey
public
function
handle
(
$request
,
Closure
$next
)
{
try
{
$url
=
$request
->
url
;
$url
=
$request
->
url
;
$api_key
=
$request
->
api_key
;
$user_sn
=
$request
->
user_sn
;
if
(
empty
(
$url
)
||
empty
(
$api_key
)
||
empty
(
$user_sn
)){
return
$this
->
errorWithInfo
(
'参数验证不通过'
,
401
);
}
$param
=
$request
->
except
([
'url'
,
'client_info_json'
,
'source'
,
'aes'
,
'upload'
,
'fail_recall_of_reason'
]);
Log
::
channel
(
'api'
)
->
info
(
'API_PARAM:'
.
json_encode
(
$param
));
...
...
@@ -29,19 +39,16 @@ class CheckApiKey
if
(
strcmp
(
$url
,
$md_url
)){
if
(
$_SERVER
[
'REQUEST_SCHEME'
]
==
'http'
){
return
response
()
->
json
(
array
(
'code'
=>
10001
,
'msg'
=>
'验证url失败'
)
);
return
$this
->
errorWithInfo
(
'验证url失败'
,
401
);
}
}
$api_key
=
$request
->
api_key
;
$user_sn
=
$request
->
user_sn
;
$user
=
Users
::
where
(
'user_sn'
,
$param
[
'user_sn'
])
->
first
();
$user
=
DB
::
table
(
'users'
)
->
where
(
'user_sn'
,
$param
[
'user_sn'
])
->
first
();
if
(
empty
(
$user
->
parent_sn
)){
$the_expired
=
$user
->
expired
;
}
else
{
$puser
=
Users
::
where
(
'user_name'
,
$user
->
parent_sn
)
->
select
(
'expired'
)
->
first
();
$puser
=
DB
::
table
(
'users'
)
->
where
(
'user_name'
,
$user
->
parent_sn
)
->
select
(
'expired'
)
->
first
();
$the_expired
=
$puser
->
expired
;
}
...
...
@@ -49,13 +56,13 @@ class CheckApiKey
$expiredDate
=
strtotime
(
$the_expired
.
' 00:00:00'
);
if
(
empty
(
$the_expired
)
||
$expiredDate
-
$todayDate
<=
0
){
return
response
()
->
json
(
array
(
'code'
=>
20008
,
'msg'
=>
'您的账号已过期,请联系管理员处理'
)
);
return
$this
->
errorWithInfo
(
'您的账号已过期,请联系管理员处理'
,
401
);
}
$request
->
attributes
->
add
([
'user'
=>
$user
]);
//添加参数
}
catch
(
\Exception
$e
){
Log
::
info
(
$e
->
getFile
()
.
'-'
.
$e
->
getLine
()
.
'-'
.
$e
->
getMessage
());
return
response
()
->
json
(
array
(
'code'
=>
500
,
'msg'
=>
$e
->
getMessage
()
.
'-'
.
$e
->
getLine
())
);
Log
::
channel
(
'api'
)
->
error
(
$e
->
getFile
()
.
'-'
.
$e
->
getLine
()
.
'-'
.
$e
->
getMessage
());
return
$this
->
errorWithInfo
(
'验证异常'
,
401
);
}
return
$next
(
$request
);
}
...
...
database/seeds/DatabaseSeeder.php
View file @
6eed3133
...
...
@@ -63,7 +63,7 @@ class DatabaseSeeder extends Seeder
});
}
$tableName
=
'
task_data
'
;
//任务数据(任务已建未建)
$tableName
=
'
strategy_task
'
;
//任务数据(任务已建未建)
if
(
!
Schema
::
hasTable
(
$tableName
)){
//创建表语句
Schema
::
create
(
$tableName
,
function
(
Blueprint
$table
){
...
...
routes/api.php
View file @
6eed3133
...
...
@@ -18,11 +18,10 @@ Route::middleware('auth:api')->get('/user', function (Request $request) {
});
//接口路由
Route
::
match
([
'get'
,
'post'
],
'login'
,
'LoginApiController@index'
);
Route
::
match
([
'get'
,
'post'
],
'loginc'
,
'LoginCheckController@index'
);
Route
::
post
(
'login'
,
'LoginApiController@index'
);
Route
::
group
([
'middleware'
=>
'check.apikey'
,
'
prefix'
=>
'api
'
],
function
()
{
Route
::
group
([
'middleware'
=>
'check.apikey'
,
'
namespace'
=>
'strategy
'
],
function
()
{
Route
::
match
([
'get'
,
'post'
],
'strategyLists'
,
'InfoController@strategyLists'
);
//初始化
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment