完善项目
This commit is contained in:
36
src/main/java/com/ping/study/service/tx/QQCookieService.java
Normal file
36
src/main/java/com/ping/study/service/tx/QQCookieService.java
Normal file
@@ -0,0 +1,36 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user