Files
NBA/src/main/java/com/ping/study/service/tx/QQCookieService.java
2025-04-21 11:17:19 +08:00

37 lines
1.1 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package com.ping.study.service.tx;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;
@Service
public class QQCookieService {
@Autowired
private StringRedisTemplate stringRedisTemplate;
private static final String REDIS_KEY = "user:nba"; // 固定 Key
// 存储 Cookie无需 uin 参数)
public void saveCookie(Map<String, String> cookies) {
stringRedisTemplate.opsForHash().putAll(REDIS_KEY, cookies);
stringRedisTemplate.expire(REDIS_KEY, 30, TimeUnit.DAYS);
}
// 获取 Cookie无需 uin 参数)
public Map<String, String> getCookie() {
Map<Object, Object> entries = stringRedisTemplate.opsForHash().entries(REDIS_KEY);
Map<String, String> result = new HashMap<>();
entries.forEach((key, value) ->
result.put(key.toString(), value.toString())
);
return result;
}
}