Base.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. namespace app\youzan\controller;
  3. use app\BaseController;
  4. use think\App;
  5. class Base extends BaseController{
  6. protected $noLogin=["*"];
  7. protected $uid=0;
  8. protected $uname='system';
  9. protected $roleid=0;
  10. protected $level=0;
  11. protected $token='';
  12. protected $model=null;
  13. public function __construct(App $app) {
  14. parent::__construct($app);
  15. $this->token = $this->request->param('token','','trim');
  16. if (!action_in_arr($this->noLogin)){
  17. if($this->token=='')throw new \Exception('token不能为空',101);
  18. $this->Auth();
  19. }
  20. }
  21. /**授权token鉴定
  22. * @return \think\response\Json|void
  23. */
  24. public function Auth(){
  25. $User = \app\common\User::instance();
  26. $User->init($this->token);
  27. if (!$User->isLogin()) throw new \Exception($User->getError(),$User->getErroCode());
  28. $this->uid = $User->id;
  29. $this->uname = $User->nickname;
  30. $this->level = $User->level;
  31. }
  32. }