Base.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. namespace app\inter\controller;
  3. use app\admin\library\Auth;
  4. use app\admin\model\Admin;
  5. use think\Controller;
  6. use think\Db;
  7. use think\Session;
  8. use think\Config;
  9. use think\Cookie;
  10. use think\Cache;
  11. use think\Log;
  12. use think\Request;
  13. class Base extends Controller
  14. {
  15. protected $logined = false; //登录状态
  16. /**
  17. * 无需登录的方法,同时也就不需要鉴权了
  18. * @var array
  19. */
  20. protected $noNeedLogin = [];
  21. public $sessionid;
  22. /**
  23. * 初始化操作
  24. */
  25. public function _initialize()
  26. {
  27. $sessionid = Request::instance()->param('sessionid');
  28. log::record($sessionid);
  29. log::record('-----------base 页面cache-------------');
  30. log::record($sessionid);
  31. log::record('------------------------');
  32. $admin = Cache::get($sessionid);
  33. if (!$admin) {
  34. die(json_encode(['status'=>'fail','code'=>'1010','msg'=>'对不起,您还未进行登录,请先登录']));
  35. // $this->error('对不起,您还未进行登录,请先登录','inter/index');
  36. }
  37. }
  38. function getRandomString($len, $chars=null)
  39. {
  40. if (is_null($chars)){
  41. $chars = "abcdefghijklmnopqrstuvwxyz0123456789";
  42. }
  43. mt_srand(10000000*(double)microtime());
  44. for ($i = 0, $str = '', $lc = strlen($chars)-1; $i < $len; $i++){
  45. $str .= $chars[mt_rand(0, $lc)];
  46. }
  47. return $str;
  48. }
  49. public function _construct()
  50. {
  51. $request = Request::instance();
  52. if($request->method() == 'OPTIONS'){
  53. return;
  54. }
  55. }
  56. }