替换域名链接为eparty链接
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
package com.accompany.common.constant;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author: chucheng
|
||||
* @Date: 2019/7/25 14:41
|
||||
@@ -61,4 +64,15 @@ public enum AppEnum {
|
||||
public String getH5RootDir() {
|
||||
return h5RootDir;
|
||||
}
|
||||
|
||||
public static List<AppEnum> getOtherTwoAppEnums(AppEnum currentApp) {
|
||||
List<AppEnum> otherApps = new ArrayList<>();
|
||||
// 遍历所有枚举,排除传入的 app 对应的枚举
|
||||
for (AppEnum app : AppEnum.values()) {
|
||||
if (!app.equals(currentApp)) {
|
||||
otherApps.add(app);
|
||||
}
|
||||
}
|
||||
return otherApps;
|
||||
}
|
||||
}
|
||||
|
@@ -23,7 +23,9 @@ public enum PublicHeaderParamEnum {
|
||||
ANDROID_ID("androidId"),
|
||||
IDFA("idfa"),
|
||||
OAID("oaid"),
|
||||
OAID_MD5("oaidMd5");
|
||||
OAID_MD5("oaidMd5"),
|
||||
HOST("host"),
|
||||
;
|
||||
|
||||
private final String value;
|
||||
|
||||
|
@@ -116,4 +116,8 @@ public class BaseRequestVO {
|
||||
public String getClient() {
|
||||
return httpServletRequest != null ? httpServletRequest.getHeader(PublicHeaderParamEnum.CLIENT.getValue()) : "";
|
||||
}
|
||||
@ApiModelProperty(value = "公共参数-域名", hidden = true)
|
||||
public String getHost() {
|
||||
return httpServletRequest != null ? httpServletRequest.getHeader(PublicHeaderParamEnum.HOST.getValue()) : "";
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,84 @@
|
||||
package com.accompany.business.interceptor;
|
||||
|
||||
import com.accompany.common.constant.AppEnum;
|
||||
import com.accompany.common.result.BusiResult;
|
||||
import com.accompany.common.utils.EnvComponent;
|
||||
import com.accompany.core.vo.BaseRequestVO;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.server.ServerHttpRequest;
|
||||
import org.springframework.http.server.ServerHttpResponse;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||
import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
@RestControllerAdvice
|
||||
@Slf4j
|
||||
public class ResponseDataHandler implements ResponseBodyAdvice {
|
||||
|
||||
@Autowired
|
||||
private EnvComponent envComponent;
|
||||
|
||||
@Override
|
||||
public boolean supports(MethodParameter methodParameter, Class aClass) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object beforeBodyWrite(Object body, MethodParameter methodParameter, MediaType mediaType, Class selectedConverterType,
|
||||
ServerHttpRequest serverHttpRequest, ServerHttpResponse serverHttpResponse) {
|
||||
if (envComponent.getDevOrNativeEnv()) {
|
||||
return body;
|
||||
}
|
||||
if (body == null) {
|
||||
return body;
|
||||
}
|
||||
if (!(body instanceof BusiResult)) {
|
||||
return body;
|
||||
}
|
||||
try {
|
||||
BusiResult result = (BusiResult) body;
|
||||
Object data = result.getData();
|
||||
String uri = serverHttpRequest.getURI().getPath();
|
||||
if (null != data) {
|
||||
String json = JSONObject.toJSONString(data);
|
||||
json = handlerDomain(json, uri);
|
||||
|
||||
log.info("app:{}, uri:{} ResponseDataHandler 实际返回内容:{}" , AppEnum.getCurApp().getValue(), uri, json);
|
||||
|
||||
result.setData(JSONObject.parseObject(json, Object.class));
|
||||
return result;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("ResponseDataHandler error, e:{}" , e.getMessage(), e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return body;
|
||||
}
|
||||
|
||||
private String handlerDomain(String json, String uri) {
|
||||
AppEnum curApp = AppEnum.getCurApp();
|
||||
String apiDomain = curApp.getApiDomain();
|
||||
String resourceDomain = curApp.getResourceDomain();
|
||||
|
||||
List<AppEnum> otherTwoAppEnums = AppEnum.getOtherTwoAppEnums(curApp);
|
||||
for (AppEnum otherApp : otherTwoAppEnums) {
|
||||
String diffResourceDomain = otherApp.getResourceDomain();
|
||||
String diffApiDomain = otherApp.getApiDomain();
|
||||
if (json.contains(diffResourceDomain)) {
|
||||
json = json.replaceAll(diffResourceDomain, resourceDomain);
|
||||
}
|
||||
if (json.contains(diffApiDomain)) {
|
||||
json = json.replaceAll(diffApiDomain, apiDomain);
|
||||
}
|
||||
}
|
||||
return json;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user