zhaojs
2023-09-21 3cbd9dc493e8663d9ec1a2816e664f7c9289b8a3
application/common/controller/Api.php
@@ -110,6 +110,7 @@
        $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);
        // 检测是否需要验证登录
@@ -117,13 +118,18 @@
            //初始化
            if(empty($token))
            {//token为空,判断sessionkey
                $sessionkey= $this->request->server('HTTP_TOKEN', $this->request->request('dfgsessionkey', \think\Cookie::get('dfgsessionkey')));
                $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;
                }
            }
            $this->auth->init($token);
            if(!$hasInit)
            {
                $this->auth->init($token);
            }
            //检测是否登录
            if (!$this->auth->isLogin()) {
                $this->error(__('Please login first'), [], 401);