提交 a3cece0b authored 作者: 000516's avatar 000516 提交者: Coding

1、切换redis数据源;2、token解析改为link项目方式,通用token;2、修改Docker命令提示;修改application中的nacos配置为线下机房;添加qa配置

1、切换redis数据源;2、token解析改为link项目方式,通用token;2、修改Docker命令提示;修改application中的nacos配置为线下机房;添加qa配置
......@@ -4,9 +4,19 @@
docker build -t promotion-gateway:latest .
Live启动:
docker run -d -p 8010:8010 --name promotion-gateway \
-v /var/logs/promotion-gateway/:/var/logs/promotion-gateway/ \
--restart=always \
--network host \
promotion-gateway:latest
QA启动:
docker run -d -p 8010:8010 --name promotion-gateway \
-v /var/logs/promotion-gateway/:/var/logs/promotion-gateway/ \
--restart=always \
--network host \
--spring.profiles.active=qa \
promotion-gateway:latest
......@@ -5,7 +5,7 @@
<parent>
<groupId>com.wangxiaolu</groupId>
<artifactId>wangxiaolu-promotion-parent</artifactId>
<version>0.0.1</version>
<version>0.0.2</version>
</parent>
<groupId>com.wangxiaolu</groupId>
......
......@@ -9,4 +9,6 @@ import com.alibaba.fastjson.JSONObject;
*/
public interface UserDataService {
JSONObject getUserByToken(String token);
boolean hasKeyToken(String tokenKey);
}
......@@ -2,6 +2,7 @@ package com.promotion.gateway.data.impl;
import com.alibaba.fastjson.JSONObject;
import com.promotion.gateway.data.UserDataService;
import com.wangxiaolu.promotion.common.redis.RedisKeys;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
......@@ -26,4 +27,9 @@ public class UserDataServiceImpl implements UserDataService {
String val = vo.get(token);
return JSONObject.parseObject(val);
}
@Override
public boolean hasKeyToken(String tokenKey) {
return redisTemplate.hasKey(RedisKeys.UserKeys.WXL_LINK_TOKEN.getKey() + tokenKey);
}
}
package com.promotion.gateway.filter;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.google.gson.Gson;
import com.promotion.gateway.data.UserDataService;
import com.wangxiaolu.promotion.common.redis.RedisKeys;
import com.wangxiaolu.promotion.common.util.JwtTokenUtils;
import com.wangxiaolu.promotion.result.basedata.R;
import com.wangxiaolu.promotion.result.basedata.RCode;
import com.wangxiaolu.promotion.result.basedata.StatusCode;
import io.jsonwebtoken.Claims;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
......@@ -15,7 +15,6 @@ import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.Ordered;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.http.HttpStatus;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.http.server.reactive.ServerHttpResponse;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
......@@ -25,7 +24,6 @@ import reactor.core.publisher.Mono;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
/**
* @author : liqiulin
......@@ -43,7 +41,7 @@ public class AuthGlobalFilter implements GlobalFilter, Ordered {
private final List<String> whiteUrls = Arrays.asList("/login", "/enroll", "/sms/send/ver_code");
@Autowired
UserDataService userDataService;
private UserDataService userDataService;
@Override
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
......@@ -62,13 +60,25 @@ public class AuthGlobalFilter implements GlobalFilter, Ordered {
}
// 3、验证token
JSONObject userJson = userDataService.getUserByToken(RedisKeys.UserKeys.TEMPORARY_TOKEN.getKey() + token);
if (Objects.isNull(userJson)) {
log.info("访问URL:{},token登录错误:{}", url,token);
Claims claims = JwtTokenUtils.parseToken(token);
if (claims == null)
{
return loginError(exchange,RCode.NOT_LOGIN_TIMEOUT_ERROR);
}
ServerHttpRequest httpRequest = exchange.getRequest().mutate().header("loginId", userJson.getString("id")).header("loginQcId", userJson.getString("qcId")).build();
return chain.filter(exchange.mutate().request(httpRequest).build());
String userkey = JwtTokenUtils.getUserKey(claims);
boolean islogin = userDataService.hasKeyToken(userkey);
if (!islogin)
{
return loginError(exchange,RCode.NOT_LOGIN_TIMEOUT_ERROR);
}
String userid = JwtTokenUtils.getUserId(claims);
String username = JwtTokenUtils.getUserName(claims);
if (StringUtils.isBlank(userid) || StringUtils.isBlank(username))
{
return loginError(exchange,RCode.NOT_LOGIN_TIMEOUT_ERROR);
}
return chain.filter(exchange);
}
@Override
......
spring:
datasource:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://bj-cdb-j8ppdy86.sql.tencentcdb.com:63569/promotion_dev?autoReconnect=true
username: LnNDBM
password: fd0%bhD4@oO(%
url: jdbc:mysql://192.168.0.18:3306/promotion?autoReconnect=true
username: NvqGbJXH
password: D9Y@FR,84B*$MD^A36&m
redis:
port: 21101
host: bj-crs-oyzhz3c6.sql.tencentcdb.com
port: 6379
host: 192.168.100.40
database: 0
password: u)R3jrHk(qwt~mv$Tg=U
password: QjL6H5nH
main:
web-application-type: reactive
......@@ -16,8 +16,8 @@ spring:
cloud:
nacos:
discovery:
server-addr: 42.193.103.153:8848
namespace: dd681f3c-0d21-42e5-a96e-14863a7cdcdb
server-addr: 192.168.100.38:8848
namespace: 68c8d97c-715a-4983-99b7-9df9b99f89e7
group: promotion
gateway:
......
spring:
datasource:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://192.168.0.18:3306/promotion?autoReconnect=true
username: NvqGbJXH
password: D9Y@FR,84B*$MD^A36&m
redis:
port: 6379
host: 192.168.100.40
database: 0
password: QjL6H5nH
main:
web-application-type: reactive
cloud:
nacos:
discovery:
server-addr: 192.168.100.38:8848
namespace: 3b774c2d-b03b-4816-8fe8-a41f458ebbcc
group: promotion
gateway:
discovery:
locator:
enabled: true
routes:
- id: wangxiaolu-promotion-service
uri: lb://wangxiaolu-promotion-service
# uri: http://127.0.0.1:8011
predicates:
- Path=/**
logging:
config: classpath:logback-spring.xml
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论