User.php 1001 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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['user_id'] ?: 0;
  15. }
  16. public static function getUserName() {
  17. $userName = self::$userInfo['nick_name'] ?: self::$userInfo['user_name'];
  18. return $userName;
  19. }
  20. public static function getInfo() {
  21. if (self::$userInfo) {
  22. return self::$userInfo;
  23. }
  24. $userId = $_REQUEST['user_id'] ?: $_COOKIE['user_id'];
  25. $accessToken = $_REQUEST['access_token'] ?: $_COOKIE['access_token'];
  26. $info = ThirdApi::getMeeUserInfo($userId, $accessToken);
  27. if ($info) {
  28. self::$userInfo = $info;
  29. return self::$userInfo;
  30. } else {
  31. return [];
  32. }
  33. }
  34. }