|
|
package com.yoho.unions.server.service.impl;
|
|
|
|
|
|
import com.yoho.core.common.utils.MD5;
|
|
|
import com.yoho.service.model.union.request.TransPinYouRequestBO;
|
|
|
import com.yoho.service.model.union.request.ViewPinYouRequestBO;
|
|
|
import com.yoho.service.model.union.response.UnionResponse;
|
|
|
import com.yoho.unions.common.enums.ClientTypeEnum;
|
|
|
import com.yoho.unions.common.enums.EnentValueEnum;
|
|
|
import com.yoho.unions.common.utils.DateUtil;
|
|
|
import com.yoho.unions.common.utils.HttpUtils;
|
|
|
import com.yoho.unions.server.service.IPinYouService;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.apache.commons.lang3.tuple.Pair;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.net.URLDecoder;
|
|
|
|
|
|
/**
|
|
|
* Created by yoho on 2016/11/15.
|
|
|
*/
|
|
|
@Service
|
|
|
public class PinYouServiceImpl implements IPinYouService {
|
|
|
|
|
|
static Logger log = LoggerFactory.getLogger(PinYouServiceImpl.class);
|
|
|
|
|
|
static String PINYOU_VIEW_URL = "http://stats.ipinyou.com/madv?";
|
|
|
|
|
|
static String PINYOU_TRANS_URL = "http://stats.ipinyou.com/mcdv?";
|
|
|
|
|
|
@Override
|
|
|
/**
|
|
|
* jp:启动参数,固定位1
|
|
|
*df:debug flag 固定0
|
|
|
*/
|
|
|
public UnionResponse sendViem(ViewPinYouRequestBO requestBO){
|
|
|
//广告主信息
|
|
|
String advertiser = "MC.LF";
|
|
|
//操作系统信息
|
|
|
String os = requestBO.getOs();
|
|
|
//根据从大数据获取的IDFA,IMEI来判断是安卓还是IOS
|
|
|
String client_type = ClientTypeEnum.IOS.getName();
|
|
|
String idfa = requestBO.getIdfa();
|
|
|
String imei = requestBO.getImei();
|
|
|
if(StringUtils.isEmpty(idfa)){
|
|
|
client_type = ClientTypeEnum.ANDROID.getName();
|
|
|
}
|
|
|
//时间戳
|
|
|
int currentTime = DateUtil.getCurrentTimeSecond();
|
|
|
//启动参数,固定位1
|
|
|
String jp = "1";
|
|
|
//用户id
|
|
|
String user_id = requestBO.getUser_id();
|
|
|
//用户行为事件
|
|
|
String event = requestBO.getEvent();
|
|
|
//用户行为数据
|
|
|
String event_value = requestBO.getEvent_value();
|
|
|
//客户端ip
|
|
|
String ip = requestBO.getIp();
|
|
|
//debug flag
|
|
|
String df = "0";
|
|
|
//按照品友的格式进行拼接
|
|
|
StringBuffer stringBuffer = new StringBuffer();
|
|
|
stringBuffer = stringBuffer.append(PINYOU_VIEW_URL).append("a=")
|
|
|
.append(advertiser).append("&os=").append(os)
|
|
|
.append("&ts=").append(currentTime)
|
|
|
.append("&jp=1").append("&ip=").append(ip)
|
|
|
.append("&event=").append(event)
|
|
|
.append("&event_vaule").append(event_value).append("&df=0");
|
|
|
String url = null;
|
|
|
if(event_value.equals(EnentValueEnum.ADD_CART.getName())||event_value.equals(EnentValueEnum.VIEW_ITEM.getName())){
|
|
|
stringBuffer= stringBuffer.append("&p").append(event_value);
|
|
|
}
|
|
|
if(StringUtils.isNotEmpty(user_id)){
|
|
|
stringBuffer = stringBuffer.append("&user_id").append(user_id);
|
|
|
}
|
|
|
if(client_type.equalsIgnoreCase(ClientTypeEnum.ANDROID.getName())){
|
|
|
//如果是浏览商品和加入购物车则需要传p=商品编号
|
|
|
String dim = MD5.md5(imei);
|
|
|
stringBuffer = stringBuffer.append("&dim=").append(dim);
|
|
|
}
|
|
|
if(client_type.equalsIgnoreCase(ClientTypeEnum.IOS.getName())){
|
|
|
String iam = MD5.md5(idfa);
|
|
|
stringBuffer = stringBuffer.append("&iam=").append(iam);
|
|
|
}
|
|
|
url = stringBuffer.toString();
|
|
|
UnionResponse response = sendUrl(url);
|
|
|
return response;
|
|
|
}
|
|
|
|
|
|
public UnionResponse sendTrans(TransPinYouRequestBO requestBO){
|
|
|
//广告主信息
|
|
|
String advertiser = "MC.LF";
|
|
|
//操作系统信息
|
|
|
String os = requestBO.getOs();
|
|
|
//根据从大数据获取的IDFA,IMEI来判断是安卓还是IOS
|
|
|
String client_type = ClientTypeEnum.IOS.getName();
|
|
|
String idfa = requestBO.getIdfa();
|
|
|
String imei = requestBO.getImei();
|
|
|
if(StringUtils.isEmpty(idfa)){
|
|
|
client_type = ClientTypeEnum.ANDROID.getName();
|
|
|
}
|
|
|
//时间戳
|
|
|
int currentTime = DateUtil.getCurrentTimeSecond();
|
|
|
//启动参数,固定位1
|
|
|
String jp = "1";
|
|
|
//用户id
|
|
|
String user_id = requestBO.getUser_id();
|
|
|
//用户行为事件
|
|
|
String event = requestBO.getEvent();
|
|
|
//用户行为数据
|
|
|
String event_value = requestBO.getEvent_value();
|
|
|
//客户端ip
|
|
|
String ip = requestBO.getIp();
|
|
|
//debug flag
|
|
|
String df = "0";
|
|
|
StringBuffer stringBuffer = new StringBuffer();
|
|
|
stringBuffer = stringBuffer.append(PINYOU_TRANS_URL).append("a=")
|
|
|
.append(advertiser).append("&os=").append(os)
|
|
|
.append("&ts=").append(currentTime)
|
|
|
.append("&jp=1").append("&ip=").append(ip)
|
|
|
.append("&event=").append(event)
|
|
|
.append("&event_vaule").append(event_value).append("&df=0")
|
|
|
.append("&p=").append(event_value).append("&user_id").append(user_id);
|
|
|
String url = null;
|
|
|
if(client_type.equalsIgnoreCase(ClientTypeEnum.ANDROID.getName())){
|
|
|
//如果是浏览商品和加入购物车则需要传p=商品编号
|
|
|
String dim = MD5.md5(imei);
|
|
|
stringBuffer = stringBuffer.append("&dim=").append(dim);
|
|
|
}
|
|
|
if(client_type.equalsIgnoreCase(ClientTypeEnum.IOS.getName())){
|
|
|
String iam = MD5.md5(idfa);
|
|
|
stringBuffer = stringBuffer.append("&iam=").append(iam);
|
|
|
}
|
|
|
url = stringBuffer.toString();
|
|
|
UnionResponse response = sendUrl(url);
|
|
|
return response;
|
|
|
}
|
|
|
|
|
|
private UnionResponse sendUrl(String url){
|
|
|
log.info("sendUrl url is {}",url);
|
|
|
try{
|
|
|
url = URLDecoder.decode(url, "UTF-8");
|
|
|
Pair<Integer, String> pair = HttpUtils.httpGet(url);
|
|
|
log.info("activateUnion call union success url={}, and result={}", url, pair);
|
|
|
if (pair.getLeft() != 200) {
|
|
|
log.warn("callback error with request={}", url);
|
|
|
return new UnionResponse(204, "callback error");
|
|
|
}
|
|
|
}catch (Exception e){
|
|
|
log.error("callback error with request={}", url, e.getMessage());
|
|
|
}
|
|
|
return new UnionResponse();
|
|
|
}
|
|
|
} |
...
|
...
|
|