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.
38 lines
1.1 KiB
38 lines
1.1 KiB
<?php
|
|
declare (strict_types = 1);
|
|
|
|
namespace app\middleware;
|
|
|
|
use think\Exception;
|
|
use think\facade\Cache;
|
|
use think\facade\Request;
|
|
use think\facade\Session;
|
|
|
|
class CheckAgent
|
|
{
|
|
/**
|
|
* 处理请求
|
|
* @param $request
|
|
* @param \Closure $next
|
|
* @return mixed|\think\response\Json
|
|
*/
|
|
public function handle($request, \Closure $next)
|
|
{
|
|
try {
|
|
$token = Request::header()['token']??false;
|
|
if(!$token)
|
|
throw new Exception('当前登录已失效,请重新登录',403);
|
|
$userinfo = checkToken($token);
|
|
if($userinfo['code'] != 200)
|
|
throw new Exception('当前登录已失效,请重新登录',403);
|
|
$request->userInfo = $userinfo['data'];
|
|
if (!Session::get('login_agent_user_data')) {
|
|
throw new Exception('代理未登陆,请先登陆后操作',201);
|
|
}
|
|
}
|
|
catch (\Exception $err){
|
|
return json(['code'=>$err->getCode(),'msg'=>$err->getMessage()]);
|
|
}
|
|
return $next($request);
|
|
}
|
|
}
|
|
|