Showing
4 changed files
with
167 additions
and
58 deletions
@@ -4,7 +4,6 @@ package com.yoho.unions.dal; | @@ -4,7 +4,6 @@ package com.yoho.unions.dal; | ||
4 | import com.yoho.unions.dal.model.UnionActivity; | 4 | import com.yoho.unions.dal.model.UnionActivity; |
5 | 5 | ||
6 | public interface IUnionActivityDAO { | 6 | public interface IUnionActivityDAO { |
7 | - int deleteByPrimaryKey(Long id); | ||
8 | 7 | ||
9 | int insert(UnionActivity record); | 8 | int insert(UnionActivity record); |
10 | 9 | ||
@@ -12,9 +11,5 @@ public interface IUnionActivityDAO { | @@ -12,9 +11,5 @@ public interface IUnionActivityDAO { | ||
12 | 11 | ||
13 | UnionActivity selectByPrimaryKey(Long id); | 12 | UnionActivity selectByPrimaryKey(Long id); |
14 | 13 | ||
15 | - int updateByPrimaryKeySelective(UnionActivity record); | ||
16 | - | ||
17 | - int updateByPrimaryKey(UnionActivity record); | ||
18 | - | ||
19 | UnionActivity selectByUdid(String udid); | 14 | UnionActivity selectByUdid(String udid); |
20 | } | 15 | } |
1 | <?xml version="1.0" encoding="UTF-8" ?> | 1 | <?xml version="1.0" encoding="UTF-8" ?> |
2 | <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" > | 2 | <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" > |
3 | -<mapper namespace="com.yoho.unions.dal.model.UnionActivity" > | ||
4 | - <resultMap id="BaseResultMap" type="com.yoho.unions.dal.UnionActivity" > | 3 | +<mapper namespace="com.yoho.unions.dal.IUnionActivityDAO" > |
4 | + <resultMap id="BaseResultMap" type="com.yoho.unions.dal.model.UnionActivity" > | ||
5 | <id column="id" property="id" jdbcType="BIGINT" /> | 5 | <id column="id" property="id" jdbcType="BIGINT" /> |
6 | <result column="udid" property="udid" jdbcType="VARCHAR" /> | 6 | <result column="udid" property="udid" jdbcType="VARCHAR" /> |
7 | <result column="union_type" property="unionType" jdbcType="VARCHAR" /> | 7 | <result column="union_type" property="unionType" jdbcType="VARCHAR" /> |
@@ -23,7 +23,7 @@ | @@ -23,7 +23,7 @@ | ||
23 | delete from union_activity | 23 | delete from union_activity |
24 | where id = #{id,jdbcType=BIGINT} | 24 | where id = #{id,jdbcType=BIGINT} |
25 | </delete> | 25 | </delete> |
26 | - <insert id="insert" parameterType="com.yoho.unions.dal.UnionActivity" > | 26 | + <insert id="insert" parameterType="com.yoho.unions.dal.model.UnionActivity" > |
27 | insert into union_activity (id, udid, union_type, | 27 | insert into union_activity (id, udid, union_type, |
28 | client_type, advertiser_id, click_id, | 28 | client_type, advertiser_id, click_id, |
29 | create_time) | 29 | create_time) |
@@ -31,7 +31,7 @@ | @@ -31,7 +31,7 @@ | ||
31 | #{clientType,jdbcType=VARCHAR}, #{advertiserId,jdbcType=VARCHAR}, #{clickId,jdbcType=VARCHAR}, | 31 | #{clientType,jdbcType=VARCHAR}, #{advertiserId,jdbcType=VARCHAR}, #{clickId,jdbcType=VARCHAR}, |
32 | #{createTime,jdbcType=INTEGER}) | 32 | #{createTime,jdbcType=INTEGER}) |
33 | </insert> | 33 | </insert> |
34 | - <insert id="insertSelective" parameterType="com.yoho.unions.dal.UnionActivity" > | 34 | + <insert id="insertSelective" parameterType="com.yoho.unions.dal.model.UnionActivity" > |
35 | insert into union_activity | 35 | insert into union_activity |
36 | <trim prefix="(" suffix=")" suffixOverrides="," > | 36 | <trim prefix="(" suffix=")" suffixOverrides="," > |
37 | <if test="id != null" > | 37 | <if test="id != null" > |
@@ -80,38 +80,5 @@ | @@ -80,38 +80,5 @@ | ||
80 | </if> | 80 | </if> |
81 | </trim> | 81 | </trim> |
82 | </insert> | 82 | </insert> |
83 | - <update id="updateByPrimaryKeySelective" parameterType="com.yoho.unions.dal.UnionActivity" > | ||
84 | - update union_activity | ||
85 | - <set > | ||
86 | - <if test="udid != null" > | ||
87 | - udid = #{udid,jdbcType=VARCHAR}, | ||
88 | - </if> | ||
89 | - <if test="unionType != null" > | ||
90 | - union_type = #{unionType,jdbcType=VARCHAR}, | ||
91 | - </if> | ||
92 | - <if test="clientType != null" > | ||
93 | - client_type = #{clientType,jdbcType=VARCHAR}, | ||
94 | - </if> | ||
95 | - <if test="advertiserId != null" > | ||
96 | - advertiser_id = #{advertiserId,jdbcType=VARCHAR}, | ||
97 | - </if> | ||
98 | - <if test="clickId != null" > | ||
99 | - click_id = #{clickId,jdbcType=VARCHAR}, | ||
100 | - </if> | ||
101 | - <if test="createTime != null" > | ||
102 | - create_time = #{createTime,jdbcType=INTEGER}, | ||
103 | - </if> | ||
104 | - </set> | ||
105 | - where id = #{id,jdbcType=BIGINT} | ||
106 | - </update> | ||
107 | - <update id="updateByPrimaryKey" parameterType="com.yoho.unions.dal.UnionActivity" > | ||
108 | - update union_activity | ||
109 | - set udid = #{udid,jdbcType=VARCHAR}, | ||
110 | - union_type = #{unionType,jdbcType=VARCHAR}, | ||
111 | - client_type = #{clientType,jdbcType=VARCHAR}, | ||
112 | - advertiser_id = #{advertiserId,jdbcType=VARCHAR}, | ||
113 | - click_id = #{clickId,jdbcType=VARCHAR}, | ||
114 | - create_time = #{createTime,jdbcType=INTEGER} | ||
115 | - where id = #{id,jdbcType=BIGINT} | ||
116 | - </update> | 83 | + |
117 | </mapper> | 84 | </mapper> |
1 | package com.yoho.unions.server.task; | 1 | package com.yoho.unions.server.task; |
2 | 2 | ||
3 | +import com.yoho.service.model.union.response.UnionResponse; | ||
4 | +import com.yoho.unions.common.enums.ClientTypeEnum; | ||
5 | +import com.yoho.unions.common.utils.DateUtil; | ||
6 | +import com.yoho.unions.common.utils.HttpUtils; | ||
3 | import com.yoho.unions.dal.IUnionActivityDAO; | 7 | import com.yoho.unions.dal.IUnionActivityDAO; |
8 | +import com.yoho.unions.dal.IUnionConfigDAO; | ||
4 | import com.yoho.unions.dal.model.UnionActivity; | 9 | import com.yoho.unions.dal.model.UnionActivity; |
10 | +import com.yoho.unions.dal.model.UnionConfig; | ||
5 | import com.yoho.unions.server.service.IUnionOrderService; | 11 | import com.yoho.unions.server.service.IUnionOrderService; |
6 | -import com.yoho.unions.vo.OrderInfo; | 12 | +import com.yoho.core.common.utils.MD5; |
13 | +import org.apache.commons.codec.binary.Base64; | ||
7 | import com.yoho.unions.vo.TransInfo; | 14 | import com.yoho.unions.vo.TransInfo; |
8 | import com.yoho.unions.vo.UnionOrderReqVO; | 15 | import com.yoho.unions.vo.UnionOrderReqVO; |
9 | import org.apache.commons.collections.CollectionUtils; | 16 | import org.apache.commons.collections.CollectionUtils; |
17 | +import org.apache.commons.lang.StringUtils; | ||
18 | +import org.apache.commons.lang3.tuple.Pair; | ||
10 | import org.slf4j.Logger; | 19 | import org.slf4j.Logger; |
11 | import org.slf4j.LoggerFactory; | 20 | import org.slf4j.LoggerFactory; |
12 | import org.springframework.beans.factory.annotation.Autowired; | 21 | import org.springframework.beans.factory.annotation.Autowired; |
@@ -14,6 +23,9 @@ import org.springframework.scheduling.annotation.Scheduled; | @@ -14,6 +23,9 @@ import org.springframework.scheduling.annotation.Scheduled; | ||
14 | import org.springframework.stereotype.Component; | 23 | import org.springframework.stereotype.Component; |
15 | 24 | ||
16 | import javax.annotation.Resource; | 25 | import javax.annotation.Resource; |
26 | +import java.io.UnsupportedEncodingException; | ||
27 | +import java.math.BigDecimal; | ||
28 | +import java.net.URLEncoder; | ||
17 | import java.util.List; | 29 | import java.util.List; |
18 | 30 | ||
19 | /** | 31 | /** |
@@ -31,6 +43,9 @@ public class GdtTransTask { | @@ -31,6 +43,9 @@ public class GdtTransTask { | ||
31 | @Resource | 43 | @Resource |
32 | IUnionActivityDAO unionActivityDAO; | 44 | IUnionActivityDAO unionActivityDAO; |
33 | 45 | ||
46 | + @Resource | ||
47 | + IUnionConfigDAO unionConfigDAO; | ||
48 | + | ||
34 | @Scheduled(cron = "* 0/3 * * * ?") | 49 | @Scheduled(cron = "* 0/3 * * * ?") |
35 | public void run() { | 50 | public void run() { |
36 | UnionOrderReqVO reqVO = new UnionOrderReqVO(); | 51 | UnionOrderReqVO reqVO = new UnionOrderReqVO(); |
@@ -50,9 +65,124 @@ public class GdtTransTask { | @@ -50,9 +65,124 @@ public class GdtTransTask { | ||
50 | //利用udid去表中查出是两个广点通账号带来的 | 65 | //利用udid去表中查出是两个广点通账号带来的 |
51 | UnionActivity unionActivity = unionActivityDAO.selectByUdid(udid); | 66 | UnionActivity unionActivity = unionActivityDAO.selectByUdid(udid); |
52 | //按照广点通要求拼接数据 | 67 | //按照广点通要求拼接数据 |
68 | + String url = urlEode(unionActivity,transInfo); | ||
69 | + //改成httpclient方式调用 | ||
70 | + Pair<Integer, String> pair = HttpUtils.httpGet(url); | ||
71 | + log.info("GdtTransTask call union success url={}, and result={}", url, pair); | ||
72 | + if (pair.getLeft() != 200) { | ||
73 | + log.warn("callback error with request={}", url); | ||
74 | + } | ||
75 | + | ||
76 | + } | ||
77 | + } | ||
78 | + | ||
79 | + public String urlEode(UnionActivity requestBO,TransInfo transInfo) { | ||
80 | + log.info("enter GdtTransTask.urlEode requestBO is {}, transInfo is {} ", requestBO,transInfo); | ||
81 | + // 根据不同的应用类型,获取不同的加密密钥和签名密钥 | ||
82 | + String encryptKey = "BAAAAAAAAAAABZJQ"; | ||
83 | + String signKey = "1461f1237d22dfc7"; | ||
84 | + String muid4MD5 = requestBO.getUdid(); | ||
85 | + String url = "http://t.gdt.qq.com/conv/app/"; | ||
86 | + //有货在智慧推的账号id | ||
87 | + String uid = "365136"; | ||
88 | + if(StringUtils.isNotEmpty(requestBO.getAdvertiserId())){ | ||
89 | + uid = requestBO.getAdvertiserId(); | ||
90 | + } | ||
91 | + String clientType = ClientTypeEnum.IOS.getName(); | ||
92 | + if(StringUtils.isNotEmpty(requestBO.getClientType())){ | ||
93 | + clientType = requestBO.getClientType().toLowerCase(); | ||
94 | + } | ||
95 | + UnionConfig unionConfig = unionConfigDAO.selectByUidAndClientType(Integer.valueOf(uid),clientType); | ||
96 | + if(null!=unionConfig){ | ||
97 | + encryptKey = unionConfig.getEncryptKey(); | ||
98 | + signKey = unionConfig.getSignKey(); | ||
99 | + url = unionConfig.getUrl(); | ||
100 | + } | ||
101 | + //APPID可以固定根据clientType判断 | ||
102 | + String appId = "490655927"; | ||
103 | + if(clientType.equals(ClientTypeEnum.ANDROID.getName())){ | ||
104 | + appId = "100898104"; | ||
105 | + } | ||
106 | + int conv_time = DateUtil.getCurrentTimeSecond(); | ||
107 | + String page = null; | ||
108 | + String query_string = null; | ||
109 | + StringBuffer bf = new StringBuffer(); | ||
110 | + StringBuffer sf = new StringBuffer(); | ||
111 | + | ||
112 | + 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(); | ||
113 | + query_string = sf.append("muid=").append(muid4MD5).append("&conv_time=").append(conv_time).append("&value=").append(transInfo.getOrderAmount().multiply(new BigDecimal(100))).toString(); | ||
114 | + | ||
115 | + // 对url进行加密 | ||
116 | + String encode_page = null; | ||
117 | + try { | ||
118 | + encode_page = URLEncoder.encode(page, "UTF-8"); | ||
119 | + log.info("activateZhiHuitui urlEncoder is{} ", encode_page); | ||
120 | + } catch (UnsupportedEncodingException e) { | ||
121 | + log.error("encode exception.", e); | ||
122 | + } | ||
123 | + // 将签名密钥和提交方式与加密后的url进行拼接 | ||
124 | + StringBuffer urlBuffer = new StringBuffer(); | ||
125 | + | ||
126 | + String property = urlBuffer.append(signKey).append("&GET&").append(encode_page).toString(); | ||
127 | + String signature = MD5.md5(property); | ||
128 | + StringBuffer base = new StringBuffer(); | ||
129 | + String base_data = base.append(query_string).append("&sign=").append(signature).toString(); | ||
130 | + | ||
131 | + // 简单异或处理 | ||
132 | + String data = simpleXorByGdt(base_data, encryptKey); | ||
133 | + // base64编码 | ||
134 | + String ret = Base64.encodeBase64String(data.getBytes()); | ||
135 | + // 64位处理之后,防止里面有换行符 | ||
136 | + String retRep = ret.replaceAll("\n", ""); | ||
137 | + // 将64位处理之后的值,按照url加密的方式进行加密 | ||
138 | + try { | ||
139 | + retRep = URLEncoder.encode(retRep, "UTF-8"); | ||
140 | + log.info("activateUnion retRep is{}", retRep); | ||
141 | + } catch (UnsupportedEncodingException e) { | ||
142 | + log.error("encode exception.", e); | ||
143 | + } | ||
144 | + // conv_type,,现在只有移动应用激活类型(MOBILEAPP_ACTIVITE); | ||
145 | + String convType = "MOBILEAPP_COST"; | ||
146 | + if(transInfo.getType().equals("1")){ | ||
147 | + convType = "MOBILEAPP_ADDTOCART"; | ||
148 | + } | ||
149 | + StringBuffer sb = new StringBuffer(); | ||
150 | + 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(); | ||
151 | + log.info("GdtTransTask url is {}", url); | ||
152 | + return url; | ||
153 | + } | ||
53 | 154 | ||
155 | + /** | ||
156 | + * 简单异或 | ||
157 | + * | ||
158 | + * @param source | ||
159 | + * @param key | ||
160 | + * @return | ||
161 | + */ | ||
162 | + private String simpleXorByGdt(String source, String key) { | ||
163 | + String result = ""; | ||
164 | + int j = 0; | ||
165 | + for (int i = 0; i < source.length(); i++) { | ||
166 | + int c1 = source.charAt(i); | ||
167 | + int c2 = key.charAt(j); | ||
168 | + | ||
169 | + result = result + (char) (c1 ^ c2); | ||
170 | + j = j + 1; | ||
171 | + j = j % (key.length()); | ||
54 | } | 172 | } |
173 | + | ||
174 | + return result; | ||
55 | } | 175 | } |
56 | 176 | ||
57 | - private | 177 | + private String clientTypeConver(String clientType) { |
178 | + if (org.apache.commons.lang3.StringUtils.isEmpty(clientType)) { | ||
179 | + return null; | ||
180 | + } | ||
181 | + if (ClientTypeEnum.ANDROID.getName().equalsIgnoreCase(clientType)) { | ||
182 | + return clientType.toUpperCase(); | ||
183 | + } else { | ||
184 | + return "IOS"; | ||
185 | + } | ||
186 | + | ||
187 | + } | ||
58 | } | 188 | } |
1 | package com.test; | 1 | package com.test; |
2 | 2 | ||
3 | import java.io.UnsupportedEncodingException; | 3 | import java.io.UnsupportedEncodingException; |
4 | +import java.math.BigDecimal; | ||
4 | import java.net.URLDecoder; | 5 | import java.net.URLDecoder; |
5 | import java.net.URLEncoder; | 6 | import java.net.URLEncoder; |
6 | 7 | ||
@@ -40,20 +41,33 @@ public class Test { | @@ -40,20 +41,33 @@ public class Test { | ||
40 | // clientType = requestBO.getClient_type().toLowerCase(); | 41 | // clientType = requestBO.getClient_type().toLowerCase(); |
41 | // } | 42 | // } |
42 | 43 | ||
43 | - String client_ip = "10.11.12.13"; | ||
44 | - String appId = "112233"; | ||
45 | - int conv_time =1422263664; | 44 | +// if(org.apache.commons.lang.StringUtils.isNotEmpty(requestBO.getAdvertiserId())){ |
45 | +// uid = requestBO.getAdvertiserId(); | ||
46 | +// } | ||
47 | +// String clientType = ClientTypeEnum.IOS.getName(); | ||
48 | +// if(org.apache.commons.lang.StringUtils.isNotEmpty(requestBO.getClientType())){ | ||
49 | +// clientType = requestBO.getClientType().toLowerCase(); | ||
50 | +// } | ||
51 | +// UnionConfig unionConfig = unionConfigDAO.selectByUidAndClientType(Integer.valueOf(uid),clientType); | ||
52 | +// if(null!=unionConfig){ | ||
53 | +// encryptKey = unionConfig.getEncryptKey(); | ||
54 | +// signKey = unionConfig.getSignKey(); | ||
55 | +// url = unionConfig.getUrl(); | ||
56 | +// } | ||
57 | + //APPID可以固定根据clientType判断 | ||
58 | + String appId = "490655927"; | ||
59 | + if(clientType.equals(ClientTypeEnum.ANDROID.getName())){ | ||
60 | + appId = "100898104"; | ||
61 | + } | ||
62 | + int conv_time = DateUtil.getCurrentTimeSecond(); | ||
46 | String page = null; | 63 | String page = null; |
47 | String query_string = null; | 64 | String query_string = null; |
48 | StringBuffer bf = new StringBuffer(); | 65 | StringBuffer bf = new StringBuffer(); |
49 | StringBuffer sf = new StringBuffer(); | 66 | StringBuffer sf = new StringBuffer(); |
50 | - if (StringUtils.isEmpty(client_ip)){ | ||
51 | - page = bf.append(url).append(appId).append("/conv?muid=").append(muid4MD5).append("&conv_time=").append(conv_time).toString(); | ||
52 | - query_string = sf.append("muid=").append(muid4MD5).append("&conv_time=").append(conv_time).toString(); | ||
53 | - }else{ | ||
54 | - page = bf.append(url).append(appId).append("/conv?muid=").append(muid4MD5).append("&conv_time=").append(conv_time).append("&client_ip=").append(client_ip).toString(); | ||
55 | - query_string = sf.append("muid=").append(muid4MD5).append("&conv_time=").append(conv_time).append("&client_ip=").append(client_ip).toString(); | ||
56 | - } | 67 | + |
68 | + 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(); | ||
69 | + query_string = sf.append("muid=").append(muid4MD5).append("&conv_time=").append(conv_time).append("&value=").append(transInfo.getOrderAmount().multiply(new BigDecimal(100))).toString(); | ||
70 | + | ||
57 | // 对url进行加密 | 71 | // 对url进行加密 |
58 | String encode_page = null; | 72 | String encode_page = null; |
59 | try { | 73 | try { |
@@ -84,10 +98,13 @@ public class Test { | @@ -84,10 +98,13 @@ public class Test { | ||
84 | log.error("encode exception.", e); | 98 | log.error("encode exception.", e); |
85 | } | 99 | } |
86 | // conv_type,,现在只有移动应用激活类型(MOBILEAPP_ACTIVITE); | 100 | // conv_type,,现在只有移动应用激活类型(MOBILEAPP_ACTIVITE); |
87 | - String convType = "MOBILE_APP_ACTIVITE"; | 101 | + String convType = "MOBILEAPP_COST"; |
102 | + if(transInfo.getType().equals("1")){ | ||
103 | + convType = "MOBILEAPP_ADDTOCART"; | ||
104 | + } | ||
88 | StringBuffer sb = new StringBuffer(); | 105 | StringBuffer sb = new StringBuffer(); |
89 | - 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(); | ||
90 | - log.info("zhihuitui url is {}", url); | 106 | + 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(); |
107 | + log.info("GdtTransTask url is {}", url); | ||
91 | System.out.print(url); | 108 | System.out.print(url); |
92 | } | 109 | } |
93 | 110 |
-
Please register or login to post a comment