Base.php 881 B

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