| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- <?php
- /**
- * ----------------------------------------------------------------------------
- * 行到水穷处,坐看云起时
- * 开发软件,找贵阳云起信息科技,官网地址:https://www.56q7.com/
- * ----------------------------------------------------------------------------
- * Author: 老成
- * email:85556713@qq.com
- */
- declare(strict_types=1);
- namespace app\api\controller;
- use app\api\service\ApiAuthService;
- use app\common\controller\BaseController;
- use think\exception\HttpResponseException;
- use think\facade\Config;
- use think\facade\Cookie;
- use think\Response;
- class Api extends BaseController
- {
- /**
- * 当前登录用户
- * @var \app\api\service\ApiAuthService
- */
- protected $auth;
- /**
- * 无需登录的方法,同时也就不需要鉴权了
- * @var array
- */
- protected $noNeedLogin = [];
- protected function _initialize()
- {
- $token=request()->header('token');
- if(!$token){
- $token=Cookie::get('token');
- }
- if(!$token){
- $token=request()->get('token');
- }
- if(!$token){
- $token=request()->post('token');
- }
- //$this->auth=ApiAuthService::newInstance(['adapter'=>new $class($token)]);
-
- $actionname = $this->request->action();
- $noNeedLoginSet=is_string($this->noNeedLogin)?[$this->noNeedLogin]:$this->noNeedLogin;
- $noNeedLogin = in_array('*',$noNeedLoginSet) || in_array($actionname,$noNeedLoginSet);
- //需要登陆
- // if(!$noNeedLogin && !$this->auth->isLogin()){
- // $response = Response::create(__('请先登录!'), 'html', 401);
- // throw new HttpResponseException($response);
- // }
- }
- }
|