CacheService.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User : zgcLives
  5. * CreateTime : 2022/10/20 11:57
  6. */
  7. namespace addons\exam\library;
  8. /**
  9. * 缓存服务
  10. */
  11. class CacheService
  12. {
  13. /**
  14. * 缓存Key:微信用户sessionKey
  15. * @param $user_id
  16. * @return string
  17. */
  18. public static function cacheKeyWechatUserSessionKey($user_id)
  19. {
  20. return "exam:wechat_user:session_key-{$user_id}";
  21. }
  22. /**
  23. * 设置微信用户sessionKey缓存
  24. * @param $user_id
  25. * @param $session_key
  26. * @return void
  27. */
  28. public static function setWechatUserSessionKey($user_id, $session_key)
  29. {
  30. $cache_key = self::cacheKeyWechatUserSessionKey($user_id);
  31. cache($cache_key, $session_key);
  32. }
  33. /**
  34. * 获取微信用户sessionKey缓存
  35. * @param $user_id
  36. * @return string
  37. */
  38. public static function getWechatUserSessionKey($user_id)
  39. {
  40. $cache_key = self::cacheKeyWechatUserSessionKey($user_id);
  41. return cache($cache_key);
  42. }
  43. }