Commit 5ba5ece1 authored by 宋新宇's avatar 宋新宇

点击

parent c012ce7b
...@@ -2,6 +2,7 @@ package com.lwby.marketing.controller; ...@@ -2,6 +2,7 @@ package com.lwby.marketing.controller;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.lwby.marketing.notify.Media; import com.lwby.marketing.notify.Media;
...@@ -14,6 +15,7 @@ import lombok.extern.slf4j.Slf4j; ...@@ -14,6 +15,7 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
...@@ -42,11 +44,45 @@ public class ClickbackService extends ServiceHelper{ ...@@ -42,11 +44,45 @@ public class ClickbackService extends ServiceHelper{
@Resource @Resource
public RedisTemplate<String, String> redisTemplate; public RedisTemplate<String, String> redisTemplate;
@Resource(name = "storyKafka")
public KafkaTemplate<String, String> storyKafkaTemplate;
@RequestMapping("/jrtt") @RequestMapping("/jrtt")
@ResponseBody @ResponseBody
public Object jrttClick(@RequestParam Map<String, String> params){ public Object jrttClick(@RequestParam Map<String, String> params){
NovelAction action = full(params); NovelAction action = fullJrtt(params);
for(DeviceType type: DeviceType.values()){
String deviceIdKey = type.getDeviceId(action.getClientInfo());
if(null != deviceIdKey){
DeliveryDeviceInfo ddi = action.getDeliveryDeviceInfo();
if (StringUtils.isNotEmpty(ddi.getDj_channel())) {
redisTemplate.opsForValue().set(CacheKeyUtils.getChannelByDeviceIdKeyAndPlatformId(assembleKey(deviceIdKey,type), ddi.getPlatform_id()),JSON.toJSONString(Integer.parseInt(ddi.getDj_channel())), bookIdExpireTime, TimeUnit.SECONDS);
if (StringUtils.isNumeric(ddi.getBook_id())) {
redisTemplate.opsForValue().set(CacheKeyUtils.getDeliveryBookIdCacheKey(assembleKey(deviceIdKey,type), ddi.getPlatform_id()),JSON.toJSONString(ddi.getBook_id()), bookIdExpireTime, TimeUnit.SECONDS);
if (StringUtils.isNumeric(ddi.getPartId())) {
redisTemplate.opsForValue().set(CacheKeyUtils.getDeliveryPartIdCacheKey(assembleKey(deviceIdKey,type), ddi.getPlatform_id()),JSON.toJSONString(ddi.getPartId()), bookIdExpireTime, TimeUnit.SECONDS);
}
}
}
if (type == DeviceType.IP) {
redisTemplate.opsForValue().set(CacheKeyUtils.getClickKey(assembleKey(deviceIdKey,type), ddi.getPlatform_id()),JSON.toJSONString(ddi),bookIdExpireTime, TimeUnit.SECONDS);
} else {
redisTemplate.opsForValue().set(CacheKeyUtils.getClickKeyByIdfaAndPlatformId(assembleKey(deviceIdKey,type), ddi.getPlatform_id()),JSON.toJSONString(ddi),bookIdExpireTime, TimeUnit.SECONDS);
}
}
}
return RESULT_SUCCESS;
}
@RequestMapping("/weChat")
@ResponseBody
public Object wechatClick(@RequestParam Map<String, String> params){
NovelAction action = fullWeChat(params);
for(DeviceType type: DeviceType.values()){ for(DeviceType type: DeviceType.values()){
String deviceIdKey = type.getDeviceId(action.getClientInfo()); String deviceIdKey = type.getDeviceId(action.getClientInfo());
...@@ -54,27 +90,33 @@ public class ClickbackService extends ServiceHelper{ ...@@ -54,27 +90,33 @@ public class ClickbackService extends ServiceHelper{
DeliveryDeviceInfo ddi = action.getDeliveryDeviceInfo(); DeliveryDeviceInfo ddi = action.getDeliveryDeviceInfo();
if (StringUtils.isNotEmpty(ddi.getDj_channel())) { if (StringUtils.isNotEmpty(ddi.getDj_channel())) {
redisTemplate.opsForValue().set(CacheKeyUtils.getChannelByDeviceIdKeyAndPlatformId(deviceIdKey, ddi.getPlatform_id()),JSON.toJSONString(Integer.parseInt(ddi.getDj_channel())), bookIdExpireTime, TimeUnit.SECONDS); redisTemplate.opsForValue().set(CacheKeyUtils.getChannelByDeviceIdKeyAndPlatformId(assembleKey(deviceIdKey,type), ddi.getPlatform_id()),JSON.toJSONString(Integer.parseInt(ddi.getDj_channel())), bookIdExpireTime, TimeUnit.SECONDS);
if (StringUtils.isNumeric(ddi.getBook_id())) { if (StringUtils.isNumeric(ddi.getBook_id())) {
redisTemplate.opsForValue().set(CacheKeyUtils.getDeliveryBookIdCacheKey(deviceIdKey, ddi.getPlatform_id()),JSON.toJSONString(ddi.getBook_id()), bookIdExpireTime, TimeUnit.SECONDS); redisTemplate.opsForValue().set(CacheKeyUtils.getDeliveryBookIdCacheKey(assembleKey(deviceIdKey,type), ddi.getPlatform_id()),JSON.toJSONString(ddi.getBook_id()), bookIdExpireTime, TimeUnit.SECONDS);
if (StringUtils.isNumeric(ddi.getPartId())) { if (StringUtils.isNumeric(ddi.getPartId())) {
redisTemplate.opsForValue().set(CacheKeyUtils.getDeliveryPartIdCacheKey(deviceIdKey, ddi.getPlatform_id()),JSON.toJSONString(ddi.getPartId()), bookIdExpireTime, TimeUnit.SECONDS); redisTemplate.opsForValue().set(CacheKeyUtils.getDeliveryPartIdCacheKey(assembleKey(deviceIdKey,type), ddi.getPlatform_id()),JSON.toJSONString(ddi.getPartId()), bookIdExpireTime, TimeUnit.SECONDS);
}
} }
} }
if (type == DeviceType.IP) {
redisTemplate.opsForValue().set(CacheKeyUtils.getClickKey(assembleKey(deviceIdKey,type), ddi.getPlatform_id()),JSON.toJSONString(ddi),bookIdExpireTime, TimeUnit.SECONDS);
} else {
redisTemplate.opsForValue().set(CacheKeyUtils.getClickKeyByIdfaAndPlatformId(assembleKey(deviceIdKey,type), ddi.getPlatform_id()),JSON.toJSONString(ddi),bookIdExpireTime, TimeUnit.SECONDS);
} }
redisTemplate.opsForValue().set(CacheKeyUtils.getClickKeyByIdfaAndPlatformId(deviceIdKey, ddi.getPlatform_id()),JSON.toJSONString(ddi),bookIdExpireTime, TimeUnit.SECONDS);
} }
} }
return RESULT_SUCCESS; return RESULT_SUCCESS;
} }
public NovelAction full(Map<String, String> params) { public NovelAction fullJrtt(Map<String, String> params) {
ClientInfo clientInfo = new ClientInfo(); ClientInfo clientInfo = new ClientInfo();
//imeiMd5
clientInfo.setImei(params.get("imei")); clientInfo.setImei(params.get("imei"));
clientInfo.setOaid(params.get("oaid")); clientInfo.setOaid(params.get("oaid_md5"));
clientInfo.setIdfa(params.get("idfa")); clientInfo.setIdfa(params.get("idfaMd5"));
clientInfo.setClientIp(params.get("ip")); clientInfo.setClientIp(params.get("ip"));
clientInfo.setUa(params.get("ua")); clientInfo.setUa(params.get("ua"));
clientInfo.setPhoneModel(encode(params.get("model"))); clientInfo.setPhoneModel(encode(params.get("model")));
...@@ -95,6 +137,16 @@ public class ClickbackService extends ServiceHelper{ ...@@ -95,6 +137,16 @@ public class ClickbackService extends ServiceHelper{
deliveryDeviceInfo.setUuid(UUID.randomUUID().toString()); deliveryDeviceInfo.setUuid(UUID.randomUUID().toString());
deliveryDeviceInfo.setAd_platform_type(params.get("ad_platform_type")); deliveryDeviceInfo.setAd_platform_type(params.get("ad_platform_type"));
deliveryDeviceInfo.setTarget_audience(params.get("target_audience")); deliveryDeviceInfo.setTarget_audience(params.get("target_audience"));
deliveryDeviceInfo.setIp(params.get("ip"));
if (!filter.contains(params.get("oaid"))) {
deliveryDeviceInfo.setOaid(params.get("oaid"));
}
if (StringUtils.isNotEmpty(clientInfo.getImei())) {
deliveryDeviceInfo.setImeiMd5(clientInfo.getImei());
}
if (StringUtils.isNotEmpty(clientInfo.getPhoneModel())) {
deliveryDeviceInfo.setModel(clientInfo.getPhoneModel());
}
//通投智选union_site //通投智选union_site
deliveryDeviceInfo.setUnion_site(params.get("union_site")); deliveryDeviceInfo.setUnion_site(params.get("union_site"));
deliveryDeviceInfo.setPartId(params.get("part_id")); deliveryDeviceInfo.setPartId(params.get("part_id"));
...@@ -109,6 +161,58 @@ public class ClickbackService extends ServiceHelper{ ...@@ -109,6 +161,58 @@ public class ClickbackService extends ServiceHelper{
//信息流投放广告来源(碎片 1 书籍 2) //信息流投放广告来源(碎片 1 书籍 2)
deliveryDeviceInfo.setSource(parseInt(params.get("source"))); deliveryDeviceInfo.setSource(parseInt(params.get("source")));
storyKafkaTemplate.send("growth_ad_click", JSONObject.toJSONString(params));
return new NovelAction(clientInfo,deliveryDeviceInfo);
}
public NovelAction fullWeChat(Map<String, String> params) {
ClientInfo clientInfo = new ClientInfo();
String deviceOsType = params.get("device_os_type");
if ("android".equals(deviceOsType)) {
clientInfo.setImei(params.get("muid"));
} else if ("ios".equals(deviceOsType)) {
clientInfo.setIdfa(params.get("muid"));
}
clientInfo.setOaid(params.get("hash_oaid"));
clientInfo.setClientIp(params.get("ip"));
clientInfo.setUa(params.get("user_agent"));
clientInfo.setPhoneModel(encode(params.get("model")));
DeliveryDeviceInfo deliveryDeviceInfo = new DeliveryDeviceInfo();
deliveryDeviceInfo.setClick_time(System.currentTimeMillis());
deliveryDeviceInfo.setClick_id(params.get("click_id"));
deliveryDeviceInfo.setAd_group_id(params.get("campaign_id"));
deliveryDeviceInfo.setAd_creative_id(params.get("ad_id"));
deliveryDeviceInfo.setAd_plan_id(params.get("adgroup_id"));
deliveryDeviceInfo.setMedia(Media.NOVEL_GDT.name);
deliveryDeviceInfo.setPlatform_id(params.get("platformId"));
deliveryDeviceInfo.setDj_channel(params.get("channel"));
deliveryDeviceInfo.setBook_id(StringUtils.defaultIfBlank(params.get("book"), StringUtils.defaultIfBlank(params.get("books"), params.get("book_id"))));
deliveryDeviceInfo.setCallback_url(params.get("callback"));
deliveryDeviceInfo.setAdvertiser_id(params.get("account_id"));
deliveryDeviceInfo.setUuid(UUID.randomUUID().toString());
deliveryDeviceInfo.setAd_platform_type(params.get("ad_platform_type"));
deliveryDeviceInfo.setTarget_audience(params.get("target_audience"));
deliveryDeviceInfo.setIp(params.get("ip"));
if (!filter.contains(params.get("oaid"))) {
deliveryDeviceInfo.setOaid(params.get("oaid"));
}
if (StringUtils.isNotEmpty(clientInfo.getImei())) {
deliveryDeviceInfo.setImeiMd5(clientInfo.getImei());
}
if (StringUtils.isNotEmpty(clientInfo.getPhoneModel())) {
deliveryDeviceInfo.setModel(clientInfo.getPhoneModel());
}
//通投智选union_site
deliveryDeviceInfo.setUnion_site(params.get("union_site"));
deliveryDeviceInfo.setPartId(params.get("part_id"));
//信息流投放广告来源(碎片 1 书籍 2)
deliveryDeviceInfo.setSource(parseInt(params.get("source")));
storyKafkaTemplate.send("growth_ad_click", JSONObject.toJSONString(params));
return new NovelAction(clientInfo,deliveryDeviceInfo); return new NovelAction(clientInfo,deliveryDeviceInfo);
} }
......
package com.lwby.marketing.controller; package com.lwby.marketing.controller;
import cn.hutool.crypto.SecureUtil;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
...@@ -25,4 +26,18 @@ public class ServiceHelper { ...@@ -25,4 +26,18 @@ public class ServiceHelper {
return null; return null;
} }
} }
public String assembleKey(String deviceId, ClickbackService.DeviceType type) {
switch (type) {
case IMEI:
case OAID:
case IDFA:
return deviceId;
case IP_UA:
case IP_MODEL:
case IP:
return SecureUtil.md5(deviceId);
}
return null;
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment