MassagerBaseApi.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\exception\HttpResponseException;
  5. use think\Request;
  6. use think\Response;
  7. class MassagerBaseApi extends Api
  8. {
  9. protected $noNeedLogin = ["*"];
  10. protected $cNoNeedLogin = [];
  11. protected $massager = null;
  12. public function __construct(Request $request = null)
  13. {
  14. parent::__construct($request);
  15. $urls = explode("/", $request->path());
  16. $method = $urls[count($urls) - 1];
  17. if (in_array($method, $this->cNoNeedLogin))
  18. return;
  19. $session_token = $request->header("session_token");
  20. $response = new HttpResponseException(Response::create([
  21. 'code' => 401,
  22. 'msg' => "请先登录",
  23. 'time' => Request::instance()->server('REQUEST_TIME'),
  24. 'data' => null,
  25. ], 'json')->header([]));
  26. if (is_null($session_token))
  27. throw $response;
  28. $m = \app\api\model\massager\Massager::where([
  29. "session_token" => $session_token,
  30. ])->where("status", "in", [\E_MASSAGER_STATUS::Normal, \E_MASSAGER_STATUS::Hidden])->find();
  31. if (!$m)
  32. throw $response;
  33. $this->massager = $m;
  34. }
  35. }