Authored by zhengwen.ge

update

... ... @@ -39,6 +39,8 @@ public class GDT2ServiceImpl extends UnionServiceImpl implements IUnionService {
requestBO.setIdfa(clickBO.getIdfa());
requestBO.setImei(clickBO.getImei());
requestBO.setCommonUse(clickBO.getCommonUse());
//广点通后台生成的点击id
requestBO.setUdid(clickBO.getClickId());
return urlEode(requestBO);
}
... ... @@ -92,11 +94,9 @@ public class GDT2ServiceImpl extends UnionServiceImpl implements IUnionService {
//IMEI 号(需转小写),进行 md5 以后得到的 32位全小写 md5 表现字符串。
muid4MD5 = requestBO.getImei().toLowerCase();
}
/**
* 对设备id进行MD5加密,获取32位小写加密串
*/
String muid = MD5.md5(muid4MD5);
log.info("activateUnion muid is{} ", muid);
... ... @@ -106,18 +106,23 @@ public class GDT2ServiceImpl extends UnionServiceImpl implements IUnionService {
String url = DynamicPropertyFactory.getInstance().getStringProperty("guangdiantong.url", "").get();
int conv_time = DateUtil.getCurrentTimeSecond();
String client_ip = requestBO.getClientIp();
String clickId = requestBO.getCommonUse();
String appId = requestBO.getAppid();
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(requestBO.getAppid()).append("/conv?muid=").append(muid).append("&conv_time=").append(conv_time).toString();
query_string = sf.append("muid=").append(muid).append("&conv_time=").append(conv_time).toString();
url4Encoude = bf.append(url).append(appId).append("/conv?click_id=").append(clickId).append("&muid=").append(muid).append("&conv_time=").append(conv_time).append("&muid=").append(muid).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(requestBO.getAppid()).append("/conv?muid=").append(muid).append("&conv_time=").append(conv_time).append("&client_ip=").append(client_ip).toString();
query_string = sf.append("muid=").append(muid).append("&conv_time=").append(conv_time).append("&client_ip=").append(client_ip).toString();
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);
// 对url进行加密
String urlEncoder = null;
try {
... ... @@ -129,13 +134,20 @@ public class GDT2ServiceImpl extends UnionServiceImpl implements IUnionService {
// 将签名密钥和提交方式与加密后的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);
// 参数组合,并进行加密
StringBuffer base = new StringBuffer();
StringBuffer sb = new StringBuffer();
String baseData = base.append(query_string).append("&sign=").append(md5).toString();
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);
// 简单异或处理
... ...
... ... @@ -228,6 +228,14 @@ public class UnionServiceImpl implements IUnionService {
}
value = yhValueOperations.get(key);
}
if(StringUtils.isEmpty(value)){
if (ClientTypeEnum.IOS.getName().equals(request.getClient_type())) {
key = UNION_KEY + "_" + MD5.md5(request.getIdfa()).toLowerCase() + "_" + request.getAppkey();
} else if (ClientTypeEnum.ANDROID.getName().equals(request.getClient_type())) {
key = UNION_KEY + "_" + MD5.md5(request.getImei()).toLowerCase() + "_" + request.getAppkey();
}
value = yhValueOperations.get(key);
}
}
log.info("activateUnion with get redis first with key={}, value={}", key, value);
... ...
... ... @@ -3,6 +3,8 @@ package com.test;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import com.yoho.unions.common.enums.ClientTypeEnum;
import com.yoho.unions.common.utils.DateUtil;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
... ... @@ -18,89 +20,107 @@ public class Test {
static Logger log = LoggerFactory.getLogger(GDTServiceImpl.class);
public static void main(String[] args){
DynamicStringProperty encrypt_key = DynamicPropertyFactory.getInstance().getStringProperty("encrypt_key", "");
String encryptKey = encrypt_key.get();
encryptKey="test_encrypt_key";
System.out.println(encryptKey);
DynamicStringProperty sign_key = DynamicPropertyFactory.getInstance().getStringProperty("sign_key", "");
String signKey = sign_key.get();
signKey = "test_sign_key";
System.out.println(signKey);
// 根据不同的应用类型,获取不同的加密密钥和签名密钥
String encryptKey = null;
String signKey = null;
String muid4MD5 = "0f074dc8e1f0547310e729032ac0730b";
// 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 = requestBO.getIdfa().toUpperCase();
// }
DynamicStringProperty android_encrypt_key = DynamicPropertyFactory.getInstance().getStringProperty("android1_encrypt_key", "");
encryptKey = "test_encrypt_key";
DynamicStringProperty android_sign_key = DynamicPropertyFactory.getInstance().getStringProperty("android1_sign_key", "");
signKey = "test_sign_key";
//IMEI 号(需转小写),进行 md5 以后得到的 32位全小写 md5 表现字符串。
// muid4MD5 = requestBO.getImei().toLowerCase();
// }
/**
* 对设备id进行MD5加密,获取32位小写加密串
*/
String muid4MD5 = "354649050046412";
String muid = MD5.md5(muid4MD5);
muid = "0f074dc8e1f0547310e729032ac0730b";
System.out.println(muid);
log.info("activateUnion muid is{} ", muid);
/**
* 对url进行拼接,并进行加密
* 对url进行拼接,并进行加密-----http://t.gdt.qq.com/conv/app/
*/
String url = "http://t.gdt.qq.com/conv/app/";
int conv_time = 1422263664;
String url = DynamicPropertyFactory.getInstance().getStringProperty("guangdiantong.url", "").get();
int conv_time = DateUtil.getCurrentTimeSecond();
String client_ip = "10.11.12.13";
String clickId = "007210548a030059ccdfd1d4";
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("112233").append("/conv?muid=").append(muid).append("&conv_time=")
.append(conv_time).toString();
query_string = sf.append("muid=").append(muid).append("&conv_time=").append(conv_time).toString();
}
else{
url4Encoude = bf.append(url).append("112233").append("/conv?muid=").append(muid).append("&conv_time=")
.append(conv_time).append("&client_ip=").append(client_ip).toString();
query_string = sf.append("muid=").append(muid).append("&conv_time=").append(conv_time).append("&client_ip=").append(client_ip).toString();
String appId = "112233";
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).append("&muid=").append(muid).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();
}
System.out.println("url4Encoude: "+url4Encoude);
System.out.println("query_string: "+query_string);
log.info("activateUnion url is {} ", url4Encoude);
//参数加密
sf = sf.append(url).append(appId).append("/conv?").append(query_string);
// 对url进行加密
String urlEncoder = null;
//对url进行加密
try {
urlEncoder = URLEncoder.encode(url4Encoude,"UTF-8");
System.out.println("urlEncoder: "+urlEncoder);
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
log.error("encode exception.", e);
}
//将签名密钥和提交方式与加密后的url进行拼接
StringBuffer urlBuffer = new StringBuffer();
url=urlBuffer.append(signKey).append("&GET&").append(urlEncoder).toString();
System.out.println("url :"+url);
//对url进行MD5加密,获取32位小写加密串
String md5 = MD5.md5(url);
System.out.println("md5 :"+md5);
StringBuffer base = new StringBuffer();
StringBuffer sb = new StringBuffer();
String baseData=base.append(query_string).append("&sign=").append(md5).toString();
//log.info("activateUnion baseDate is {}",baseData);
System.out.println("baseData: "+baseData);
//简单异或处理
String base64 = simpleXorByGdt(baseData,encryptKey);
//base64编码
String ret = Base64.encodeBase64String(base64.getBytes());
System.out.println("ret: "+ret);
//64位处理之后,防止里面有换行符
String retRep = ret.replaceAll("\n", "");
try {
retRep = URLEncoder.encode(retRep,"UTF-8");
url = sb.append("http://t.gdt.qq.com/conv/app/").append("112233").append("/conv?v=").append(retRep)
.append("&conv_type=").append("MOBILEAPP_ACTIVITE")
.append("&app_type=").append("ANDROID")
.append("&advertiser_id=").append(10000).toString();
System.out.println("url: "+url);
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
urlEncoder = URLEncoder.encode(url4Encoude, "UTF-8");
log.info("activateUnion urlEncoder is {} ", urlEncoder);
} catch (UnsupportedEncodingException e) {
log.error("encode exception.", e);
}
// 将签名密钥和提交方式与加密后的url进行拼接
StringBuffer urlBuffer = new StringBuffer();
url = urlBuffer.append(signKey).append("&GET&").append(urlEncoder).toString();
log.info("url is {}",url);
// 对url进行MD5加密,获取32位小写加密串
String md5 = MD5.md5(url);
// md5 = "c2f87710541942364691e5e8adc84f3f";
log.info("activateUnion md5 is {} ", md5);
// 参数组合,并进行加密
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 base64 = simpleXorByGdt(baseData, encryptKey);
// base64编码
String ret = Base64.encodeBase64String(base64.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_ACTIVITE";
//有货在广点通的账号id
String uid = "10000";
url = sb.append(DynamicPropertyFactory.getInstance().getStringProperty("guangdiantong.url", "").get()).append(appId).append("/conv?v=").append(retRep).append("&conv_type=").append(convType).append("&app_type=").append("ANDROID").append("&advertiser_id=").append(uid).toString();
log.info("guangdiantong url is {}", url);
System.out.print(url);
}
... ...