<?php
/**
 *
 *User:Administrator
 *Date:2021/10/1
 */

namespace app\common\middleware;

//调用自定义的异常处理类
use app\api\exception\ApiException;

class JwtAuth
{
    public function handle($request,\Closure $next)
    {
        $token = request()->header('Authorization');//access-token
        //$token = request()->param('token');

        if ($token) {
            $jwtAuth = \app\common\lib\auth\JwtAuth::getInstance();
            $jwtAuth->setToken($token);

            if ($jwtAuth->validate() && $jwtAuth->verify()) {
                return $next($request);
            } else {
                throw new ApiException(config('status.err_unKnow'));
            }
        } else {
            throw new ApiException(config('status.err_params'));
            //return show(config('status.err_params')[0],config('status.err_params')[1]);
        }
    }
}