智慧教务系统
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.
 
 
 
 
 
 

58 lines
1.9 KiB

<?php
// +----------------------------------------------------------------------
// | Niucloud-admin 企业快速开发的多应用管理平台
// +----------------------------------------------------------------------
// | 官方网址:https://www.niucloud.com
// +----------------------------------------------------------------------
// | niucloud团队 版权所有 开源版本可自由商用
// +----------------------------------------------------------------------
// | Author: Niucloud Team
// +----------------------------------------------------------------------
namespace app\api\middleware;
use app\dict\sys\AppTypeDict;
use app\Request;
use app\service\api\login\AuthService;
use app\service\api\login\LoginService;
use Closure;
use Exception;
use core\exception\AuthException;
/**
* 员工端登录token验证
* Class ApiCheckToken
* @package app\api\middleware
*/
class ApiPersonnelCheckToken
{
/**
* @param Request $request
* @param Closure $next
* @param bool $is_throw_exception 是否把错误抛出
* @return mixed
* @throws Exception
*/
public function handle(Request $request, Closure $next, bool $is_throw_exception = false)
{
$request->appType(AppTypeDict::PERSONNEL);
// 校验渠道
( new AuthService() )->checkChannel($request);
//通过配置来设置系统header参数
try {
$token = $request->apiToken();
$token_info = ( new LoginService() )->parsePersonnelToken($token);
if (!empty($token_info)) {
$request->memberId($token_info[ 'user_id' ]);
}
//校验会员和站点
$a= ( new AuthService() )->checkPersonnelMember($request);
} catch (AuthException $e) {
//是否将登录错误抛出
if ($is_throw_exception)
return fail($e->getMessage(), [], $e->getCode());
}
return $next($request);
}
}