...
|
...
|
@@ -18,12 +18,11 @@ import com.alibaba.fastjson.JSONObject; |
|
|
import com.netflix.config.DynamicPropertyFactory;
|
|
|
import com.netflix.config.DynamicStringProperty;
|
|
|
import com.yoho.core.common.utils.MD5;
|
|
|
import com.yoho.service.model.union.request.ActivateGDTRequestBO;
|
|
|
import com.yoho.service.model.union.request.MainUnionRequestBO;
|
|
|
import com.yoho.service.model.union.response.ActivateDingdangResponseBO;
|
|
|
import com.yoho.service.model.union.response.ActivateGDTResponseBO;
|
|
|
import com.yoho.service.model.union.response.MainUnionResponseBO;
|
|
|
import com.yoho.service.model.union.request.ActivateUnionRequestBO;
|
|
|
import com.yoho.service.model.union.response.UnionResponseBO;
|
|
|
import com.yoho.unions.common.enums.ClientTypeEnum;
|
|
|
import com.yoho.unions.common.enums.MsgEnum;
|
|
|
import com.yoho.unions.common.enums.UnionTypeEnum;
|
|
|
import com.yoho.unions.common.utils.DateUtil;
|
|
|
import com.yoho.unions.common.utils.HttpUtils;
|
|
|
import com.yoho.unions.dal.IUnionLogsDAO;
|
...
|
...
|
@@ -32,192 +31,199 @@ import com.yoho.unions.server.service.MainUnionService; |
|
|
|
|
|
/**
|
|
|
* 广点通接口
|
|
|
*
|
|
|
* @author yoho
|
|
|
*
|
|
|
*/
|
|
|
//@Service("gdtServiceImpl")
|
|
|
@Service("gdtServiceImpl")
|
|
|
public class GDTServiceImpl implements MainUnionService {
|
|
|
|
|
|
|
|
|
static Logger log = LoggerFactory.getLogger(GDTServiceImpl.class);
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
IUnionLogsDAO unionLogsDAO;
|
|
|
|
|
|
@Override
|
|
|
public MainUnionResponseBO addUnionCheck(MainUnionRequestBO request) {
|
|
|
// TODO Auto-generated method stub
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
|
|
|
@Override
|
|
|
public MainUnionResponseBO addUnion(MainUnionRequestBO request) {
|
|
|
public JSONObject addUnion(Object obj) {
|
|
|
// TODO Auto-generated method stub
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public MainUnionResponseBO activateUnionCheck(MainUnionRequestBO request) {
|
|
|
ActivateGDTRequestBO requestBO = (ActivateGDTRequestBO) request;
|
|
|
log.debug("activateUnionCheck with param is {}" , requestBO);
|
|
|
if(requestBO.getAppid()==0){
|
|
|
log.warn("activateUnionCheck error because appid is{}",requestBO.getAppid());
|
|
|
return new ActivateGDTResponseBO(false, "appid is null");
|
|
|
private UnionResponseBO check(ActivateUnionRequestBO request) {
|
|
|
log.debug("activateUnionCheck with param is {}", request);
|
|
|
if (StringUtils.isEmpty(request.getAppid())) {
|
|
|
log.warn("activateUnionCheck error because appid is null with param is {}", request);
|
|
|
return new UnionResponseBO(false, "appid is null");
|
|
|
}
|
|
|
if(requestBO.getUid()==0){
|
|
|
log.warn("activateUnionCheck error because uid is{}",requestBO.getUid());
|
|
|
return new ActivateGDTResponseBO(false, "uid is null");
|
|
|
if (StringUtils.isEmpty(request.getClient_type()) || (!request.getClient_type().equalsIgnoreCase(ClientTypeEnum.ANDROID.getName()) && !request.getClient_type().equalsIgnoreCase(ClientTypeEnum.IOS.getName()))) {
|
|
|
log.warn("activateUnionCheck error with param is {}", request);
|
|
|
return new UnionResponseBO(false, "app_type is error");
|
|
|
}
|
|
|
if(StringUtils.isEmpty(requestBO.getConv_type())||!requestBO.getConv_type().equals("MOBILEAPP_ACTIVITE")){
|
|
|
log.warn("activateUnionCheck error because conv_type is{}",requestBO.getConv_type());
|
|
|
return new ActivateGDTResponseBO(false, "conv_type is error");
|
|
|
if (request.getClient_type().equalsIgnoreCase(ClientTypeEnum.ANDROID.getName()) && StringUtils.isEmpty(request.getImei())) {
|
|
|
log.warn("activateUnionCheck error because imei is null with client_type is andriod with param is {}", request);
|
|
|
return new UnionResponseBO(false, "imei is error");
|
|
|
}
|
|
|
if(StringUtils.isEmpty(requestBO.getApp_type())||(!requestBO.getApp_type().equals("ANDROID")&&!requestBO.getApp_type().equals("IOS"))){
|
|
|
log.warn("activateUnionCheck error because app_type is{}",requestBO.getApp_type());
|
|
|
return new ActivateGDTResponseBO(false, "app_type is error");
|
|
|
if (request.getClient_type().equalsIgnoreCase(ClientTypeEnum.IOS.getName()) && StringUtils.isEmpty(request.getIdfa())) {
|
|
|
log.warn("activateUnionCheck error because idfa is null with client_type is ios with param is {}", request);
|
|
|
return new UnionResponseBO(false, "idfa is error");
|
|
|
}
|
|
|
if (StringUtils.isEmpty(requestBO.getMuid())) {
|
|
|
log.warn("activateUnionCheck error becauls muid is{}",requestBO.getMuid());
|
|
|
return new ActivateGDTResponseBO(false, "muid is null");
|
|
|
}
|
|
|
return new ActivateGDTResponseBO();
|
|
|
return new UnionResponseBO(true, "success");
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public MainUnionResponseBO activateUnion(MainUnionRequestBO request) {
|
|
|
ActivateGDTRequestBO requestBO = (ActivateGDTRequestBO) request;
|
|
|
log.info("activateUnion with param is{}",request);
|
|
|
//对url进行加密,拼接
|
|
|
String url = urlEode(requestBO);
|
|
|
|
|
|
MainUnionResponseBO response = null;
|
|
|
public UnionResponseBO activeUnion(ActivateUnionRequestBO request) {
|
|
|
UnionResponseBO response = check(request);
|
|
|
if (!response.getIsSuccess()) {
|
|
|
return response;
|
|
|
}
|
|
|
|
|
|
log.info("activateUnion with param is{}", request);
|
|
|
// 对url进行加密,拼接
|
|
|
String url = urlEode(request);
|
|
|
|
|
|
String msg = null;
|
|
|
String ret = null;
|
|
|
Pair<Integer, String> pair = HttpUtils.httpGet(url);
|
|
|
// Pair<Integer, String> pair = Pair.of(200, "{\"ret\":0,\"msg\":\"success\"}");
|
|
|
// Pair<Integer, String> pair = Pair.of(200,
|
|
|
// "{\"ret\":0,\"msg\":\"success\"}");
|
|
|
UnionLogs unionLogs = new UnionLogs();
|
|
|
unionLogs.setAppId(String.valueOf(requestBO.getAppid()));
|
|
|
unionLogs.setUdid(requestBO.getMuid());
|
|
|
unionLogs.setUnionType((byte) requestBO.getUnionType());
|
|
|
unionLogs.setActivateParams(JSON.toJSONString(requestBO));
|
|
|
//如果status是200,证明发送成功
|
|
|
if(pair.getLeft() == HttpStatus.SC_OK){
|
|
|
log.debug("url return message is {}",pair.getRight());
|
|
|
unionLogs.setAppId(String.valueOf(request.getAppid()));
|
|
|
unionLogs.setUdid("");
|
|
|
if (ClientTypeEnum.IOS.getName().equalsIgnoreCase(request.getClient_type())){
|
|
|
unionLogs.setIdfa(request.getIdfa());
|
|
|
}else{
|
|
|
unionLogs.setImei(request.getImei());
|
|
|
}
|
|
|
unionLogs.setUnionType((byte)UnionTypeEnum.GUANGDIANTONG.getValue());
|
|
|
unionLogs.setActivateParams(JSON.toJSONString(request));
|
|
|
// 如果status是200,证明发送成功
|
|
|
if (pair.getLeft() == HttpStatus.SC_OK) {
|
|
|
log.debug("url return message is {}", pair.getRight());
|
|
|
JSONObject json = JSONObject.parseObject(pair.getRight());
|
|
|
ret = json.getString("ret");
|
|
|
// msg = json.getString("msg");
|
|
|
// 广点通那边返回的msg是空,我们根据广点通的返回码获取msg
|
|
|
msg = MsgEnum.getNameByCode(ret);
|
|
|
//广点通返回成功
|
|
|
if(StringUtils.isNotEmpty(ret)&&"0".equals(ret)){
|
|
|
// 广点通返回成功
|
|
|
if (StringUtils.isNotEmpty(ret) && "0".equals(ret)) {
|
|
|
unionLogs.setIsActivate((byte) 1);
|
|
|
unionLogs.setCreateTime(DateUtil.getCurrentTimeSecond());
|
|
|
unionLogs.setUpdateTime(DateUtil.getCurrentTimeSecond());
|
|
|
log.debug("add to unionLogs db with param is {}", unionLogs);
|
|
|
response = new ActivateDingdangResponseBO(true, msg);
|
|
|
response = new UnionResponseBO(true, msg);
|
|
|
}
|
|
|
//广点通返回错误
|
|
|
else{
|
|
|
// 广点通返回错误
|
|
|
else {
|
|
|
unionLogs.setIsActivate((byte) 0);
|
|
|
unionLogs.setCreateTime(DateUtil.getCurrentTimeSecond());
|
|
|
unionLogs.setUpdateTime(DateUtil.getCurrentTimeSecond());
|
|
|
response = new ActivateDingdangResponseBO(false, msg);
|
|
|
}
|
|
|
}
|
|
|
else{
|
|
|
//激活失败
|
|
|
response = new UnionResponseBO(false, msg);
|
|
|
}
|
|
|
} else {
|
|
|
// 激活失败
|
|
|
unionLogs.setIsActivate((byte) 0);
|
|
|
unionLogs.setCreateTime(DateUtil.getCurrentTimeSecond());
|
|
|
unionLogs.setUpdateTime(DateUtil.getCurrentTimeSecond());
|
|
|
response = new ActivateDingdangResponseBO(false, "激活失败");
|
|
|
response = new UnionResponseBO(false, "激活失败");
|
|
|
}
|
|
|
unionLogsDAO.insert(unionLogs);
|
|
|
return response;
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 对url进行拼接,加密
|
|
|
*
|
|
|
* @param requestBO
|
|
|
* @return
|
|
|
*/
|
|
|
private static String urlEode(ActivateGDTRequestBO requestBO){
|
|
|
//加密密钥,在配置文件中定义
|
|
|
// String encrypt_key = "a9dc833b8a75c21f";
|
|
|
DynamicStringProperty encrypt_key = DynamicPropertyFactory.getInstance().getStringProperty("encrypt_key", "");
|
|
|
String encryptKey = encrypt_key.get();
|
|
|
//签名密钥,在配置文件中定义
|
|
|
// String sign_key = "bd80e4c0ecd5a150";
|
|
|
DynamicStringProperty sign_key = DynamicPropertyFactory.getInstance().getStringProperty("sign_key", "");
|
|
|
String signKey = sign_key.get();
|
|
|
private static String urlEode(ActivateUnionRequestBO requestBO) {
|
|
|
log.info("enter GDTServiceImpl.urlEode param{} is ", requestBO);
|
|
|
// 根据不同的应用类型,获取不同的加密密钥和签名密钥
|
|
|
String encryptKey = null;
|
|
|
String signKey = null;
|
|
|
String muid4MD5 = "";
|
|
|
if (ClientTypeEnum.IOS.getName().equalsIgnoreCase(requestBO.getClient_type())) {
|
|
|
DynamicStringProperty ios_encrypt_key = DynamicPropertyFactory.getInstance().getStringProperty("ios_encrypt_key", "");
|
|
|
encryptKey = ios_encrypt_key.get();
|
|
|
DynamicStringProperty ios_sign_key = DynamicPropertyFactory.getInstance().getStringProperty("ios_sign_key", "");
|
|
|
signKey = ios_sign_key.get();
|
|
|
muid4MD5 = requestBO.getIdfa();
|
|
|
} else {
|
|
|
DynamicStringProperty android_encrypt_key = DynamicPropertyFactory.getInstance().getStringProperty("android_encrypt_key", "");
|
|
|
encryptKey = android_encrypt_key.get();
|
|
|
DynamicStringProperty android_sign_key = DynamicPropertyFactory.getInstance().getStringProperty("android_sign_key", "");
|
|
|
signKey = android_sign_key.get();
|
|
|
muid4MD5 = requestBO.getImei();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 对设备id进行MD5加密,获取32位小写加密串
|
|
|
*/
|
|
|
String muid4MD5 = requestBO.getMuid();
|
|
|
|
|
|
String muid = MD5.md5(muid4MD5);
|
|
|
log.info("activateUnion muid is{}",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/";
|
|
|
String url = DynamicPropertyFactory.getInstance().getStringProperty("url", "").get();
|
|
|
int conv_time = requestBO.getConv_time();
|
|
|
String client_ip = requestBO.getClient_ip();
|
|
|
String url = DynamicPropertyFactory.getInstance().getStringProperty("guangdiantong.url", "").get();
|
|
|
int conv_time = DateUtil.getCurrentTimeSecond();
|
|
|
String client_ip = requestBO.getClientIp();
|
|
|
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();
|
|
|
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();
|
|
|
}
|
|
|
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();
|
|
|
} 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();
|
|
|
}
|
|
|
log.info("activateUnion url is{}",url4Encoude);
|
|
|
//对url进行加密
|
|
|
log.info("activateUnion url is{} ", url4Encoude);
|
|
|
// 对url进行加密
|
|
|
String urlEncoder = null;
|
|
|
try {
|
|
|
urlEncoder = URLEncoder.encode(url4Encoude,"UTF-8");
|
|
|
log.info("activateUnion urlEncoder is{}",urlEncoder);
|
|
|
urlEncoder = URLEncoder.encode(url4Encoude, "UTF-8");
|
|
|
log.info("activateUnion urlEncoder is{} ", urlEncoder);
|
|
|
} catch (UnsupportedEncodingException e) {
|
|
|
log.error("encode exception.", e);
|
|
|
}
|
|
|
//将签名密钥和提交方式与加密后的url进行拼接
|
|
|
}
|
|
|
// 将签名密钥和提交方式与加密后的url进行拼接
|
|
|
StringBuffer urlBuffer = new StringBuffer();
|
|
|
url=urlBuffer.append(signKey).append("&GET&").append(urlEncoder).toString();
|
|
|
//对url进行MD5加密,获取32位小写加密串
|
|
|
url = urlBuffer.append(signKey).append("&GET&").append(urlEncoder).toString();
|
|
|
// 对url进行MD5加密,获取32位小写加密串
|
|
|
String md5 = MD5.md5(url);
|
|
|
log.info("activateUnion md5 is{}",md5);
|
|
|
//参数组合,并进行加密
|
|
|
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();
|
|
|
log.info("activateUnion baseDate is {}",baseData);
|
|
|
|
|
|
//简单异或处理
|
|
|
String base64 = simpleXorByGdt(baseData,encryptKey);
|
|
|
//base64编码
|
|
|
String baseData = base.append(query_string).append("&sign=").append(md5).toString();
|
|
|
log.info("activateUnion baseDate is {} ", baseData);
|
|
|
|
|
|
// 简单异或处理
|
|
|
String base64 = simpleXorByGdt(baseData, encryptKey);
|
|
|
// base64编码
|
|
|
String ret = Base64.encodeBase64String(base64.getBytes());
|
|
|
//64位处理之后,防止里面有换行符
|
|
|
// 64位处理之后,防止里面有换行符
|
|
|
String retRep = ret.replaceAll("\n", "");
|
|
|
//将64位处理之后的值,按照url加密的方式进行加密
|
|
|
// 将64位处理之后的值,按照url加密的方式进行加密
|
|
|
try {
|
|
|
retRep = URLEncoder.encode(retRep,"UTF-8");
|
|
|
log.info("activateUnion retRep is{}",retRep);
|
|
|
retRep = URLEncoder.encode(retRep, "UTF-8");
|
|
|
log.info("activateUnion retRep is{}", retRep);
|
|
|
} catch (UnsupportedEncodingException e) {
|
|
|
log.error("encode exception.", e);
|
|
|
}
|
|
|
url = sb.append(DynamicPropertyFactory.getInstance().getStringProperty("url", "").get()).append(requestBO.getAppid()).append("/conv?v=").append(retRep)
|
|
|
.append("&conv_type=").append(requestBO.getConv_type())
|
|
|
.append("&app_type=").append(requestBO.getApp_type())
|
|
|
.append("&advertiser_id=").append(requestBO.getUid()).toString();
|
|
|
log.info("activateUnion url is {}",url);
|
|
|
// conv_type,,现在只有移动应用激活类型(MOBILEAPP_ACTIVITE);
|
|
|
String convType = "MOBILEAPP_ACTIVITE";
|
|
|
String uid = "1261905";
|
|
|
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(requestBO.getClient_type()).append("&advertiser_id=").append(uid).toString();
|
|
|
log.info("activateUnion url is {}", url);
|
|
|
return url;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 简单异或
|
|
|
*
|
|
|
* @param source
|
|
|
* @param key
|
|
|
* @return
|
...
|
...
|
@@ -229,8 +235,8 @@ public class GDTServiceImpl implements MainUnionService { |
|
|
int c1 = source.charAt(i);
|
|
|
int c2 = key.charAt(j);
|
|
|
|
|
|
result = result + (char)(c1 ^ c2);
|
|
|
j = j+1;
|
|
|
result = result + (char) (c1 ^ c2);
|
|
|
j = j + 1;
|
|
|
j = j % (key.length());
|
|
|
}
|
|
|
|
...
|
...
|
|