yumeng пре 3 дана
родитељ
комит
816cd35058

+ 42 - 0
module-common/src/main/java/cn/com/ctop/common/module/config/AdqRedisConfig.java

@@ -0,0 +1,42 @@
+package cn.com.ctop.common.module.config;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.data.redis.connection.RedisPassword;
+import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
+import org.springframework.data.redis.connection.lettuce.LettuceClientConfiguration;
+import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
+import org.springframework.data.redis.core.StringRedisTemplate;
+
+/**
+ * ADQ 独立 Redis 配置
+ * 用于将 ADQ access_token 同步到另一个 Redis 实例
+ */
+@Configuration
+public class AdqRedisConfig {
+
+    /**
+     * ADQ 专用 RedisTemplate
+     * host:172.30.0.25
+     * port:6379
+     * password:hcst@2026qwe..
+     * db:5
+     */
+    @Bean(name = "adqRedisTemplate")
+    public StringRedisTemplate adqRedisTemplate() {
+        RedisStandaloneConfiguration standaloneConfig = new RedisStandaloneConfiguration();
+        standaloneConfig.setHostName("172.30.0.25");
+        standaloneConfig.setPort(6379);
+        standaloneConfig.setDatabase(5);
+        standaloneConfig.setPassword(RedisPassword.of("hcst@2026qwe.."));
+
+        LettuceClientConfiguration clientConfig = LettuceClientConfiguration.builder().build();
+
+        LettuceConnectionFactory connectionFactory = new LettuceConnectionFactory(standaloneConfig, clientConfig);
+        connectionFactory.afterPropertiesSet();
+
+        StringRedisTemplate template = new StringRedisTemplate(connectionFactory);
+        template.afterPropertiesSet();
+        return template;
+    }
+}

+ 18 - 0
module-common/src/main/java/cn/com/ctop/common/module/service/impl/RefreshTokenServiceImpl.java

@@ -15,13 +15,16 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.xxl.job.core.context.XxlJobHelper;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.redis.core.StringRedisTemplate;
 import org.springframework.stereotype.Service;
 
+import javax.annotation.Resource;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
 
 @Slf4j
 @Service
@@ -34,6 +37,8 @@ public class RefreshTokenServiceImpl implements IRefreshTokenService {
     private IOauthAgentTokenService agentTokenService;
     @Autowired
     private IOauthConfigService configService;
+    @Resource(name = "adqRedisTemplate")
+    private StringRedisTemplate adqRedisTemplate;
     private static ExecutorService kuaishouTokenExecutorService = Executors.newFixedThreadPool(4);
 
     /**
@@ -137,6 +142,19 @@ public class RefreshTokenServiceImpl implements IRefreshTokenService {
             String updateAccessToken = data.getString("access_token");
             String updateRefreshToken = data.getString("refresh_token");
             oauthTokenService.updateAdqToken(adminAdvertiserId, updateAccessToken, updateRefreshToken);
+            // 同步到 ADQ 独立 Redis,key 规则:adq:access_token:{adminAdvertiserId}
+            try {
+                String redisKey = "adq:access_token:" + adminAdvertiserId;
+                Integer expiresIn = data.getInteger("expires_in");
+                if (expiresIn != null && expiresIn > 0) {
+                    adqRedisTemplate.opsForValue().set(redisKey, updateAccessToken, expiresIn, TimeUnit.SECONDS);
+                } else {
+                    adqRedisTemplate.opsForValue().set(redisKey, updateAccessToken);
+                }
+                XxlJobHelper.log("ADQ token 已同步到 Redis, account:{}, key:{}", adminAdvertiserId, redisKey);
+            } catch (Exception e) {
+                log.error("ADQ token 同步到 Redis 失败, account:{}", adminAdvertiserId, e);
+            }
         }
     }