You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1008 B
49 lines
1008 B
<?php
|
|
|
|
namespace App\Http\Middleware;
|
|
|
|
use Closure;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Cache;
|
|
|
|
class AuthApi
|
|
{
|
|
/**
|
|
* Handle an incoming request.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @param \Closure $next
|
|
* @return mixed
|
|
*/
|
|
public function handle(Request $request, Closure $next)
|
|
{
|
|
$auth = $request->header('Authentication');
|
|
$appid = $request->header('appid');
|
|
if (!$auth || !$appid) {
|
|
return response()->json([
|
|
'code' => -1,
|
|
'msg' => 'header参数缺失',
|
|
'data' => [],
|
|
'status' => '500',
|
|
]);
|
|
}
|
|
// TODO 登录部分待优化
|
|
if (!Cache::get($auth)) {
|
|
return response()->json([
|
|
'code' => -1,
|
|
'msg' => '请先登录',
|
|
'data' => [],
|
|
'status' => '500',
|
|
]);
|
|
}
|
|
if (!Cache::get($appid)) {
|
|
return response()->json([
|
|
'code' => -1,
|
|
'msg' => 'lose appid',
|
|
'data' => [],
|
|
'status' => '500',
|
|
]);
|
|
}
|
|
return $next($request);
|
|
}
|
|
}
|