Auth.php 772 B

1234567891011121314151617181920212223242526272829
  1. <?php
  2. namespace app\controller;
  3. use app\exceptions\AuthException;
  4. use think\facade\Cache;
  5. use think\facade\Db;
  6. use think\facade\Log;
  7. class Auth
  8. {
  9. //检查token
  10. public static function checkToken($token,$param){
  11. try {
  12. //redis
  13. $uid = Cache::get($token);
  14. //如果redis不存在,则提示token不存在
  15. if(!$uid) return false;
  16. $userInfo = Db::query("select * from `rrx_user` where `uid`=? limit 1", [$uid]);
  17. if (!$userInfo) return ['code'=>101];
  18. return array('data'=>$param,'userInfo'=>$userInfo[0]);
  19. } catch (\Exception $exception) {
  20. Log::info('检查token出错'.parseException($exception));
  21. return array('code'=>500);
  22. }
  23. }
  24. }