37 lines
1.1 KiB
Java
37 lines
1.1 KiB
Java
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;
|
||
}
|
||
}
|