|
|
1
|
+package com.yoho.unions.server.service.impl;
|
|
|
2
|
+
|
|
|
3
|
+import com.yoho.core.common.utils.MD5;
|
|
|
4
|
+import com.yoho.service.model.union.request.TransPinYouRequestBO;
|
|
|
5
|
+import com.yoho.service.model.union.request.ViewPinYouRequestBO;
|
|
|
6
|
+import com.yoho.service.model.union.response.UnionResponse;
|
|
|
7
|
+import com.yoho.unions.common.enums.ClientTypeEnum;
|
|
|
8
|
+import com.yoho.unions.common.enums.EnentValueEnum;
|
|
|
9
|
+import com.yoho.unions.common.utils.DateUtil;
|
|
|
10
|
+import com.yoho.unions.common.utils.HttpUtils;
|
|
|
11
|
+import com.yoho.unions.server.service.IPinYouService;
|
|
|
12
|
+import org.apache.commons.lang.StringUtils;
|
|
|
13
|
+import org.apache.commons.lang3.tuple.Pair;
|
|
|
14
|
+import org.slf4j.Logger;
|
|
|
15
|
+import org.slf4j.LoggerFactory;
|
|
|
16
|
+import org.springframework.stereotype.Service;
|
|
|
17
|
+
|
|
|
18
|
+import java.net.URLDecoder;
|
|
|
19
|
+
|
|
|
20
|
+/**
|
|
|
21
|
+ * Created by yoho on 2016/11/15.
|
|
|
22
|
+ */
|
|
|
23
|
+@Service
|
|
|
24
|
+public class PinYouServiceImpl implements IPinYouService {
|
|
|
25
|
+
|
|
|
26
|
+ static Logger log = LoggerFactory.getLogger(PinYouServiceImpl.class);
|
|
|
27
|
+
|
|
|
28
|
+ static String PINYOU_VIEW_URL = "http://stats.ipinyou.com/madv?";
|
|
|
29
|
+
|
|
|
30
|
+ static String PINYOU_TRANS_URL = "http://stats.ipinyou.com/mcdv?";
|
|
|
31
|
+
|
|
|
32
|
+ @Override
|
|
|
33
|
+ /**
|
|
|
34
|
+ * jp:启动参数,固定位1
|
|
|
35
|
+ *df:debug flag 固定0
|
|
|
36
|
+ */
|
|
|
37
|
+ public UnionResponse sendViem(ViewPinYouRequestBO requestBO){
|
|
|
38
|
+ //广告主信息
|
|
|
39
|
+ String advertiser = "MC.LF";
|
|
|
40
|
+ //操作系统信息
|
|
|
41
|
+ String os = requestBO.getOs();
|
|
|
42
|
+ //根据从大数据获取的IDFA,IMEI来判断是安卓还是IOS
|
|
|
43
|
+ String client_type = ClientTypeEnum.IOS.getName();
|
|
|
44
|
+ String idfa = requestBO.getIdfa();
|
|
|
45
|
+ String imei = requestBO.getImei();
|
|
|
46
|
+ if(StringUtils.isEmpty(idfa)){
|
|
|
47
|
+ client_type = ClientTypeEnum.ANDROID.getName();
|
|
|
48
|
+ }
|
|
|
49
|
+ //时间戳
|
|
|
50
|
+ int currentTime = DateUtil.getCurrentTimeSecond();
|
|
|
51
|
+ //启动参数,固定位1
|
|
|
52
|
+ String jp = "1";
|
|
|
53
|
+ //用户id
|
|
|
54
|
+ String user_id = requestBO.getUser_id();
|
|
|
55
|
+ //用户行为事件
|
|
|
56
|
+ String event = requestBO.getEvent();
|
|
|
57
|
+ //用户行为数据
|
|
|
58
|
+ String event_value = requestBO.getEvent_value();
|
|
|
59
|
+ //客户端ip
|
|
|
60
|
+ String ip = requestBO.getIp();
|
|
|
61
|
+ //debug flag
|
|
|
62
|
+ String df = "0";
|
|
|
63
|
+ //按照品友的格式进行拼接
|
|
|
64
|
+ StringBuffer stringBuffer = new StringBuffer();
|
|
|
65
|
+ stringBuffer = stringBuffer.append(PINYOU_VIEW_URL).append("a=")
|
|
|
66
|
+ .append(advertiser).append("&os=").append(os)
|
|
|
67
|
+ .append("&ts=").append(currentTime)
|
|
|
68
|
+ .append("&jp=1").append("&ip=").append(ip)
|
|
|
69
|
+ .append("&event=").append(event)
|
|
|
70
|
+ .append("&event_vaule").append(event_value).append("&df=0");
|
|
|
71
|
+ String url = null;
|
|
|
72
|
+ if(event_value.equals(EnentValueEnum.ADD_CART.getName())||event_value.equals(EnentValueEnum.VIEW_ITEM.getName())){
|
|
|
73
|
+ stringBuffer= stringBuffer.append("&p").append(event_value);
|
|
|
74
|
+ }
|
|
|
75
|
+ if(StringUtils.isNotEmpty(user_id)){
|
|
|
76
|
+ stringBuffer = stringBuffer.append("&user_id").append(user_id);
|
|
|
77
|
+ }
|
|
|
78
|
+ if(client_type.equalsIgnoreCase(ClientTypeEnum.ANDROID.getName())){
|
|
|
79
|
+ //如果是浏览商品和加入购物车则需要传p=商品编号
|
|
|
80
|
+ String dim = MD5.md5(imei);
|
|
|
81
|
+ stringBuffer = stringBuffer.append("&dim=").append(dim);
|
|
|
82
|
+ }
|
|
|
83
|
+ if(client_type.equalsIgnoreCase(ClientTypeEnum.IOS.getName())){
|
|
|
84
|
+ String iam = MD5.md5(idfa);
|
|
|
85
|
+ stringBuffer = stringBuffer.append("&iam=").append(iam);
|
|
|
86
|
+ }
|
|
|
87
|
+ url = stringBuffer.toString();
|
|
|
88
|
+ UnionResponse response = sendUrl(url);
|
|
|
89
|
+ return response;
|
|
|
90
|
+ }
|
|
|
91
|
+
|
|
|
92
|
+ public UnionResponse sendTrans(TransPinYouRequestBO requestBO){
|
|
|
93
|
+ //广告主信息
|
|
|
94
|
+ String advertiser = "MC.LF";
|
|
|
95
|
+ //操作系统信息
|
|
|
96
|
+ String os = requestBO.getOs();
|
|
|
97
|
+ //根据从大数据获取的IDFA,IMEI来判断是安卓还是IOS
|
|
|
98
|
+ String client_type = ClientTypeEnum.IOS.getName();
|
|
|
99
|
+ String idfa = requestBO.getIdfa();
|
|
|
100
|
+ String imei = requestBO.getImei();
|
|
|
101
|
+ if(StringUtils.isEmpty(idfa)){
|
|
|
102
|
+ client_type = ClientTypeEnum.ANDROID.getName();
|
|
|
103
|
+ }
|
|
|
104
|
+ //时间戳
|
|
|
105
|
+ int currentTime = DateUtil.getCurrentTimeSecond();
|
|
|
106
|
+ //启动参数,固定位1
|
|
|
107
|
+ String jp = "1";
|
|
|
108
|
+ //用户id
|
|
|
109
|
+ String user_id = requestBO.getUser_id();
|
|
|
110
|
+ //用户行为事件
|
|
|
111
|
+ String event = requestBO.getEvent();
|
|
|
112
|
+ //用户行为数据
|
|
|
113
|
+ String event_value = requestBO.getEvent_value();
|
|
|
114
|
+ //客户端ip
|
|
|
115
|
+ String ip = requestBO.getIp();
|
|
|
116
|
+ //debug flag
|
|
|
117
|
+ String df = "0";
|
|
|
118
|
+ StringBuffer stringBuffer = new StringBuffer();
|
|
|
119
|
+ stringBuffer = stringBuffer.append(PINYOU_TRANS_URL).append("a=")
|
|
|
120
|
+ .append(advertiser).append("&os=").append(os)
|
|
|
121
|
+ .append("&ts=").append(currentTime)
|
|
|
122
|
+ .append("&jp=1").append("&ip=").append(ip)
|
|
|
123
|
+ .append("&event=").append(event)
|
|
|
124
|
+ .append("&event_vaule").append(event_value).append("&df=0")
|
|
|
125
|
+ .append("&p=").append(event_value).append("&user_id").append(user_id);
|
|
|
126
|
+ String url = null;
|
|
|
127
|
+ if(client_type.equalsIgnoreCase(ClientTypeEnum.ANDROID.getName())){
|
|
|
128
|
+ //如果是浏览商品和加入购物车则需要传p=商品编号
|
|
|
129
|
+ String dim = MD5.md5(imei);
|
|
|
130
|
+ stringBuffer = stringBuffer.append("&dim=").append(dim);
|
|
|
131
|
+ }
|
|
|
132
|
+ if(client_type.equalsIgnoreCase(ClientTypeEnum.IOS.getName())){
|
|
|
133
|
+ String iam = MD5.md5(idfa);
|
|
|
134
|
+ stringBuffer = stringBuffer.append("&iam=").append(iam);
|
|
|
135
|
+ }
|
|
|
136
|
+ url = stringBuffer.toString();
|
|
|
137
|
+ UnionResponse response = sendUrl(url);
|
|
|
138
|
+ return response;
|
|
|
139
|
+ }
|
|
|
140
|
+
|
|
|
141
|
+ private UnionResponse sendUrl(String url){
|
|
|
142
|
+ log.info("sendUrl url is {}",url);
|
|
|
143
|
+ try{
|
|
|
144
|
+ url = URLDecoder.decode(url, "UTF-8");
|
|
|
145
|
+ Pair<Integer, String> pair = HttpUtils.httpGet(url);
|
|
|
146
|
+ log.info("activateUnion call union success url={}, and result={}", url, pair);
|
|
|
147
|
+ if (pair.getLeft() != 200) {
|
|
|
148
|
+ log.warn("callback error with request={}", url);
|
|
|
149
|
+ return new UnionResponse(204, "callback error");
|
|
|
150
|
+ }
|
|
|
151
|
+ }catch (Exception e){
|
|
|
152
|
+ log.error("callback error with request={}", url, e.getMessage());
|
|
|
153
|
+ }
|
|
|
154
|
+ return new UnionResponse();
|
|
|
155
|
+ }
|
|
|
156
|
+} |