Base.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace app\master\controller;
  3. use app\core\exception\AppException;
  4. use app\core\model\Master;
  5. use think\Log;
  6. class Base
  7. {
  8. public $master;
  9. public $data = [];
  10. public $request;
  11. public $app;
  12. public function __construct()
  13. {
  14. header("Access-Control-Allow-Origin: *");
  15. $this->request = request();
  16. $this->data = $this->request->post();
  17. if(!isset($this->data['token'])) {
  18. throw new AppException(-1002, 'token是必传字段');
  19. }
  20. if($this->request->action() != strtolower('loginByPassword')) {
  21. $master = Master::get([
  22. 'token'=>$this->data['token']
  23. ]);
  24. if(!$master) {
  25. throw new AppException(-1001, '不存在token');
  26. }
  27. if($master['tokenOverTime'] < THINK_START_TIME) {
  28. throw new AppException(-1002, '登录超时,请重新登录');
  29. }
  30. $this->request->bind('master', $master);
  31. if(!\app\master\logic\Master::checkAuth($master, str_replace('master/', '', $this->request->path()))) {
  32. throw new AppException(-1003, '没有权限');
  33. }
  34. }
  35. $this->request->bind('app', isset($this->data['app']) ? $this->data['app'] : []);
  36. $this->__initialize();
  37. }
  38. public function __call($name, $arguments)
  39. {
  40. // TODO: Implement __call() method.
  41. }
  42. }