<?php


namespace app\admin\controller;


use app\BaseController;
use Firebase\JWT\JWT;
use think\App;
use think\facade\Request;

class Base extends BaseController
{

    protected $uid; //后台管理员管理员id

    public function __construct(App $app)
    {
        parent::__construct($app);
        if(Request::header('token')) {
            $token =  Request::header('token');
            //判断是否在redis中
            if($token) {
                $decodeData = JWT::decode($token,config('app.jwt_key'),array("HS256"));
                $decodeData = json_decode($decodeData,true);
                if($decodeData) {
                    if($decodeData['expire_time'] < time()) {
                        echo json_encode(['code'=>400,'msg'=>'token已过期!']);exit;
                    }
                    $this->admin_id = $decodeData['admin_id'];
                } else{
                    echo json_encode(['code'=>400,'msg'=>'非法的token!']);exit;
                }
            } else{
                echo json_encode(['code'=>400,'msg'=>'token不存在']);exit;
            }
        } else {
            echo json_encode(['code'=>400,'msg'=>'token不存在']);exit;
        }

    }



}