Authored by zhengwen.ge

智慧推

package com.yoho.unions.dal;
import com.yoho.unions.dal.model.UnionConfig;
import org.apache.ibatis.annotations.Param;
public interface IUnionConfigDAO {
UnionConfig selectByPrimaryKey(Integer uid);
UnionConfig selectByUidAndClientType(@Param("uid") int uid, @Param("client_type") String client_type);
}
\ No newline at end of file
... ...
package com.yoho.unions.dal.model;
public class UnionConfig {
private Integer id;
private Integer uid;
private String clientType;
private String encryptKey;
private String signKey;
private String url;
private Integer createTime;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getUid() {
return uid;
}
public void setUid(Integer uid) {
this.uid = uid;
}
public String getClientType() {
return clientType;
}
public void setClientType(String clientType) {
this.clientType = clientType == null ? null : clientType.trim();
}
public String getEncryptKey() {
return encryptKey;
}
public void setEncryptKey(String encryptKey) {
this.encryptKey = encryptKey == null ? null : encryptKey.trim();
}
public String getSignKey() {
return signKey;
}
public void setSignKey(String signKey) {
this.signKey = signKey == null ? null : signKey.trim();
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url == null ? null : url.trim();
}
public Integer getCreateTime() {
return createTime;
}
public void setCreateTime(Integer createTime) {
this.createTime = createTime;
}
}
\ 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.IUnionConfigDAO" >
<resultMap id="BaseResultMap" type="com.yoho.unions.dal.model.UnionConfig" >
<id column="id" property="id" jdbcType="INTEGER" />
<result column="uid" property="uid" jdbcType="INTEGER" />
<result column="client_type" property="clientType" jdbcType="VARCHAR" />
<result column="encrypt_key" property="encryptKey" jdbcType="VARCHAR" />
<result column="sign_key" property="signKey" jdbcType="VARCHAR" />
<result column="url" property="url" jdbcType="VARCHAR" />
<result column="create_time" property="createTime" jdbcType="INTEGER" />
</resultMap>
<sql id="Base_Column_List" >
id, uid, client_type, encrypt_key, sign_key, url, create_time
</sql>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
select
<include refid="Base_Column_List" />
from union_config
where uid = #{uid,jdbcType=INTEGER}
</select>
<select id="selectByUidAndClientType" resultMap="BaseResultMap">
select <include refid="Base_Column_List" />
from union_config
where uid = #{uid} and client_type = #{client_type} limit 1
</select>
</mapper>
\ No newline at end of file
... ...
... ... @@ -366,7 +366,7 @@ public class UnionServiceImpl implements IUnionService,ApplicationEventPublisher
MktMarketingUrl mktMarketingUrl = redisValueCache.get(unionTypekey,MktMarketingUrl.class);
if(mktMarketingUrl==null){
mktMarketingUrl = mktMarketingUrlDAO.selectByPrimaryKey(Long.valueOf(click.getUnion_type()));
redisValueCache.set(unionTypekey,mktMarketingUrl,1, TimeUnit.HOURS);
redisValueCache.set(unionTypekey, mktMarketingUrl, 1, TimeUnit.HOURS);
}
UnionTypeModel u = new UnionTypeModel();
u.setName(mktMarketingUrl.getName());
... ... @@ -501,7 +501,7 @@ public class UnionServiceImpl implements IUnionService,ApplicationEventPublisher
log.info("activateUnion in success request is {}", request);
return new UnionResponse();
}
if(!"3".equals(union_type)){
if(!"3".equals(union_type)||!"100000000000453".equals(union_type)){
url = URLDecoder.decode(url, "UTF-8");
}
... ...
... ... @@ -7,6 +7,8 @@ import com.yoho.service.model.union.request.ActivateUnionRequestBO;
import com.yoho.service.model.union.request.ClickUnionRequestBO;
import com.yoho.unions.common.enums.ClientTypeEnum;
import com.yoho.unions.common.utils.DateUtil;
import com.yoho.unions.dal.IUnionConfigDAO;
import com.yoho.unions.dal.model.UnionConfig;
import com.yoho.unions.server.service.IUnionService;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang3.StringUtils;
... ... @@ -66,7 +68,7 @@ public class ZhihuituiServiceImpl extends UnionServiceImpl implements IUnionServ
bo.setUnion_type(request.getParameter("union_type"));
bo.setClickTime(Integer.valueOf(request.getParameter("click_time")));
bo.setTd(request.getParameter("td"));
//广告主在广点通的账户id
//广告主在智慧推的账户id
// bo.setJson(JSONObject.parseObject(request.getParameter("advertiser_id")));
bo.setCommonUse(String.valueOf(request.getParameter("advertiser_id")));
return bo;
... ... @@ -81,103 +83,68 @@ public class ZhihuituiServiceImpl extends UnionServiceImpl implements IUnionServ
public String urlEode(ActivateUnionRequestBO requestBO) {
log.info("enter GDTServiceImpl.urlEode param{} is ", requestBO);
// 根据不同的应用类型,获取不同的加密密钥和签名密钥
String encryptKey = null;
String signKey = null;
String encryptKey = "b4e4b76af6626299";
String signKey = "04ddd32894b3c683";
String muid4MD5 = "";
//有货在广点通的账号id
String uid = requestBO.getCommonUse();
String url = "http://jump.t.l.qq.com/conv/app/";
//有货在智慧推的账号id
String uid = "18261";
if(StringUtils.isNotEmpty(requestBO.getCommonUse())){
uid = requestBO.getCommonUse();
}
String clientType = ClientTypeEnum.IOS.getName();
if(StringUtils.isNotEmpty(requestBO.getClient_type())){
clientType = requestBO.getClient_type().toLowerCase();
}
UnionConfig unionConfig = unionConfigDAO.selectByUidAndClientType(Integer.valueOf(uid),clientType);
if(null!=unionConfig){
encryptKey = unionConfig.getEncryptKey();
signKey = unionConfig.getSignKey();
url = unionConfig.getUrl();
}
if (ClientTypeEnum.IOS.getName().equalsIgnoreCase(requestBO.getClient_type())) {
//由于有两个广点通账号,根据不同的账号取不同的加密密钥和签名密钥
if(StringUtils.isNotEmpty(uid)&&uid.equals("365136")){
DynamicStringProperty ios_encrypt_key = DynamicPropertyFactory.getInstance().getStringProperty("ios1_encrypt_key", "");
encryptKey = ios_encrypt_key.get();
DynamicStringProperty ios_sign_key = DynamicPropertyFactory.getInstance().getStringProperty("ios1_sign_key", "");
signKey = ios_sign_key.get();
}else{
DynamicStringProperty ios2_encrypt_key = DynamicPropertyFactory.getInstance().getStringProperty("ios2_encrypt_key", "");
encryptKey = ios2_encrypt_key.get();
DynamicStringProperty ios2_sign_key = DynamicPropertyFactory.getInstance().getStringProperty("ios2_sign_key", "");
signKey = ios2_sign_key.get();
}
//IDFA 码(需转大写),进行 md5 以后得到的 32位全小写 md5 表现字符串。
muid4MD5 = requestBO.getIdfa().toUpperCase();
//IDFA 码
muid4MD5 = requestBO.getIdfa();
} else {
if(StringUtils.isNotEmpty(uid)&&uid.equals("365136")){
DynamicStringProperty android_encrypt_key = DynamicPropertyFactory.getInstance().getStringProperty("android1_encrypt_key", "");
encryptKey = android_encrypt_key.get();
DynamicStringProperty android_sign_key = DynamicPropertyFactory.getInstance().getStringProperty("android1_sign_key", "");
signKey = android_sign_key.get();
}else{
DynamicStringProperty android2_encrypt_key = DynamicPropertyFactory.getInstance().getStringProperty("android2_encrypt_key", "");
encryptKey = android2_encrypt_key.get();
DynamicStringProperty android2_sign_key = DynamicPropertyFactory.getInstance().getStringProperty("android2_sign_key", "");
signKey = android2_sign_key.get();
}
//IMEI 号(需转小写),进行 md5 以后得到的 32位全小写 md5 表现字符串。
muid4MD5 = requestBO.getImei().toLowerCase();
//IMEI 号
muid4MD5 = requestBO.getImei();
}
/**
* 对设备id进行MD5加密,获取32位小写加密串
*/
String muid = MD5.md5(muid4MD5);
log.info("activateUnion muid is{} ", muid);
/**
* 对url进行拼接,并进行加密-----http://t.gdt.qq.com/conv/app/
*/
String url = DynamicPropertyFactory.getInstance().getStringProperty("guangdiantong.url", "").get();
int conv_time = DateUtil.getCurrentTimeSecond();
String client_ip = requestBO.getClientIp();
String clickId = requestBO.getUdid();
String appId = requestBO.getAppid();
int conv_time = DateUtil.getCurrentTimeSecond();
String page = null;
String query_string = null;
StringBuffer bf = new StringBuffer();
StringBuffer sf = new StringBuffer();
String query_string = null;
String url4Encoude = null;
if (StringUtils.isEmpty(client_ip)) {
url4Encoude = bf.append(url).append(appId).append("/conv?click_id=").append(clickId).append("&muid=").append(muid).append("&conv_time=").append(conv_time).toString();
query_string = sf.append("click_id=").append(clickId).append("&muid=").append(muid).append("&conv_time=").append(conv_time).toString();
} else {
url4Encoude = bf.append(url).append(appId).append("/conv?click_id=").append(clickId).append("&muid=").append(muid).append("&conv_time=").append(conv_time).append("&client_ip=").append(client_ip).toString();
query_string = sf.append("click_id=").append(clickId).append("&muid=").append(muid).append("&conv_time=").append(conv_time).append("&client_ip=").append(client_ip).toString();
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();
}
log.info("activateUnion url is{} ", url4Encoude);
//参数加密
// sf = sf.append(url).append(requestBO.getAppid()).append("/conv?").append(query_string);
// 对url进行加密
String urlEncoder = null;
String encode_page = null;
try {
urlEncoder = URLEncoder.encode(url4Encoude, "UTF-8");
log.info("activateUnion urlEncoder is{} ", urlEncoder);
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();
url = urlBuffer.append(signKey).append("&GET&").append(urlEncoder).toString();
log.info("signkey url is {}",url);
// 对url进行MD5加密,获取32位小写加密串
String md5 = MD5.md5(url);
log.info("activateUnion md5 is{} ", md5);
// 参数组合,并进行加密
String property = urlBuffer.append(signKey).append("&GET&").append(encode_page).toString();
String signature = MD5.md5(property);
StringBuffer base = new StringBuffer();
StringBuffer sb = new StringBuffer();
String md5UrlEncoude = null;
try{
md5UrlEncoude = URLEncoder.encode(md5,"UTF-8");
}catch (UnsupportedEncodingException e) {
log.error("encode exception.", e);
}
String baseData = base.append(query_string).append("&sign=").append(md5UrlEncoude).toString();
log.info("activateUnion baseDate is {} ", baseData);
String base_data = base.append(query_string).append("&sign=").append(signature).toString();
// 简单异或处理
String base64 = simpleXorByGdt(baseData, encryptKey);
String data = simpleXorByGdt(base_data, encryptKey);
// base64编码
String ret = Base64.encodeBase64String(base64.getBytes());
String ret = Base64.encodeBase64String(data.getBytes());
// 64位处理之后,防止里面有换行符
String retRep = ret.replaceAll("\n", "");
// 将64位处理之后的值,按照url加密的方式进行加密
... ... @@ -188,9 +155,9 @@ public class ZhihuituiServiceImpl extends UnionServiceImpl implements IUnionServ
log.error("encode exception.", e);
}
// conv_type,,现在只有移动应用激活类型(MOBILEAPP_ACTIVITE);
String convType = "MOBILEAPP_ACTIVITE";
url = sb.append(DynamicPropertyFactory.getInstance().getStringProperty("guangdiantong.url", "").get()).append(requestBO.getAppid()).append("/conv?v=").append(retRep).append("&conv_type=").append(convType).append("&app_type=").append(clientTypeConver(requestBO.getClient_type())).append("&advertiser_id=").append(uid).toString();
String convType = "MOBILE_APP_ACTIVITE";
StringBuffer sb = new StringBuffer();
url = sb.append(url).append(requestBO.getAppid()).append("/conv?v=").append(retRep).append("&conv_type=").append(convType).append("&app_type=").append(clientTypeConver(requestBO.getClient_type())).append("&advertiser_id=").append(uid).toString();
log.info("zhihuitui url is {}", url);
return url;
}
... ...
... ... @@ -8,6 +8,7 @@ import com.yoho.service.model.union.request.ActivateUnionRequestBO;
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.model.UnionConfig;
import com.yoho.unions.server.service.impl.GDT2ServiceImpl;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang3.StringUtils;
... ... @@ -26,109 +27,68 @@ public class Test {
public static void main(String[] args){
// 根据不同的应用类型,获取不同的加密密钥和签名密钥
// 根据不同的应用类型,获取不同的加密密钥和签名密钥
String encryptKey = "BAAAAAAAAAAABZJQ";
String signKey = "1461f1237d22dfc7";
// String muid4MD5 = "0f074dc8e1f0547310e729032ac0730b";
String encryptKey = "test_encrypt_key";
String signKey = "test_sign_key";
String muid4MD5 = "0f074dc8e1f0547310e729032ac0730b";
String url = "http://jump.t.l.qq.com/conv/app/";
//有货在智慧推的账号id
String uid = "18261";
GDT2ServiceImpl gdt2Service = new GDT2ServiceImpl();
ActivateUnionRequestBO requestBO = new ActivateUnionRequestBO();
requestBO.setIdfa("5bdfa8ee7a491f67428b2c341a803514");
requestBO.setUdid("sykvcwayaaaasz2b2x7a");
requestBO.setCommonUse("365136");
requestBO.setAppid("490655927");
requestBO.setClient_type("ios");
// requestBO.setClientIp("171.213.29.236");
// String url = gdt2Service.urlEode(requestBO);
// String url1 = url+"&identify_id=null";
// Pair<Integer, String> pair = HttpUtils.httpGet(url1);
// try{
// url = URLDecoder.decode(url1, "UTF-8");
// }catch (Exception e){
//
String clientType = ClientTypeEnum.IOS.getName();
// if(StringUtils.isNotEmpty(requestBO.getClient_type())){
// clientType = requestBO.getClient_type().toLowerCase();
// }
String idfa = requestBO.getIdfa().toUpperCase();
// Pair<Integer, String> pair1 = HttpUtils.httpGet(url);
String client_ip = "10.11.12.13";
String appId = "112233";
int conv_time =1422263664;
String page = null;
String query_string = null;
StringBuffer bf = new StringBuffer();
StringBuffer sf = new StringBuffer();
String query_string = sf.append("click_id=").append(requestBO.getUdid()).append("&muid=").append(MD5.md5(idfa)).append("&conv_time=").append(1481714596).toString();
String page = "http://t.gdt.qq.com/conv/app/"+490655927+"/conv?"+query_string;
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();
}
// 对url进行加密
String encode_page = null;
String GDTurl = null;
try{
try {
encode_page = URLEncoder.encode(page, "UTF-8");
String property = signKey+"&GET&"+encode_page;
String signature = MD5.md5(property);
String base_data = query_string+"&sign="+URLEncoder.encode(signature,"UTF-8");
String data = simpleXorByGdt(base_data, encryptKey);
// base64编码
String ret = Base64.encodeBase64String(data.getBytes());
String attachment = "conv_type="+"MOBILEAPP_ACTIVITE"+"&app_type="+clientTypeConver(requestBO.getClient_type())+"&advertiser_id="+365136;
GDTurl = "http://t.gdt.qq.com/conv/app/"+requestBO.getAppid()+"/conv?v="+ret+"&"+attachment;
}catch (UnsupportedEncodingException e){
log.info("activateZhiHuitui urlEncoder is{} ", encode_page);
} catch (UnsupportedEncodingException e) {
log.error("encode exception.", e);
}
// System.out.print(pair);
// 将签名密钥和提交方式与加密后的url进行拼接
StringBuffer urlBuffer = new StringBuffer();
// if (ClientTypeEnum.IOS.getName().equalsIgnoreCase(requestBO.getClient_type())) {
// DynamicStringProperty ios_encrypt_key = DynamicPropertyFactory.getInstance().getStringProperty("ios1_encrypt_key", "");
// encryptKey = ios_encrypt_key.get();
// DynamicStringProperty ios_sign_key = DynamicPropertyFactory.getInstance().getStringProperty("ios1_sign_key", "");
// signKey = ios_sign_key.get();
// //IDFA 码(需转大写),进行 md5 以后得到的 32位全小写 md5 表现字符串。
// muid4MD5 = 0f074dc8e1f0547310e729032ac0730b
// } else {
// DynamicStringProperty android_encrypt_key = DynamicPropertyFactory.getInstance().getStringProperty("android1_encrypt_key", "");
// encryptKey = android_encrypt_key.get();
// DynamicStringProperty android_sign_key = DynamicPropertyFactory.getInstance().getStringProperty("android1_sign_key", "");
// signKey = android_sign_key.get();
// //IMEI 号(需转小写),进行 md5 以后得到的 32位全小写 md5 表现字符串。
// muid4MD5 = requestBO.getImei().toLowerCase();
// }
/**
* 对设备id进行MD5加密,获取32位小写加密串
*/
//
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();
/**
* 对url进行拼接,并进行加密-----http://t.gdt.qq.com/conv/app/
*/
// String url = "";
// String client_ip = "11.22.33";
// int conv_time = DateUtil.getCurrentTimeSecond();
// String clickId = "007210548a030059ccdfd1d4";
// String appId = "490655927";
// StringBuffer bf = new StringBuffer();
// StringBuffer sf = new StringBuffer();
// String query_string = null;
// String url4Encoude = null;
// //有货在广点通的账号id
// String advertiser_id = "365136";
// if (StringUtils.isEmpty(client_ip)) {
// url4Encoude = bf.append(url).append(appId).append("/conv?click_id=").append(clickId).append("&muid=").append(muid).append("&conv_time=").append(conv_time).toString();
// query_string = sf.append("click_id=").append(clickId).append("&muid=").append(muid).append("&conv_time=").append(conv_time).toString();
// } else {
// url4Encoude = bf.append(url).append(appId).append("/conv?click_id=").append(clickId).append("&muid=").append(muid).append("&conv_time=").append(conv_time).append("&client_ip=").append(client_ip).toString();
// query_string = sf.append("click_id=").append(clickId).append("&muid=").append(muid).append("&conv_time=").append(conv_time).append("&client_ip=").append(client_ip).toString();
// }
// log.info("activateUnion url is{} ", url4Encoude);
// //参数加密
//// sf = sf.append(url).append(requestBO.getAppid()).append("/conv?").append(query_string);
// String page = "http://t.gdt.qq.com/conv/app/"+appId+"/conv?"+query_string;
// String encode_page = null;
// String GDTurl = null;
// try{
// encode_page = URLEncoder.encode(page, "UTF-8");
// String property = signKey+"&GET"+"encode_page";
// String signature = MD5.md5(property);
// String base_data = query_string+"&sign="+URLEncoder.encode(signature,"UTF-8");
// String data = simpleXorByGdt(base_data, encryptKey);
// String attachment = "conv_type="+"MOBILEAPP_ACTIVITE"+"&app_type="+"ANDROID"+"&advertiser_id="+advertiser_id;
// GDTurl = "http://t.gdt.qq.com/conv/app/"+"490655927"+"/conv?v="+data+"&"+attachment;
// Pair<Integer, String> pair = HttpUtils.httpGet(GDTurl);
// }catch (UnsupportedEncodingException e){
// log.error("encode exception.", e);
// }
// System.out.print(GDTurl);
// 简单异或处理
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 = "MOBILE_APP_ACTIVITE";
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);
}
private static String clientTypeConver(String clientType) {
... ... @@ -136,9 +96,9 @@ public class Test {
return null;
}
if (ClientTypeEnum.ANDROID.getName().equalsIgnoreCase(clientType)) {
return clientType.toUpperCase();
return clientType.toLowerCase();
} else {
return "IOS";
return "ios";
}
}
... ...