...
|
...
|
@@ -6,16 +6,21 @@ 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.redis.RedisListCache;
|
|
|
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.collections.CollectionUtils;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.apache.commons.lang3.tuple.Pair;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.net.URLDecoder;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
|
* Created by yoho on 2016/11/15.
|
...
|
...
|
@@ -29,12 +34,56 @@ public class PinYouServiceImpl implements IPinYouService { |
|
|
|
|
|
static String PINYOU_TRANS_URL = "http://stats.ipinyou.com/mcvt?";
|
|
|
|
|
|
private static final String UNION_VIEW_KEY = "union:pinyou:view";
|
|
|
|
|
|
private static final String UNION_TRANS_KEY = "union:pinyou:trans";
|
|
|
|
|
|
@Autowired
|
|
|
private RedisListCache redisListCache;
|
|
|
|
|
|
@Override
|
|
|
public UnionResponse sendPinYou() {
|
|
|
//从redis里面获取大数据的数据
|
|
|
Long viewSize = redisListCache.size(UNION_VIEW_KEY);
|
|
|
Long transSize = redisListCache.size(UNION_TRANS_KEY);
|
|
|
List<ViewPinYouRequestBO> viewPinYouRequestBOList = new ArrayList<>();
|
|
|
int viewSizeInt = viewSize == null ? 0 : viewSize.intValue();
|
|
|
int transSizeInt = transSize == null ? 0 : transSize.intValue();
|
|
|
List<TransPinYouRequestBO> transPinYouRequestBOList = new ArrayList<>();
|
|
|
|
|
|
if (viewSizeInt > 0) {
|
|
|
for (int i = 0; i < viewSizeInt; i++) {
|
|
|
ViewPinYouRequestBO viewPinYouRequestBO = redisListCache.rightPop(UNION_VIEW_KEY, ViewPinYouRequestBO.class);
|
|
|
viewPinYouRequestBOList.add(viewPinYouRequestBO);
|
|
|
}
|
|
|
}
|
|
|
if (transSizeInt > 0) {
|
|
|
for (int i = 0; i < transSizeInt; i++) {
|
|
|
TransPinYouRequestBO transPinYouRequestBO = redisListCache.rightPop(UNION_TRANS_KEY, TransPinYouRequestBO.class);
|
|
|
transPinYouRequestBOList.add(transPinYouRequestBO);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (CollectionUtils.isNotEmpty(viewPinYouRequestBOList)) {
|
|
|
for (ViewPinYouRequestBO requestBO : viewPinYouRequestBOList) {
|
|
|
sendView(requestBO);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (CollectionUtils.isNotEmpty(transPinYouRequestBOList)) {
|
|
|
for (TransPinYouRequestBO transPinYouRequestBO : transPinYouRequestBOList) {
|
|
|
sendTrans(transPinYouRequestBO);
|
|
|
}
|
|
|
}
|
|
|
return new UnionResponse();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* jp:启动参数,固定位1
|
|
|
*df:debug flag 固定0
|
|
|
* df:debug flag 固定0
|
|
|
*/
|
|
|
public UnionResponse sendViem(ViewPinYouRequestBO requestBO){
|
|
|
@Override
|
|
|
public UnionResponse sendView(ViewPinYouRequestBO requestBO) {
|
|
|
//广告主信息
|
|
|
String advertiser = "MC.LF";
|
|
|
//操作系统信息
|
...
|
...
|
@@ -44,12 +93,15 @@ public class PinYouServiceImpl implements IPinYouService { |
|
|
String client_type = ClientTypeEnum.IOS.getName();
|
|
|
String idfa = requestBO.getIdfa();
|
|
|
String imei = requestBO.getImei();
|
|
|
if(idfa.equals("")||StringUtils.isEmpty(idfa)){
|
|
|
if (idfa.equals("") || StringUtils.isEmpty(idfa)) {
|
|
|
client_type = ClientTypeEnum.ANDROID.getName();
|
|
|
os = ClientTypeEnum.ANDROID.getName();
|
|
|
}
|
|
|
//时间戳
|
|
|
int currentTime = DateUtil.getCurrentTimeSecond();
|
|
|
String ts = requestBO.getTs();
|
|
|
if (StringUtils.isEmpty(ts)) {
|
|
|
ts = String.valueOf(DateUtil.getCurrentTimeSecond() * 1000);
|
|
|
}
|
|
|
//启动参数,固定位1
|
|
|
String jp = "1";
|
|
|
//用户id
|
...
|
...
|
@@ -67,23 +119,23 @@ public class PinYouServiceImpl implements IPinYouService { |
|
|
StringBuffer stringBuffer = new StringBuffer();
|
|
|
stringBuffer = stringBuffer.append(PINYOU_VIEW_URL).append("a=")
|
|
|
.append(advertiser).append("&os=").append(os)
|
|
|
.append("&ts=").append(currentTime)
|
|
|
.append("&ts=").append(ts)
|
|
|
.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.equals(EnentValueEnum.ADD_CART.getName())||event.equals(EnentValueEnum.VIEW_ITEM.getName())){
|
|
|
stringBuffer= stringBuffer.append("&p=").append(event_value);
|
|
|
if (event.equals(EnentValueEnum.ADD_CART.getName()) || event.equals(EnentValueEnum.VIEW_ITEM.getName())) {
|
|
|
stringBuffer = stringBuffer.append("&p=").append(event_value);
|
|
|
}
|
|
|
if(StringUtils.isNotEmpty(user_id)&& user_id.matches("[0-9]+")){
|
|
|
if (StringUtils.isNotEmpty(user_id) && user_id.matches("[0-9]+")) {
|
|
|
stringBuffer = stringBuffer.append("&user_id=").append(user_id);
|
|
|
}
|
|
|
if(client_type.equalsIgnoreCase(ClientTypeEnum.ANDROID.getName())){
|
|
|
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())){
|
|
|
if (client_type.equalsIgnoreCase(ClientTypeEnum.IOS.getName())) {
|
|
|
String iam = MD5.md5(idfa);
|
|
|
stringBuffer = stringBuffer.append("&iam=").append(iam);
|
|
|
}
|
...
|
...
|
@@ -92,22 +144,25 @@ public class PinYouServiceImpl implements IPinYouService { |
|
|
return response;
|
|
|
}
|
|
|
|
|
|
public UnionResponse sendTrans(TransPinYouRequestBO requestBO){
|
|
|
public UnionResponse sendTrans(TransPinYouRequestBO requestBO) {
|
|
|
//广告主信息
|
|
|
String advertiser = "MC.LF";
|
|
|
//操作系统信息
|
|
|
String os = requestBO.getOs();
|
|
|
//根据从大数据获取的IDFA,IMEI来判断是安卓还是IOS
|
|
|
String client_type = ClientTypeEnum.IOS.getName();
|
|
|
os=ClientTypeEnum.IOS.getName();
|
|
|
os = ClientTypeEnum.IOS.getName();
|
|
|
String idfa = requestBO.getIdfa();
|
|
|
String imei = requestBO.getImei();
|
|
|
if(idfa.equals("")||StringUtils.isEmpty(idfa)){
|
|
|
if (idfa.equals("") || StringUtils.isEmpty(idfa)) {
|
|
|
client_type = ClientTypeEnum.ANDROID.getName();
|
|
|
os=ClientTypeEnum.ANDROID.getName();
|
|
|
os = ClientTypeEnum.ANDROID.getName();
|
|
|
}
|
|
|
//时间戳
|
|
|
int currentTime = DateUtil.getCurrentTimeSecond();
|
|
|
String ts = requestBO.getTs();
|
|
|
if (StringUtils.isEmpty(ts)) {
|
|
|
ts = String.valueOf(DateUtil.getCurrentTimeSecond() * 1000);
|
|
|
}
|
|
|
|
|
|
String order = requestBO.getOrder();
|
|
|
String money = requestBO.getMoney();
|
...
|
...
|
@@ -122,27 +177,27 @@ public class PinYouServiceImpl implements IPinYouService { |
|
|
StringBuffer stringBuffer = new StringBuffer();
|
|
|
stringBuffer = stringBuffer.append(PINYOU_TRANS_URL).append("a=")
|
|
|
.append(advertiser).append("&os=").append(os)
|
|
|
.append("&ts=").append(currentTime)
|
|
|
.append("&ts=").append(ts)
|
|
|
.append("&ip=").append(ip)
|
|
|
.append("&df=0").append("&order=").append(order)
|
|
|
.append("&money=").append(money)
|
|
|
.append("&plist=").append(plist);
|
|
|
String url = null;
|
|
|
if(client_type.equalsIgnoreCase(ClientTypeEnum.ANDROID.getName())){
|
|
|
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())){
|
|
|
if (client_type.equalsIgnoreCase(ClientTypeEnum.IOS.getName())) {
|
|
|
String iam = MD5.md5(idfa);
|
|
|
stringBuffer = stringBuffer.append("&iam=").append(iam);
|
|
|
}
|
|
|
if(StringUtils.isNotEmpty(user_id)&& user_id.matches("[0-9]+")){
|
|
|
if (StringUtils.isNotEmpty(user_id) && user_id.matches("[0-9]+")) {
|
|
|
stringBuffer = stringBuffer.append("&user_id=").append(user_id);
|
|
|
}
|
|
|
if(orderStatus.equals("1")||orderStatus.equals("2")){
|
|
|
if (orderStatus.equals("1") || orderStatus.equals("2")) {
|
|
|
stringBuffer = stringBuffer.append("&gl=9466");
|
|
|
}else{
|
|
|
} else {
|
|
|
stringBuffer = stringBuffer.append("&gl=334");
|
|
|
}
|
|
|
url = stringBuffer.toString();
|
...
|
...
|
@@ -150,9 +205,9 @@ public class PinYouServiceImpl implements IPinYouService { |
|
|
return response;
|
|
|
}
|
|
|
|
|
|
private UnionResponse sendUrl(String url){
|
|
|
log.info("sendUrl url is {}",url);
|
|
|
try{
|
|
|
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);
|
...
|
...
|
@@ -160,9 +215,9 @@ public class PinYouServiceImpl implements IPinYouService { |
|
|
log.warn("callback error with request={}", url);
|
|
|
return new UnionResponse(204, "callback error");
|
|
|
}
|
|
|
}catch (Exception e){
|
|
|
} catch (Exception e) {
|
|
|
log.error("callback error with request={}", url, e.getMessage());
|
|
|
}
|
|
|
return new UnionResponse();
|
|
|
return new UnionResponse();
|
|
|
}
|
|
|
} |
...
|
...
|
|