| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- <?php
- namespace app\api\controller;
- use app\common\controller\Api;
- use think\exception\HttpResponseException;
- use think\Request;
- use think\Response;
- class MassagerBaseApi extends Api
- {
- protected $noNeedLogin = ["*"];
- protected $cNoNeedLogin = [];
- protected $massager = null;
- 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");
- $response = new HttpResponseException(Response::create([
- 'code' => 401,
- 'msg' => "请先登录",
- 'time' => Request::instance()->server('REQUEST_TIME'),
- 'data' => null,
- ], 'json')->header([]));
- if (is_null($session_token))
- throw $response;
- $m = \app\api\model\massager\Massager::where([
- "session_token" => $session_token,
- ])->where("status", "in", [\E_MASSAGER_STATUS::Normal, \E_MASSAGER_STATUS::Hidden])->find();
- if (!$m)
- throw $response;
- $this->massager = $m;
- }
- }
|