package com.game.common.utils.app;


import com.game.common.constant.ConstantsList;
import com.game.common.core.redis.RedisCache;
import com.game.common.utils.spring.SpringUtils;
import org.redisson.api.RedissonClient;

public class AppUserCache {

    static String getUserToken(long uid) {
        RedissonClient redissonClient = SpringUtils.getBean(RedissonClient.class);
        Object objToken = redissonClient.getBucket("U:Token:" + uid).get();
        if (objToken == null) {
            return "";
        } else {
            String token = (String) objToken;
            if (token.length() < 5) {
                return "";
            }
            return token;
        }
    }

    public static boolean checkHaveToken(long uid, String token) {
        if (token == null || token.length() < 5) {
            return false;
        }

        // 游客用户
        if (uid == ConstantsList.visitorUserId) {
            if (token.equals("3c71f46eeaba42c8b16b1ea0837137f3")) {
                return true;
            } else {
                return false;
            }
        }

        String cacheToken = getUserToken(uid);
        if (cacheToken.equals(token)) {
            return true;
        } else {
            return false;
        }

    }

}
