User.php 975 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. /**
  3. * 用户基础信息
  4. * @author benzhan
  5. */
  6. class User extends Singleton {
  7. private static $userInfo = null;
  8. public static function checkLogin() {
  9. $userInfo = self::getInfo();
  10. return $userInfo;
  11. }
  12. public static function getUserId() {
  13. $userInfo = self::getInfo();
  14. return $userInfo['account'] ? : 0;
  15. }
  16. public static function getUserName() {
  17. $userInfo = self::getInfo();
  18. return $userInfo['account'] ? : $userInfo['account'];
  19. }
  20. public static function getInfo() {
  21. if (self::$userInfo) {
  22. return self::$userInfo;
  23. }
  24. $flag = Account::checkToken();
  25. if ($flag) {
  26. self::$userInfo = [
  27. 'account' => $_COOKIE['account'] ?: $_REQUEST['account'],
  28. 'token' => $_COOKIE['token'] ?: $_REQUEST['token'],
  29. ];
  30. return self::$userInfo;
  31. } else {
  32. return [];
  33. }
  34. }
  35. }