Authored by zhengwen.ge

Merge branch '广点通转化上报'

# Conflicts:
#	web/src/main/resources/databases.yml
#	web/src/main/webapp/META-INF/autoconf/databases.yml
package com.yoho.unions.common.redis;
import com.yoho.core.redis.YHListOperations;
import com.yoho.core.redis.YHRedisTemplate;
import com.yoho.unions.common.utils.SerializeUtils;
import com.yoho.unions.helper.CacheKeyHelper;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
... ... @@ -9,6 +12,9 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Collection;
import java.util.concurrent.TimeUnit;
@Component
public class RedisListCache {
... ... @@ -17,6 +23,8 @@ public class RedisListCache {
@Resource(name="yhListOperations")
YHListOperations<String, String> yhListOperations;
@Resource
YHRedisTemplate<String, String> yHRedisTemplate;
/**
* redis rightPop 操作
... ... @@ -66,4 +74,33 @@ public class RedisListCache {
}
public <T> void rightPushAll(String key,Collection<T> values, long timeout, TimeUnit unit) {
logger.debug("Enter rightPushAll redis list. key is {}, value is {}, timeout is {}, unit is {}", key, values, timeout, unit);
// 如果是空列表,直接返回
if (CollectionUtils.isEmpty(values)) {
return;
}
String cacheKey = key;
// 如果获取的key为空,则说明缓存开关是关闭的
if (StringUtils.isEmpty(cacheKey)) {
return;
}
try {
Collection<String> strValues = new ArrayList<String>();
for (T t : values) {
String strValue = CacheKeyHelper.value2String(t);
if (StringUtils.isEmpty(strValue)) {
continue;
}
strValues.add(strValue);
}
yhListOperations.rightPushAll(cacheKey, strValues);
yHRedisTemplate.longExpire(cacheKey, timeout, unit);
} catch (Exception e) {
logger.warn("rightPushAll redis list operation failed. key is {}", cacheKey, e);
}
}
}
... ...
package com.yoho.unions.vo;
import java.io.Serializable;
import java.math.BigDecimal;
/**
* 转化数据
* Created by yoho on 2017/2/22.
*/
public class TransInfo implements Serializable {
//标示是普通交寄还是首单交寄
private String type;
private BigDecimal orderAmount;
private String udid;
private String uid;
private String ordercode;
public String getUid() {
return uid;
}
public void setUid(String uid) {
this.uid = uid;
}
public String getOrdercode() {
return ordercode;
}
public void setOrdercode(String ordercode) {
this.ordercode = ordercode;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public BigDecimal getOrderAmount() {
return orderAmount;
}
public void setOrderAmount(BigDecimal orderAmount) {
this.orderAmount = orderAmount;
}
public String getUdid() {
return udid;
}
public void setUdid(String udid) {
this.udid = udid;
}
}
... ...
package com.yoho.unions.dal;
import com.yoho.unions.dal.model.UnionActivity;
public interface IUnionActivityDAO {
int insert(UnionActivity record);
int insertSelective(UnionActivity record);
UnionActivity selectByPrimaryKey(Long id);
UnionActivity selectByUdid(String udid);
}
\ No newline at end of file
... ...
//package com.yoho.unions.dal;
//
//
//import com.yoho.unions.dal.model.UnionDepartmentUrl;
//
//public interface IUnionDepartmentUrlDAO {
// int deleteByPrimaryKey(Integer id);
//
// int insert(UnionDepartmentUrl record);
//
// int insertSelective(UnionDepartmentUrl record);
//
// UnionDepartmentUrl selectByPrimaryKey(Integer id);
//
// int updateByPrimaryKeySelective(UnionDepartmentUrl record);
//
// int updateByPrimaryKey(UnionDepartmentUrl record);
//
// UnionDepartmentUrl selectByUnionType(String unionType);
//}
\ No newline at end of file
//package com.yoho.unions.dal;
//
//
//import com.yoho.unions.dal.model.UnionType;
//
//public interface IUnionTypeDAO {
// int deleteByPrimaryKey(Integer id);
//
// int insert(UnionType record);
//
// int insertSelective(UnionType record);
//
// UnionType selectByPrimaryKey(Integer id);
//
// UnionType selectByUnionType(Integer unionType);
//
// int updateByPrimaryKeySelective(UnionType record);
//
// int updateByPrimaryKey(UnionType record);
//}
\ No newline at end of file
package com.yoho.unions.dal.model;
public class UnionActivity {
private Long id;
private String udid;
private String muid;
private String unionType;
private String clientType;
private String advertiserId;
private String clickId;
private Integer createTime;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getUdid() {
return udid;
}
public void setUdid(String udid) {
this.udid = udid == null ? null : udid.trim();
}
public String getMuid() {
return muid;
}
public void setMuid(String muid) {
this.muid = muid == null ? null : muid.trim();
}
public String getUnionType() {
return unionType;
}
public void setUnionType(String unionType) {
this.unionType = unionType == null ? null : unionType.trim();
}
public String getClientType() {
return clientType;
}
public void setClientType(String clientType) {
this.clientType = clientType == null ? null : clientType.trim();
}
public String getAdvertiserId() {
return advertiserId;
}
public void setAdvertiserId(String advertiserId) {
this.advertiserId = advertiserId == null ? null : advertiserId.trim();
}
public String getClickId() {
return clickId;
}
public void setClickId(String clickId) {
this.clickId = clickId == null ? null : clickId.trim();
}
public Integer getCreateTime() {
return createTime;
}
public void setCreateTime(Integer createTime) {
this.createTime = createTime;
}
}
\ No newline at end of file
... ...
package com.yoho.unions.dal.model;
import java.math.BigDecimal;
/**
* Created by yoho on 2017/2/22.
*/
public class UnionActivityTrans {
//订单金额
private BigDecimal order_amount;
//设备号
private String udid;
private String uid;
private String order_code;
public String getUid() {
return uid;
}
public void setUid(String uid) {
this.uid = uid;
}
public String getUdid() {
return udid;
}
public void setUdid(String udid) {
this.udid = udid;
}
public BigDecimal getOrder_amount() {
return order_amount;
}
public void setOrder_amount(BigDecimal order_amount) {
this.order_amount = order_amount;
}
public String getOrder_code() {
return order_code;
}
public void setOrder_code(String order_code) {
this.order_code = order_code;
}
}
... ...
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.yoho.unions.dal.IUnionActivityDAO" >
<resultMap id="BaseResultMap" type="com.yoho.unions.dal.model.UnionActivity" >
<id column="id" property="id" jdbcType="BIGINT" />
<result column="udid" property="udid" jdbcType="VARCHAR" />
<result column="muid" property="muid" jdbcType="VARCHAR" />
<result column="union_type" property="unionType" jdbcType="VARCHAR" />
<result column="client_type" property="clientType" jdbcType="VARCHAR" />
<result column="advertiser_id" property="advertiserId" jdbcType="VARCHAR" />
<result column="click_id" property="clickId" jdbcType="VARCHAR" />
<result column="create_time" property="createTime" jdbcType="INTEGER" />
</resultMap>
<sql id="Base_Column_List" >
id, udid, muid, union_type, client_type, advertiser_id, click_id, create_time
</sql>
<select id="selectByUdid" resultMap="BaseResultMap">
select <include refid="Base_Column_List" />
from union_activity
where udid = #{udid} limit 1
</select>
<insert id="insert" parameterType="com.yoho.unions.dal.model.UnionActivity" >
insert into union_activity (id, udid, muid,
union_type, client_type, advertiser_id,
click_id, create_time)
values (#{id,jdbcType=BIGINT}, #{udid,jdbcType=VARCHAR}, #{muid,jdbcType=VARCHAR},
#{unionType,jdbcType=VARCHAR}, #{clientType,jdbcType=VARCHAR}, #{advertiserId,jdbcType=VARCHAR},
#{clickId,jdbcType=VARCHAR}, #{createTime,jdbcType=INTEGER})
</insert>
<insert id="insertSelective" parameterType="com.yoho.unions.dal.model.UnionActivity" >
insert into union_activity
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="id != null" >
id,
</if>
<if test="udid != null" >
udid,
</if>
<if test="muid != null" >
muid,
</if>
<if test="unionType != null" >
union_type,
</if>
<if test="clientType != null" >
client_type,
</if>
<if test="advertiserId != null" >
advertiser_id,
</if>
<if test="clickId != null" >
click_id,
</if>
<if test="createTime != null" >
create_time,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="id != null" >
#{id,jdbcType=BIGINT},
</if>
<if test="udid != null" >
#{udid,jdbcType=VARCHAR},
</if>
<if test="muid != null" >
#{muid,jdbcType=VARCHAR},
</if>
<if test="unionType != null" >
#{unionType,jdbcType=VARCHAR},
</if>
<if test="clientType != null" >
#{clientType,jdbcType=VARCHAR},
</if>
<if test="advertiserId != null" >
#{advertiserId,jdbcType=VARCHAR},
</if>
<if test="clickId != null" >
#{clickId,jdbcType=VARCHAR},
</if>
<if test="createTime != null" >
#{createTime,jdbcType=INTEGER},
</if>
</trim>
</insert>
</mapper>
\ No newline at end of file
... ...
package com.yoho.unions.server.service;
import com.yoho.unions.vo.OrderInfo;
import com.yoho.unions.vo.TransInfo;
import com.yoho.unions.vo.UnionOrderReqVO;
import java.util.List;
... ... @@ -9,4 +10,6 @@ public interface IUnionOrderService {
public List<OrderInfo> getUnionOrders(UnionOrderReqVO req);
public List<TransInfo> getTrandInfo(UnionOrderReqVO req);
}
... ...
package com.yoho.unions.server.service.impl;
import com.yoho.service.model.union.UnionTrans;
import com.yoho.unions.common.redis.RedisHashCache;
import com.yoho.unions.common.redis.RedisListCache;
import com.yoho.unions.dal.model.UnionActivityTrans;
import com.yoho.unions.dal.model.UnionOrders;
import com.yoho.unions.dal.model.UnionOrdersGoods;
import com.yoho.unions.server.service.IUnionOrderService;
import com.yoho.unions.vo.OrderInfo;
import com.yoho.unions.vo.OrdersGood;
import com.yoho.unions.vo.TransInfo;
import com.yoho.unions.vo.UnionOrderReqVO;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
... ... @@ -26,8 +29,14 @@ public class UnionOrderServiceImpl implements IUnionOrderService {
private static final String UNION_ORDER_KEY = "union:orders";
private static final String UNION_TRAND = "YH:BD:ORDER:UNIONS";
private static final String UNION_ORDER_GOODS_KEY_PRE = "union:order_goods:";
private static final String UNION_TRANS_UNIONTYPE = "YH:BD:UNI:1:ORDER:";
private static final String UNION_NORMAL_TRANS_UNIONTYPE = "YH:BD:UNI:ALL:ORDER:";
@Autowired
private RedisListCache redisListCache;
... ... @@ -67,6 +76,52 @@ public class UnionOrderServiceImpl implements IUnionOrderService {
}
}
@Override
public List<TransInfo> getTrandInfo(UnionOrderReqVO req) {
logger.info("Enter getTrandInfo: request param is {}", req);
try {
List<TransInfo> resList = new ArrayList<TransInfo>();
Long size = redisListCache.size(UNION_TRAND);
int sizeInt = size == null ? 0 : size.intValue();
if (sizeInt > 0) {
for (int i = 0; i < size; i++) {
UnionTrans unionTrans = redisListCache.rightPop(UNION_TRAND, UnionTrans.class);
String union_type = unionTrans.getUnion_type();
//首单交寄
String firstOrder = UNION_TRANS_UNIONTYPE + union_type;
//普通交寄
String normalOrder = UNION_NORMAL_TRANS_UNIONTYPE + union_type;
List<UnionActivityTrans> firstOrderList = new ArrayList<>();
Long firstOrderSize = redisListCache.size(firstOrder);
Long normalOrderSize = redisListCache.size(normalOrder);
if (firstOrderSize > 0) {
for (int j = 0; j < firstOrderSize; j++) {
UnionActivityTrans unionActivityTrans = redisListCache.rightPop(firstOrder, UnionActivityTrans.class);
firstOrderList.add(unionActivityTrans);
}
}
logger.info("getFirstOrderList: from bigdata redis: key is {}, result size is {}", firstOrder, firstOrderList == null ? 0 : firstOrderList.size());
List<UnionActivityTrans> normalOrderList = new ArrayList<>();
if (normalOrderSize > 0) {
for (int k = 0; k < normalOrderSize; k++) {
UnionActivityTrans unionActivityTrans = redisListCache.rightPop(normalOrder, UnionActivityTrans.class);
normalOrderList.add(unionActivityTrans);
}
}
logger.info("getNormalOrderList: from bigdata redis: key is {}, result size is {}", normalOrder, normalOrderList == null ? 0 : normalOrderList.size());
resList = this.convertTrans(resList,firstOrderList, normalOrderList);
}
}
return resList;
} catch (Exception e) {
logger.warn("getUnionOrders: get orders from bigdata redis failed, error is {}", e);
return null;
}
}
private OrderInfo convertToUnionOrderBo(UnionOrders unionOrder){
if(null == unionOrder){
return null;
... ... @@ -114,4 +169,35 @@ public class UnionOrderServiceImpl implements IUnionOrderService {
return resList;
}
private List<TransInfo> convertTrans(List<TransInfo> resList,List<UnionActivityTrans> firstOrderList,List<UnionActivityTrans> normalOrderList){
if(CollectionUtils.isEmpty(firstOrderList)&&CollectionUtils.isEmpty(normalOrderList)){
return null;
}
if(CollectionUtils.isNotEmpty(firstOrderList)){
for(UnionActivityTrans unionActivityTrans:firstOrderList){
TransInfo transInfo = new TransInfo();
//首单设为1
transInfo.setType("1");
transInfo.setUdid(unionActivityTrans.getUdid());
transInfo.setOrderAmount(unionActivityTrans.getOrder_amount());
transInfo.setUid(unionActivityTrans.getUid());
transInfo.setOrdercode(unionActivityTrans.getOrder_code());
resList.add(transInfo);
}
}
if(CollectionUtils.isNotEmpty(normalOrderList)){
for(UnionActivityTrans unionActivityTran:normalOrderList){
TransInfo transInfo = new TransInfo();
//正常单设为2
transInfo.setType("2");
transInfo.setUdid(unionActivityTran.getUdid());
transInfo.setOrderAmount(unionActivityTran.getOrder_amount());
transInfo.setUid(unionActivityTran.getUid());
transInfo.setOrdercode(unionActivityTran.getOrder_code());
resList.add(transInfo);
}
}
return resList;
}
}
... ...
... ... @@ -19,6 +19,7 @@ import com.yoho.service.model.union.request.ActivateUnionRequestBO;
import com.yoho.service.model.union.request.ClickUnionRequestBO;
import com.yoho.service.model.union.response.UnionResponse;
import com.yoho.unions.common.enums.ClientTypeEnum;
import com.yoho.unions.common.redis.RedisListCache;
import com.yoho.unions.common.redis.RedisValueCache;
import com.yoho.unions.common.utils.DateUtil;
import com.yoho.unions.common.utils.HttpUtils;
... ... @@ -34,6 +35,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.net.URLDecoder;
import java.util.List;
... ... @@ -70,7 +72,7 @@ public class UnionServiceImpl implements IUnionService,ApplicationEventPublisher
@Resource(name="yhValueOperations")
YHValueOperations<String, String> yhValueOperations;
@Resource
IUnionLogsDAO unionLogsDAO;
... ... @@ -84,6 +86,9 @@ public class UnionServiceImpl implements IUnionService,ApplicationEventPublisher
RedisValueCache redisValueCache;
@Resource
RedisListCache redisListCache;
@Resource
IMktMarketingUrlDAO mktMarketingUrlDAO;
@Resource
... ... @@ -93,6 +98,9 @@ public class UnionServiceImpl implements IUnionService,ApplicationEventPublisher
IUnionActivityLogsDAO unionActivityLogsDAO;
@Resource
IUnionActivityDAO unionActivityDAO;
@Resource
IUnionTypeMatchDAO unionTypeMatchDAO;
@Resource(name="unionServiceImpl")
... ... @@ -182,25 +190,18 @@ public class UnionServiceImpl implements IUnionService,ApplicationEventPublisher
yhValueOperations.set(key, JSON.toJSONString(request));
yHRedisTemplate.longExpire(key, activeTime.get(), TimeUnit.HOURS);
clickUnion.info("clickUnion set redis second success. with key={}, value={}", key, JSON.toJSONString(request));
// log.info("clickUnion set redis success with request={}", request);
// if (union != null) {
// //如果90天以内,已经存在点击记录,则不需要插入或更新数据库
// log.info("clickUnion have click in 90 days with request={}", request);
// return new UnionResponse();
// UnionActivityTrans unionActivityTrans = new UnionActivityTrans();
// List<UnionActivityTrans> list = new ArrayList<>();
// for(int i=0;i<3;i++){
// UnionActivityTrans unionActivityTrans = new UnionActivityTrans();
// unionActivityTrans.setOrdercode("123");
// unionActivityTrans.setUdid("234");
// unionActivityTrans.setOrderAmount(new BigDecimal(12));
// unionActivityTrans.setUid("12");
// list.add(unionActivityTrans);
// }
//保存信息到数据库
// UnionLogs logs = new UnionLogs();
// logs.setTd(request.getTd());
// logs.setAppId(request.getAppid());
// logs.setClientType(request.getClient_type());
// logs.setUnionType(Byte.valueOf(request.getUnion_type()));
// logs.setCreateTime(DateUtil.getCurrentTimeSecond());
// logs.setUpdateTime(logs.getCreateTime());
// logs.setAddParams(JSON.toJSONString(request));
// logs.setIsActivate(Byte.valueOf("0"));
// unionLogsDAO.insert(logs);
// redisListCache.rightPushAll("UNION:KEY:123",list,activeTime.get(),TimeUnit.HOURS);
return new UnionResponse();
} catch (Exception e) {
... ... @@ -507,12 +508,17 @@ public class UnionServiceImpl implements IUnionService,ApplicationEventPublisher
log.warn("callback error with request={}", request);
return new UnionResponse(204, "callback error");
}
//如果来源是广点通,则把广点通的一些信息记入表,给之后做转化上报使用
if(union_type.equals("3")){
saveUnionActivity(click,request);
}
} catch (Exception e) {
log.error("callback error with request={}", request, e);
//return new UnionResponse(204, "callback error");
}
activeUnion.info("activateUnion in success request is {}", request);
return new UnionResponse();
... ... @@ -565,6 +571,30 @@ public class UnionServiceImpl implements IUnionService,ApplicationEventPublisher
});
}
private void saveUnionActivity(ClickUnionRequestBO click,ActivateUnionRequestBO request){
taskExecutor.execute(new Runnable(){
@Override
public void run()
{
UnionActivity unionActivity = new UnionActivity();
unionActivity.setClientType(request.getClient_type());
unionActivity.setUdid(request.getUdid());
if(StringUtils.isNotEmpty(click.getIdfa())){
unionActivity.setUdid(click.getIdfa());
}else {
unionActivity.setUdid(click.getImei());
}
unionActivity.setUnionType(click.getUnion_type());
//广点通的账号id存入的是click的commonUse字段
unionActivity.setAdvertiserId(click.getCommonUse());
//广点通点击id
unionActivity.setClickId(click.getClickId());
unionActivity.setCreateTime(DateUtil.getCurrentTimeSecond());
unionActivityDAO.insertSelective(unionActivity);
}
});
}
@Override
public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
this.publisher = applicationEventPublisher;
... ...
package com.yoho.unions.server.task;
import com.yoho.service.model.union.response.UnionResponse;
import com.yoho.unions.common.enums.ClientTypeEnum;
import com.yoho.unions.common.utils.DateUtil;
import com.yoho.unions.common.utils.HttpUtils;
import com.yoho.unions.dal.IUnionActivityDAO;
import com.yoho.unions.dal.IUnionConfigDAO;
import com.yoho.unions.dal.model.UnionActivity;
import com.yoho.unions.dal.model.UnionConfig;
import com.yoho.unions.server.service.IUnionOrderService;
import com.yoho.core.common.utils.MD5;
import org.apache.commons.codec.binary.Base64;
import com.yoho.unions.vo.TransInfo;
import com.yoho.unions.vo.UnionOrderReqVO;
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.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.net.URLEncoder;
import java.util.List;
/**
* 广点通转化数据上报,定时从大数据抽取数据,然后联盟拼接,上报给广点通
* Created by yoho on 2017/2/22.
*/
@Component
public class GdtTransTask {
static Logger log = LoggerFactory.getLogger(GdtTransTask.class);
@Autowired
private IUnionOrderService unionOrderService;
@Resource
IUnionActivityDAO unionActivityDAO;
@Resource
IUnionConfigDAO unionConfigDAO;
@Scheduled(cron = "* 0/5 * * * ?")
public void run() {
UnionOrderReqVO reqVO = new UnionOrderReqVO();
reqVO.setLimit(20);
this.execute(reqVO);
}
public void execute(UnionOrderReqVO reqVO){
//从大数据中取出联盟需要的广点通带来转化的设备号,和金额
List<TransInfo> transInfoList = unionOrderService.getTrandInfo(reqVO);
if (CollectionUtils.isEmpty(transInfoList)) {
return;
}
//将取出来的数据进行拼接
for(TransInfo transInfo:transInfoList){
log.info("enter trans udid is {},ordercode is {}",transInfo.getUdid(),transInfo.getOrdercode());
String udid = transInfo.getUdid();
//利用udid去表中查出是两个广点通账号带来的
UnionActivity unionActivity = unionActivityDAO.selectByUdid(udid);
if(unionActivity==null){
return;
}
//按照广点通要求拼接数据
String url = urlEode(unionActivity,transInfo);
//改成httpclient方式调用
Pair<Integer, String> pair = HttpUtils.httpGet(url);
log.info("GdtTransTask call union success url={}, and result={}", url, pair);
if (pair.getLeft() != 200) {
log.warn("callback error with request={}", url);
}
}
}
public String urlEode(UnionActivity requestBO,TransInfo transInfo) {
log.info("enter GdtTransTask.urlEode requestBO is {}, transInfo is {} ", requestBO,transInfo);
// 根据不同的应用类型,获取不同的加密密钥和签名密钥
String encryptKey = "BAAAAAAAAAAABZJQ";
String signKey = "1461f1237d22dfc7";
String muid4MD5 = requestBO.getMuid();
String url = "http://t.gdt.qq.com/conv/app/";
//有货在智慧推的账号id
String uid = "365136";
if(StringUtils.isNotEmpty(requestBO.getAdvertiserId())){
uid = requestBO.getAdvertiserId();
}
String clientType = ClientTypeEnum.IOS.getName();
if(StringUtils.isNotEmpty(requestBO.getClientType())){
clientType = requestBO.getClientType().toLowerCase();
}
UnionConfig unionConfig = unionConfigDAO.selectByUidAndClientType(Integer.valueOf(uid),clientType);
if(null!=unionConfig){
encryptKey = unionConfig.getEncryptKey();
signKey = unionConfig.getSignKey();
url = unionConfig.getUrl();
}
//APPID可以固定根据clientType判断
String appId = "490655927";
if(clientType.equals(ClientTypeEnum.ANDROID.getName())){
appId = "100898104";
}
int conv_time = DateUtil.getCurrentTimeSecond();
String page = null;
String query_string = null;
String clickId = requestBO.getClickId();
StringBuffer bf = new StringBuffer();
StringBuffer sf = new StringBuffer();
page = bf.append(url).append(appId).append("/conv?click_id=").append(clickId).append("&muid=").append(muid4MD5).append("&conv_time=").append(conv_time).append("&value=").append(transInfo.getOrderAmount().multiply(new BigDecimal(100))).toString();
query_string = sf.append("click_id=").append(clickId).append("&muid=").append(muid4MD5).append("&conv_time=").append(conv_time).append("&value=").append(transInfo.getOrderAmount().multiply(new BigDecimal(100))).toString();
log.info("enter GdtTransTask.urlEode page is {}",page);
log.info("enter GdtTransTask.urlEode query_string is {}",query_string);
// 对url进行加密
String encode_page = null;
try {
encode_page = URLEncoder.encode(page, "UTF-8");
log.info("activateZhiHuitui urlEncoder is{} ", encode_page);
} catch (UnsupportedEncodingException e) {
log.error("encode exception.", e);
}
// 将签名密钥和提交方式与加密后的url进行拼接
StringBuffer urlBuffer = new StringBuffer();
String property = urlBuffer.append(signKey).append("&GET&").append(encode_page).toString();
String signature = MD5.md5(property);
StringBuffer base = new StringBuffer();
String base_data = base.append(query_string).append("&sign=").append(signature).toString();
// 简单异或处理
String data = simpleXorByGdt(base_data, encryptKey);
// base64编码
String ret = Base64.encodeBase64String(data.getBytes());
// 64位处理之后,防止里面有换行符
String retRep = ret.replaceAll("\n", "");
// 将64位处理之后的值,按照url加密的方式进行加密
try {
retRep = URLEncoder.encode(retRep, "UTF-8");
log.info("activateUnion retRep is{}", retRep);
} catch (UnsupportedEncodingException e) {
log.error("encode exception.", e);
}
// conv_type,,现在只有移动应用激活类型(MOBILEAPP_ACTIVITE);
String convType = "MOBILEAPP_COST";
if(transInfo.getType().equals("1")){
convType = "MOBILEAPP_ADDTOCART";
}
StringBuffer sb = new StringBuffer();
url = sb.append(url).append(appId).append("/conv?v=").append(retRep).append("&conv_type=").append(convType).append("&app_type=").append(clientTypeConver(clientType)).append("&advertiser_id=").append(uid).toString();
log.info("GdtTransTask url is {}", url);
return url;
}
/**
* 简单异或
*
* @param source
* @param key
* @return
*/
private String simpleXorByGdt(String source, String key) {
String result = "";
int j = 0;
for (int i = 0; i < source.length(); i++) {
int c1 = source.charAt(i);
int c2 = key.charAt(j);
result = result + (char) (c1 ^ c2);
j = j + 1;
j = j % (key.length());
}
return result;
}
private String clientTypeConver(String clientType) {
if (StringUtils.isEmpty(clientType)) {
return null;
}
if (ClientTypeEnum.ANDROID.getName().equalsIgnoreCase(clientType)) {
return clientType.toUpperCase();
} else {
return "IOS";
}
}
}
... ...
... ... @@ -42,6 +42,7 @@ datasources:
- com.yoho.unions.dal.IUnionTypeMatchDAO
- com.yoho.unions.dal.ITencentMktActivityDAO
- com.yoho.unions.dal.ITencentMktCouponHistoryDAO
- com.yoho.unions.dal.IUnionActivityDAO
- com.yoho.unions.dal.IUnionConfigDAO
readOnlyInSlave: true
\ No newline at end of file
... ...
... ... @@ -43,6 +43,7 @@ datasources:
- com.yoho.unions.dal.IUnionTypeMatchDAO
- com.yoho.unions.dal.ITencentMktActivityDAO
- com.yoho.unions.dal.ITencentMktCouponHistoryDAO
- com.yoho.unions.dal.IUnionActivityDAO
- com.yoho.unions.dal.IUnionConfigDAO
readOnlyInSlave: true
\ No newline at end of file
... ...
package com.test;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.net.URLDecoder;
import java.net.URLEncoder;
... ... @@ -30,7 +31,7 @@ public class Test {
String encryptKey = "test_encrypt_key";
String signKey = "test_sign_key";
String muid4MD5 = "0f074dc8e1f0547310e729032ac0730b";
String url = "http://jump.t.l.qq.com/conv/app/";
String url = "http://t.gdt.qq.com/conv/app/";
//有货在智慧推的账号id
String uid = "18261";
... ... @@ -40,20 +41,33 @@ public class Test {
// clientType = requestBO.getClient_type().toLowerCase();
// }
String client_ip = "10.11.12.13";
// if(org.apache.commons.lang.StringUtils.isNotEmpty(requestBO.getAdvertiserId())){
// uid = requestBO.getAdvertiserId();
// }
// String clientType = ClientTypeEnum.IOS.getName();
// if(org.apache.commons.lang.StringUtils.isNotEmpty(requestBO.getClientType())){
// clientType = requestBO.getClientType().toLowerCase();
// }
// UnionConfig unionConfig = unionConfigDAO.selectByUidAndClientType(Integer.valueOf(uid),clientType);
// if(null!=unionConfig){
// encryptKey = unionConfig.getEncryptKey();
// signKey = unionConfig.getSignKey();
// url = unionConfig.getUrl();
// }
//APPID可以固定根据clientType判断
String appId = "112233";
int conv_time =1422263664;
if(clientType.equals(ClientTypeEnum.ANDROID.getName())){
appId = "112233";
}
int conv_time = DateUtil.getCurrentTimeSecond();
String page = null;
String query_string = null;
StringBuffer bf = new StringBuffer();
StringBuffer sf = new StringBuffer();
if (StringUtils.isEmpty(client_ip)){
page = bf.append(url).append(appId).append("/conv?muid=").append(muid4MD5).append("&conv_time=").append(conv_time).toString();
query_string = sf.append("muid=").append(muid4MD5).append("&conv_time=").append(conv_time).toString();
}else{
page = bf.append(url).append(appId).append("/conv?muid=").append(muid4MD5).append("&conv_time=").append(conv_time).append("&client_ip=").append(client_ip).toString();
query_string = sf.append("muid=").append(muid4MD5).append("&conv_time=").append(conv_time).append("&client_ip=").append(client_ip).toString();
}
page = bf.append(url).append(appId).append("/conv?click_id=").append("007210548a030059ccdfd1d4").append("&muid=").append(muid4MD5).append("&conv_time=").append(conv_time).append("&client_ip=10.11.12.13").toString();
query_string = sf.append("click_id=").append("007210548a030059ccdfd1d4").append("&muid=").append(muid4MD5).append("&conv_time=").append(conv_time).append("&client_ip=10.11.12.13").toString();
// 对url进行加密
String encode_page = null;
try {
... ... @@ -84,11 +98,15 @@ public class Test {
log.error("encode exception.", e);
}
// conv_type,,现在只有移动应用激活类型(MOBILEAPP_ACTIVITE);
String convType = "MOBILE_APP_ACTIVITE";
String convType = "MOBILEAPP_COST";
// if(transInfo.getType().equals("1")){
// convType = "MOBILEAPP_ADDTOCART";
// }
StringBuffer sb = new StringBuffer();
url = sb.append(url).append(112233).append("/conv?v=").append(retRep).append("&conv_type=").append(convType).append("&app_type=").append(clientTypeConver("Android")).append("&advertiser_id=").append(uid).toString();
log.info("zhihuitui url is {}", url);
System.out.print(url);
url = sb.append(url).append(appId).append("/conv?v=").append(retRep).append("&conv_type=").append(convType).append("&app_type=").append(clientTypeConver(clientType)).append("&advertiser_id=").append(uid).toString();
log.info("GdtTransTask url is {}", url);
String md5 = MD5.md5("862380036648114");
System.out.print(md5);
}
private static String clientTypeConver(String clientType) {
... ...