Authored by zhengwen.ge

去掉多余代码

... ... @@ -129,7 +129,7 @@ public class ClickUnionRest {
*/
@RequestMapping("/addUnion4Special")
public void addUnion4Special(ClickUnionRequestBO bo, HttpServletRequest request, HttpServletResponse response) {
clickUnion.info("addUnion4Special with param is {}", bo);
log.info("addUnion4Special with param is {}", bo);
try {
String clientIp = null;
String IP = RemoteIPInterceptor.getRemoteIP();
... ... @@ -139,47 +139,28 @@ public class ClickUnionRest {
}
bo.setClientIp(clientIp);
String agent = request.getHeader("user-agent");
agent = agent.toLowerCase();
clickUnion.info("user-agent={}", agent);
String url = "https://itunes.apple.com/cn/app/yoho!-you-huo/id490655927?mt=8";
try{
if (!StringUtils.isEmpty(agent)) {
//对encode的进行处理
String agentEncode = URLDecoder.decode(agent, "UTF-8");
if (!agent.equals(agentEncode)) { //encode前后不相等,说明经过了encode处理,则需要decode
agent = agentEncode;
}
if (agent.indexOf("mac os x") >= 0 || agent.indexOf("iphone") >= 0 || agent.indexOf("ipad") > 0) {
setClickUnionRequestBO(agent, bo, url);
}
}
}catch (Exception e){
log.error("addUnion4Special error with request={}", bo, e);
log.info("user-agent={}", agent);
if (StringUtils.isEmpty(agent)) {
log.warn("addUnion4Special user-agent is empty with bo={}", bo);
return;
}
if (agent.toLowerCase().indexOf("mac os x") < 0 && agent.toLowerCase().indexOf("iphone") < 0) {
log.warn("addUnion4Special is not ios with user-agent={}, bo={}", agent, bo);
return;
}
// if (StringUtils.isEmpty(agent)) {
// log.warn("addUnion4Special user-agent is empty with bo={}", bo);
// return;
// }
// if (agent.toLowerCase().indexOf("mac os x") < 0 && agent.toLowerCase().indexOf("iphone") < 0) {
// log.warn("addUnion4Special is not ios with user-agent={}, bo={}", agent, bo);
// return;
// }
// if (agent.indexOf(" like") < agent.indexOf(" OS ") + 4) {
// log.warn("addUnion4Special agent is not correct with user-agent={}, bo={}", agent, bo);
// return;
// }
//
// String version = agent.substring(agent.indexOf(" OS ") + 4, agent.indexOf(" like"));
// clickUnion.info("addUnion4Special version={}", version);
// bo.setTd("ios_" + version.replaceAll("_", "."));
// bo.setClient_type("ios");
// bo.setAppid("490655927");
// log.info("addUnion4Special request={}", bo);
if (agent.indexOf(" like") < agent.indexOf(" OS ") + 4) {
log.warn("addUnion4Special agent is not correct with user-agent={}, bo={}", agent, bo);
return;
}
String version = agent.substring(agent.indexOf(" OS ") + 4, agent.indexOf(" like"));
log.info("addUnion4Special version={}", version);
bo.setTd("ios_" + version.replaceAll("_", "."));
bo.setClient_type("ios");
bo.setAppid("490655927");
log.info("addUnion4Special request={}", bo);
unionService.clickUnion(bo);
// log.info("addUnion4Special with result is {}, and request is {}", response, bo);
log.info("addUnion4Special with result is {}, and request is {}", response, bo);
clickUnion.info("addUnion4Special request is {}", bo);
response.setStatus(301);
response.sendRedirect("https://itunes.apple.com/cn/app/yoho!-you-huo/id490655927?mt=8");
... ... @@ -187,135 +168,7 @@ public class ClickUnionRest {
log.error("addUnion4Special error with request={}", bo, e);
}
}
private void setClickUnionRequestBO(String agent, ClickUnionRequestBO bo, String url) throws UnsupportedEncodingException {
if(agent.contains("os")&&agent.contains("like")){
String version = agent.substring(agent.indexOf(" os ") + 4, agent.indexOf(" like"));
bo.setTd("ios_" + version.replaceAll("_", "."));
bo.setClient_type("ios");
bo.setAppid("490655927");
url = "https://itunes.apple.com/cn/app/yoho!-you-huo/id490655927?mt=8";
}
//youku;5.4;ios;10.2;iphone6,1 ---这种情况比较多
else if(agent.contains("youku")){
String version = "";
if(agent.contains("ios")){
int first = agent.indexOf("ios;")+4;
String version1 = agent.substring(first);
version = version1.substring(version1.indexOf(" ")+1, version1.indexOf(";"));
bo.setTd("ios_" + version.replaceAll("_", "."));
bo.setClient_type("ios");
bo.setAppid("490655927");
url = "https://itunes.apple.com/cn/app/yoho!-you-huo/id490655927?mt=8";
} //youku;5.4.1;iphone os;8.4.1;iphone6,2
else if(agent.contains("os")){
int first = agent.indexOf("os;") + 3;
String version1 = agent.substring(first);
version = version1.substring(version1.indexOf(" ") + 1, version1.indexOf(";"));
bo.setTd("ios_" + version.replaceAll("_", "."));
bo.setClient_type("ios");
bo.setAppid("490655927");
url = "https://itunes.apple.com/cn/app/yoho!-you-huo/id490655927?mt=8";
}
}
//momochat/7.5.6 ios/664 (iphone 6; ios 10.2; zh_cn; iphone7,2; s1)
else if(agent.contains("momochat")){
String version = "";
if(agent.contains("ios")){
int first = agent.indexOf(" ios ")+4;
String version1 = agent.substring(first);
version = version1.substring(version1.indexOf(" ")+1, version1.indexOf(";"));
bo.setTd("ios_" + version.replaceAll("_", "."));
bo.setClient_type("ios");
bo.setAppid("490655927");
url = "https://itunes.apple.com/cn/app/yoho!-you-huo/id490655927?mt=8";
} //momochat/7.5.6 ios/664 (iphone 6s; iphone os 9.2; zh_cn; iphone8,1; s1)
else if(agent.contains("os")){
int first = agent.indexOf(" os ")+3;
String version1 = agent.substring(first);
version = version1.substring(version1.indexOf(" ")+1, version1.indexOf(";"));
bo.setTd("ios_" + version.replaceAll("_", "."));
bo.setClient_type("ios");
bo.setAppid("490655927");
url = "https://itunes.apple.com/cn/app/yoho!-you-huo/id490655927?mt=8";
}
}
else if(agent.contains("ios/")){
String version= "";
if(agent.contains("mozilla")){ // mozilla/5.0,ios/10.0.2,client/5.8.1,device/iphone6.2,theme/red
version = agent.substring(agent.indexOf("ios/")+4,agent.indexOf("client")-1);
}else if (agent.contains("iphone")) { //huazhu/ios/iphone9,2/10.2.1/6.5.3
int last = agent.lastIndexOf("/");
String version1 = agent.substring(0,last);
version = version1.substring(version1.lastIndexOf("/") + 1, version1.length());
bo.setTd("ios_" + version.replaceAll("_", "."));
bo.setClient_type("ios");
bo.setAppid("490655927");
url = "https://itunes.apple.com/cn/app/yoho!-you-huo/id490655927?mt=8";
}else{ //ios/6.6 com.jugg.doctor ipad5,3/8.3/768x1024/2.0 /1---这个应该就是ios_6.6
version = agent.substring(agent.indexOf("ios/")+4,agent.indexOf(" "));
bo.setTd("ios_" + version.replaceAll("_", "."));
bo.setClient_type("ios");
bo.setAppid("490655927");
url = "https://itunes.apple.com/cn/app/yoho!-you-huo/id490655927?mt=8";
}
}
//365jia news client/cn.ahurls.news/3.5.0_300500.209/ios(7.1|0|iphone)/59c2ed8b88175124c539e0c7a96a18d4eedb3d6c(none|none)/640x1136@2
else if(agent.contains("/ios")){
int first = agent.indexOf("/ios(") + 5;
String version1 = agent.substring(first);
String version = version1.substring(0,version1.indexOf("|"));
bo.setTd("ios_" + version.replaceAll("_", "."));
bo.setClient_type("ios");
bo.setAppid("490655927");
url = "https://itunes.apple.com/cn/app/yoho!-you-huo/id490655927?mt=8";
}
else if (agent.contains("ios")){
String version = "";
if(agent.contains("letvshop")){
//letvshop;1.6.6;iphone 6plus;ios-iphone;9.2;zh_cn
int lastIndex = agent.lastIndexOf(";");
String version1 = agent.substring(0,lastIndex);
version = agent.substring(version1.lastIndexOf(";")+1,lastIndex);
bo.setTd("ios_" + version.replaceAll("_", "."));
bo.setClient_type("ios");
bo.setAppid("490655927");
url = "https://itunes.apple.com/cn/app/yoho!-you-huo/id490655927?mt=8";
}else if(agent.contains("jxsg")) { //jxsg_ios-1.2.5/0.0.2 (iphone7,2; ios 10.2.1)
int first = agent.lastIndexOf("ios ") + 4;
String version1 = agent.substring(first);
int lastIndex = version1.indexOf(")");
version = version1.substring(version1.indexOf(" ") + 1, lastIndex);
bo.setTd("ios_" + version.replaceAll("_", "."));
bo.setClient_type("ios");
bo.setAppid("490655927");
url = "https://itunes.apple.com/cn/app/yoho!-you-huo/id490655927?mt=8";
}else{
int first = agent.lastIndexOf("ios ") + 4;
String version1 = agent.substring(first);
int lastIndex = version1.indexOf(";");
version = version1.substring(0, lastIndex);
bo.setTd("ios_" + version.replaceAll("_", "."));
bo.setClient_type("ios");
bo.setAppid("490655927");
url = "https://itunes.apple.com/cn/app/yoho!-you-huo/id490655927?mt=8";
}
}
}
public static void main(String[] args) {
String agent = "Mozilla/5.0 (iPhone; CPU iPhone OS like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Mobile TADChid/0 AppVersion/4.5.0";
agent = "Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Mobile/13B143 TADChid/0 AppVersion/4.8.5";
if (agent.toLowerCase().indexOf("mac os x") < 0 && agent.toLowerCase().indexOf("iphone") < 0) {
return;
}
if (agent.indexOf(" like") < agent.indexOf(" OS ") + 4) {
return;
}
String version = agent.substring(agent.indexOf(" OS ") + 4, agent.indexOf(" like"));
log.info("addUnion4Special version={}", version);
}
@RequestMapping("/addUnion4Jump")
public void addUnion4Stream(ClickUnionRequestBO bo, HttpServletRequest request, HttpServletResponse response) {
clickUnion.info("addUnion4Stream ClickUnionRequestBO{}", bo);
... ...