zhaojs
2023-07-31 8dcfae4fff98fbbb19ff46bd9750f25bc56801a9
application/common/controller/Api.php
@@ -110,12 +110,26 @@
        $token = $this->request->server('HTTP_TOKEN', $this->request->request('token', \think\Cookie::get('token')));
        $path = str_replace('.', '/', $controllername) . '/' . $actionname;
        $hasInit=false;
        // 设置当前请求的URI
        $this->auth->setRequestUri($path);
        // 检测是否需要验证登录
        if (!$this->auth->match($this->noNeedLogin)) {
            //初始化
            $this->auth->init($token);
            if(empty($token))
            {//token为空,判断sessionkey
                $sessionkey= $this->request->server('HTTP_DFGSESSIONKEY', $this->request->request('dfgsessionkey', \think\Cookie::get('dfgsessionkey')));
                if(!empty($sessionkey))
                {//校验sessionkey
                    $paramsArr=$this->request->post(false);
                    $this->auth->initSession($sessionkey,$paramsArr);
                    $hasInit=true;
                }
            }
            if(!$hasInit)
            {
                $this->auth->init($token);
            }
            //检测是否登录
            if (!$this->auth->isLogin()) {
                $this->error(__('Please login first'), [], 401);