Authored by zhengwen.ge

UPDATE

... ... @@ -4,7 +4,6 @@ package com.yoho.unions.dal;
import com.yoho.unions.dal.model.UnionActivity;
public interface IUnionActivityDAO {
int deleteByPrimaryKey(Long id);
int insert(UnionActivity record);
... ... @@ -12,9 +11,5 @@ public interface IUnionActivityDAO {
UnionActivity selectByPrimaryKey(Long id);
int updateByPrimaryKeySelective(UnionActivity record);
int updateByPrimaryKey(UnionActivity record);
UnionActivity selectByUdid(String udid);
}
\ No newline at end of file
... ...
<?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.model.UnionActivity" >
<resultMap id="BaseResultMap" type="com.yoho.unions.dal.UnionActivity" >
<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="union_type" property="unionType" jdbcType="VARCHAR" />
... ... @@ -23,7 +23,7 @@
delete from union_activity
where id = #{id,jdbcType=BIGINT}
</delete>
<insert id="insert" parameterType="com.yoho.unions.dal.UnionActivity" >
<insert id="insert" parameterType="com.yoho.unions.dal.model.UnionActivity" >
insert into union_activity (id, udid, union_type,
client_type, advertiser_id, click_id,
create_time)
... ... @@ -31,7 +31,7 @@
#{clientType,jdbcType=VARCHAR}, #{advertiserId,jdbcType=VARCHAR}, #{clickId,jdbcType=VARCHAR},
#{createTime,jdbcType=INTEGER})
</insert>
<insert id="insertSelective" parameterType="com.yoho.unions.dal.UnionActivity" >
<insert id="insertSelective" parameterType="com.yoho.unions.dal.model.UnionActivity" >
insert into union_activity
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="id != null" >
... ... @@ -80,38 +80,5 @@
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.yoho.unions.dal.UnionActivity" >
update union_activity
<set >
<if test="udid != null" >
udid = #{udid,jdbcType=VARCHAR},
</if>
<if test="unionType != null" >
union_type = #{unionType,jdbcType=VARCHAR},
</if>
<if test="clientType != null" >
client_type = #{clientType,jdbcType=VARCHAR},
</if>
<if test="advertiserId != null" >
advertiser_id = #{advertiserId,jdbcType=VARCHAR},
</if>
<if test="clickId != null" >
click_id = #{clickId,jdbcType=VARCHAR},
</if>
<if test="createTime != null" >
create_time = #{createTime,jdbcType=INTEGER},
</if>
</set>
where id = #{id,jdbcType=BIGINT}
</update>
<update id="updateByPrimaryKey" parameterType="com.yoho.unions.dal.UnionActivity" >
update union_activity
set udid = #{udid,jdbcType=VARCHAR},
union_type = #{unionType,jdbcType=VARCHAR},
client_type = #{clientType,jdbcType=VARCHAR},
advertiser_id = #{advertiserId,jdbcType=VARCHAR},
click_id = #{clickId,jdbcType=VARCHAR},
create_time = #{createTime,jdbcType=INTEGER}
where id = #{id,jdbcType=BIGINT}
</update>
</mapper>
\ No newline at end of file
... ...
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.unions.vo.OrderInfo;
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;
... ... @@ -14,6 +23,9 @@ 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;
/**
... ... @@ -31,6 +43,9 @@ public class GdtTransTask {
@Resource
IUnionActivityDAO unionActivityDAO;
@Resource
IUnionConfigDAO unionConfigDAO;
@Scheduled(cron = "* 0/3 * * * ?")
public void run() {
UnionOrderReqVO reqVO = new UnionOrderReqVO();
... ... @@ -50,9 +65,124 @@ public class GdtTransTask {
//利用udid去表中查出是两个广点通账号带来的
UnionActivity unionActivity = unionActivityDAO.selectByUdid(udid);
//按照广点通要求拼接数据
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.getUdid();
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;
StringBuffer bf = new StringBuffer();
StringBuffer sf = new StringBuffer();
page = bf.append(url).append(appId).append("/conv?muid=").append(muid4MD5).append("&conv_time=").append(conv_time).append("&value=").append(transInfo.getOrderAmount().multiply(new BigDecimal(100))).toString();
query_string = sf.append("muid=").append(muid4MD5).append("&conv_time=").append(conv_time).append("&value=").append(transInfo.getOrderAmount().multiply(new BigDecimal(100))).toString();
// 对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
private String clientTypeConver(String clientType) {
if (org.apache.commons.lang3.StringUtils.isEmpty(clientType)) {
return null;
}
if (ClientTypeEnum.ANDROID.getName().equalsIgnoreCase(clientType)) {
return clientType.toUpperCase();
} else {
return "IOS";
}
}
}
... ...
package com.test;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.net.URLDecoder;
import java.net.URLEncoder;
... ... @@ -40,20 +41,33 @@ public class Test {
// clientType = requestBO.getClient_type().toLowerCase();
// }
String client_ip = "10.11.12.13";
String appId = "112233";
int conv_time =1422263664;
// 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 = "490655927";
if(clientType.equals(ClientTypeEnum.ANDROID.getName())){
appId = "100898104";
}
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?muid=").append(muid4MD5).append("&conv_time=").append(conv_time).append("&value=").append(new BigDecimal(1).multiply(new BigDecimal(100))).toString();
query_string = sf.append("muid=").append(muid4MD5).append("&conv_time=").append(conv_time).append("&value=").append(transInfo.getOrderAmount().multiply(new BigDecimal(100))).toString();
// 对url进行加密
String encode_page = null;
try {
... ... @@ -84,10 +98,13 @@ 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);
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);
System.out.print(url);
}
... ...