Переглянути джерело

河湖长域名调用

pull/44/head
chenjiandong 1 рік тому
джерело
коміт
b3916af2a6
2 змінених файлів з 19 додано та 2 видалено
  1. +1
    -1
      src/main/java/com/tuoheng/gateway/config/GatewayFilterConfig.java
  2. +18
    -1
      src/main/java/com/tuoheng/gateway/utils/GatewayUrlPathUtil.java

+ 1
- 1
src/main/java/com/tuoheng/gateway/config/GatewayFilterConfig.java Переглянути файл

@@ -62,7 +62,7 @@ public class GatewayFilterConfig implements GlobalFilter, Ordered {
if(!StringUtils.isEmpty(clientId)){
log.info("clientId is :{}", clientId);
String requestUrl = exchange.getRequest().getPath().value();
log.info("requestUrl is :{}", clientId);
log.info("requestUrl is :{}", requestUrl);
//去除gateway path 前缀
String apiUrl = requestUrl.replace(GatewayUrlPathUtil.getPathByClientId(clientId),"");
log.info("apiUrl is :{}", apiUrl);

+ 18
- 1
src/main/java/com/tuoheng/gateway/utils/GatewayUrlPathUtil.java Переглянути файл

@@ -2,6 +2,7 @@ package com.tuoheng.gateway.utils;

import com.alibaba.fastjson.JSONObject;
import com.tuoheng.gateway.commons.CommonsConfig;
import io.micrometer.core.instrument.util.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.*;
@@ -25,6 +26,10 @@ public class GatewayUrlPathUtil {

private static final String HHZ_MP = "tuoheng-hhz-mp";

private static final String FREEWAY_ADMIN = "tuoheng-freeway-admin";

private static final String FREEWAY_MP = "tuoheng-freeway-miniprogram";

/**
* 获取 gateway 路由前缀,匹配url
* @param clientId
@@ -39,6 +44,12 @@ public class GatewayUrlPathUtil {
case HHZ_MP:
apiPath = "/hhz/api";
break;
case FREEWAY_ADMIN:
apiPath = "/freeway/admin";
break;
case FREEWAY_MP:
apiPath = "/freeway/miniprogram";
break;
}
return apiPath;
}
@@ -48,15 +59,21 @@ public class GatewayUrlPathUtil {
* @return
*/
public static List<Integer> getRoleIdByApiUrlPermission(String clientId, String apiUrl, String token){
log.info("getRoleIdByApiUrlPermission - start");
List<Integer> resList = new ArrayList<>();
String url = "";
if(clientId.equals(HHZ_ADMIN) || clientId.equals(HHZ_MP)){
String url = CommonsConfig.hhzPermissionUrl;
url = CommonsConfig.hhzPermissionUrl;
}
if(StringUtils.isNotBlank(url)){
log.info("getRoleIdByApiUrlPermission - url:{}", url);
HttpHeaders resultRequestHeader = new HttpHeaders();
resultRequestHeader.add("Authorization", "Bearer " + token);
JSONObject json = new JSONObject();
json.put("apiUrl", apiUrl);
HttpEntity<JSONObject> entity = new HttpEntity<>(json, resultRequestHeader);
String result = new RestTemplate().postForObject(url, entity, String.class);
log.info("getRoleIdByApiUrlPermission - result:{}", result);
JSONObject jsonObject = JSONObject.parseObject(result);
Object obj = jsonObject.get("data");
if(!Objects.isNull(obj)){

Завантаження…
Відмінити
Зберегти