...
|
...
|
@@ -11,12 +11,17 @@ import org.springframework.stereotype.Service; |
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import java.beans.IntrospectionException;
|
|
|
import java.beans.PropertyDescriptor;
|
|
|
import java.io.IOException;
|
|
|
import java.io.UnsupportedEncodingException;
|
|
|
import java.lang.reflect.InvocationTargetException;
|
|
|
import java.lang.reflect.Method;
|
|
|
import java.net.URLDecoder;
|
|
|
import java.net.URLEncoder;
|
|
|
|
|
|
@Service
|
|
|
public class RedirectServiceImpl implements IRedirectService{
|
|
|
public class RedirectServiceImpl implements IRedirectService {
|
|
|
|
|
|
Logger logger = LoggerFactory.getLogger(RedirectServiceImpl.class);
|
|
|
|
...
|
...
|
@@ -37,18 +42,18 @@ public class RedirectServiceImpl implements IRedirectService{ |
|
|
return;
|
|
|
}
|
|
|
String channelId = uionReqVO.getChannel_id();
|
|
|
if(StringUtils.isEmpty(uionReqVO.getChannel_id())){
|
|
|
if (StringUtils.isEmpty(uionReqVO.getChannel_id())) {
|
|
|
logger.warn("jump: channelId is null, requst param is {}", uionReqVO);
|
|
|
return;
|
|
|
}
|
|
|
if(StringUtils.isEmpty(uionReqVO.getTracking_code())){
|
|
|
if (StringUtils.isEmpty(uionReqVO.getTracking_code())) {
|
|
|
logger.warn("jump: trackCode is null, requst param is {}", uionReqVO);
|
|
|
return;
|
|
|
}
|
|
|
String redirectUrl = "";
|
|
|
if(channelId.equals(SourceEnum.PANSHI.getValue())){
|
|
|
if (channelId.equals(SourceEnum.PANSHI.getValue())) {
|
|
|
redirectUrl = this.builderUrlForPanshi(uionReqVO);
|
|
|
}else if(channelId.equals(SourceEnum.FANLI_WAP.getValue()) || channelId.equals(SourceEnum.FANLI_WEB.getValue())){
|
|
|
} else if ("51fanli".equals(channelId)) {
|
|
|
redirectUrl = this.builderUrlForFanli(uionReqVO);
|
|
|
}
|
|
|
response.setStatus(301);
|
...
|
...
|
@@ -58,13 +63,13 @@ public class RedirectServiceImpl implements IRedirectService{ |
|
|
}
|
|
|
}
|
|
|
|
|
|
private String builderUrlForPanshi(UnionReqVO uionReqVO){
|
|
|
private String builderUrlForPanshi(UnionReqVO uionReqVO) {
|
|
|
String param = this.generateReqParam(uionReqVO);
|
|
|
StringBuffer targetUrl = new StringBuffer(uionReqVO.getTarget_url());
|
|
|
targetUrl = StringUtils.isEmpty(targetUrl) ? new StringBuffer(WAP_URL) : targetUrl;
|
|
|
if(targetUrl.toString().contains("?")){
|
|
|
if (targetUrl.toString().contains("?")) {
|
|
|
targetUrl.append("&utm_source=").append(uionReqVO.getUtm_source()).append("&utm_medium=").append(uionReqVO.getUtm_medium()).append("&utm_campaign=").append(uionReqVO.getUtm_campaign());
|
|
|
}else{
|
|
|
} else {
|
|
|
targetUrl.append("?utm_source=").append(uionReqVO.getUtm_source()).append("&utm_medium=").append(uionReqVO.getUtm_medium()).append("&utm_campaign=").append(uionReqVO.getUtm_campaign());
|
|
|
}
|
|
|
|
...
|
...
|
@@ -81,39 +86,72 @@ public class RedirectServiceImpl implements IRedirectService{ |
|
|
return urlBuilder.toString();
|
|
|
}
|
|
|
|
|
|
private String builderUrlForFanli(UnionReqVO uionReqVO){
|
|
|
private String builderUrlForFanli(UnionReqVO uionReqVO) {
|
|
|
//解析targetUrl
|
|
|
praseTargetUrl(uionReqVO);
|
|
|
String redirectUrl = "";
|
|
|
String param = this.generateReqParam(uionReqVO);
|
|
|
String targetUrl = uionReqVO.getTarget_url();
|
|
|
if(SourceEnum.FANLI_WEB.getValue().equals(uionReqVO.getChannel_id())){
|
|
|
StringBuilder targetUrl = new StringBuilder();
|
|
|
if (SourceEnum.FANLI_WEB.getValue().equals(uionReqVO.getUnion_type())) {
|
|
|
redirectUrl = WEB_REDIRECT_URL;
|
|
|
targetUrl = StringUtils.isEmpty(targetUrl) ? WEB_URL : targetUrl;
|
|
|
targetUrl.append(StringUtils.isEmpty(uionReqVO.getTarget_url()) ? WEB_URL : uionReqVO.getTarget_url());
|
|
|
}
|
|
|
if(SourceEnum.FANLI_WAP.getValue().equals(uionReqVO.getChannel_id())){
|
|
|
if (SourceEnum.FANLI_WAP.getValue().equals(uionReqVO.getUnion_type())) {
|
|
|
redirectUrl = WAP_REDIRECT_URL;
|
|
|
targetUrl = StringUtils.isEmpty(targetUrl) ? WAP_URL : targetUrl;
|
|
|
targetUrl.append(StringUtils.isEmpty(targetUrl) ? WAP_URL : uionReqVO.getTarget_url());
|
|
|
}
|
|
|
targetUrl.append("?union_type=").append(uionReqVO.getUnion_type()).append("&utm_source=").append(uionReqVO.getUtm_source())
|
|
|
.append("&utm_medium=").append(uionReqVO.getUtm_medium()).append("&utm_campaign=").append(uionReqVO.getUtm_campaign());
|
|
|
String newTargetUrl = targetUrl.toString();
|
|
|
try {
|
|
|
param = URLEncoder.encode(param, "UTF-8");
|
|
|
targetUrl = URLEncoder.encode(targetUrl, "UTF-8");
|
|
|
newTargetUrl = URLEncoder.encode(newTargetUrl, "UTF-8");
|
|
|
} catch (UnsupportedEncodingException e) {
|
|
|
logger.warn("builderUrlForFanli: urlEncode failed: request param is {}", uionReqVO);
|
|
|
}
|
|
|
StringBuilder urlBuilder = new StringBuilder();
|
|
|
urlBuilder.append(redirectUrl).append("?_QYH_UNION=");
|
|
|
urlBuilder.append(param).append("&target=");
|
|
|
urlBuilder.append(targetUrl);
|
|
|
urlBuilder.append(newTargetUrl);
|
|
|
return urlBuilder.toString();
|
|
|
}
|
|
|
|
|
|
private String generateReqParam(UnionReqVO uionReqVO){
|
|
|
/**
|
|
|
* 解析url
|
|
|
*
|
|
|
* @param uionReqVO
|
|
|
*/
|
|
|
private void praseTargetUrl(UnionReqVO uionReqVO) {
|
|
|
String url = "";
|
|
|
try {
|
|
|
url = URLDecoder.decode(uionReqVO.getTarget_url(), "UTF-8");
|
|
|
} catch (UnsupportedEncodingException e) {
|
|
|
logger.warn("decode target url fail! target_url {} e {}", uionReqVO.getTarget_url(), e);
|
|
|
}
|
|
|
String[] arr = url.split("\\?");
|
|
|
uionReqVO.setTarget_url(arr[0]);
|
|
|
PropertyDescriptor property = null;
|
|
|
for (String params : arr[1].split("&")) {
|
|
|
String[] param = params.split("=");
|
|
|
try {
|
|
|
property = new PropertyDescriptor(param[0], UnionReqVO.class);
|
|
|
//获取set方法
|
|
|
Method method = property.getWriteMethod();
|
|
|
//调用set方法
|
|
|
method.invoke(uionReqVO, param[1]);
|
|
|
} catch (Exception e) {
|
|
|
logger.warn("prase target url fail! target_url {} e {}", url, e);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private String generateReqParam(UnionReqVO uionReqVO) {
|
|
|
JSONObject param = new JSONObject();
|
|
|
param.put("client_id",uionReqVO.getChannel_id());
|
|
|
param.put("channel_code",uionReqVO.getTracking_code());
|
|
|
param.put("channel",uionReqVO.getChannel_id());
|
|
|
param.put("fl_uid",uionReqVO.getU_id());
|
|
|
param.put("go_url",uionReqVO.getTarget_url());
|
|
|
param.put("client_id", uionReqVO.getUnion_type());
|
|
|
param.put("channel_code", uionReqVO.getTracking_code());
|
|
|
param.put("channel", uionReqVO.getUnion_type());
|
|
|
param.put("fl_uid", uionReqVO.getU_id());
|
|
|
param.put("go_url", uionReqVO.getTarget_url());
|
|
|
return param.toString();
|
|
|
|
|
|
}
|
|
|
} |
...
|
...
|
|