| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- <?php
- namespace app\api\controller;
- use app\admin\model\Admin;
- use app\common\controller\Api;
- use think\exception\HttpResponseException;
- use think\Request;
- use think\Response;
- class AgencyBaseApi extends Api
- {
- protected $noNeedLogin = ["*"];
- protected $cNoNeedLogin = [];
- protected $admin = null;
- /**
- * AgencyBaseApi constructor.
- * @param Request|null $request
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function __construct(Request $request = null)
- {
- parent::__construct($request);
- $urls = explode("/", $request->path());
- $method = $urls[count($urls) - 1];
- if (in_array($method, $this->cNoNeedLogin))
- return;
- $session_token = $request->header("session_token");
- $responseException = new HttpResponseException(Response::create([
- 'code' => 401,
- 'msg' => "请先登录",
- 'time' => Request::instance()->server('REQUEST_TIME'),
- 'data' => null,
- ], 'json')->header([]));
- if (is_null($session_token))
- throw $responseException;
- $admin = Admin::where([
- "session_token" => $session_token,
- "status" => \E_MASSAGER_STATUS::Normal
- ])->find();
- if (!$admin)
- throw $responseException;
- $this->admin = $admin;
- }
- }
|