Authored by zhengwen.ge

update

... ... @@ -26,10 +26,11 @@ public class UnionConstant {
static {
//andriod系统
andriodServiceList.add("gdtServiceImpl");
//iSO系统
iOSServiceList.add("dDServiceImpl");
iOSServiceList.add("gdtServiceImpl");
}
}
... ...
package com.yoho.unions.common.enums;
public enum ClientTypeEnum {
IOS("ios"),
ANDROID("android");
private String name;
public String getName() {
return name;
}
private ClientTypeEnum(String name) {
this.name = name;
}
}
... ...
... ... @@ -8,6 +8,8 @@ public class UnionLogs {
private String udid;
private String idfa;
private String imei;
private Byte isActivate;
... ... @@ -53,7 +55,15 @@ public class UnionLogs {
this.idfa = idfa == null ? null : idfa.trim();
}
public Byte getIsActivate() {
public String getImei() {
return imei;
}
public void setImei(String imei) {
this.imei = imei;
}
public Byte getIsActivate() {
return isActivate;
}
... ...
... ... @@ -6,6 +6,7 @@
<result column="app_id" property="appId" jdbcType="VARCHAR" />
<result column="udid" property="udid" jdbcType="VARCHAR" />
<result column="idfa" property="idfa" jdbcType="VARCHAR" />
<result column="imei" property="imei" jdbcType="VARCHAR" />
<result column="is_activate" property="isActivate" jdbcType="TINYINT" />
<result column="union_type" property="unionType" jdbcType="TINYINT" />
<result column="add_params" property="addParams" jdbcType="VARCHAR" />
... ... @@ -14,8 +15,8 @@
<result column="update_time" property="updateTime" jdbcType="INTEGER" />
</resultMap>
<sql id="Base_Column_List" >
id, app_id, udid, idfa, is_activate, union_type, add_params, activate_params, create_time,
update_time
id, app_id, udid, idfa, imei, is_activate, union_type, add_params, activate_params,
create_time, update_time
</sql>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
select
... ... @@ -29,13 +30,13 @@
</delete>
<insert id="insert" parameterType="com.yoho.unions.dal.model.UnionLogs" >
insert into union_logs (id, app_id, udid,
idfa, is_activate, union_type,
add_params, activate_params, create_time,
update_time)
idfa, imei, is_activate,
union_type, add_params, activate_params,
create_time, update_time)
values (#{id,jdbcType=INTEGER}, #{appId,jdbcType=VARCHAR}, #{udid,jdbcType=VARCHAR},
#{idfa,jdbcType=VARCHAR}, #{isActivate,jdbcType=TINYINT}, #{unionType,jdbcType=TINYINT},
#{addParams,jdbcType=VARCHAR}, #{activateParams,jdbcType=VARCHAR}, #{createTime,jdbcType=INTEGER},
#{updateTime,jdbcType=INTEGER})
#{idfa,jdbcType=VARCHAR}, #{imei,jdbcType=VARCHAR}, #{isActivate,jdbcType=TINYINT},
#{unionType,jdbcType=TINYINT}, #{addParams,jdbcType=VARCHAR}, #{activateParams,jdbcType=VARCHAR},
#{createTime,jdbcType=INTEGER}, #{updateTime,jdbcType=INTEGER})
</insert>
<insert id="insertSelective" parameterType="com.yoho.unions.dal.model.UnionLogs" >
insert into union_logs
... ... @@ -52,6 +53,9 @@
<if test="idfa != null" >
idfa,
</if>
<if test="imei != null" >
imei,
</if>
<if test="isActivate != null" >
is_activate,
</if>
... ... @@ -84,6 +88,9 @@
<if test="idfa != null" >
#{idfa,jdbcType=VARCHAR},
</if>
<if test="imei != null" >
#{imei,jdbcType=VARCHAR},
</if>
<if test="isActivate != null" >
#{isActivate,jdbcType=TINYINT},
</if>
... ... @@ -116,6 +123,9 @@
<if test="idfa != null" >
idfa = #{idfa,jdbcType=VARCHAR},
</if>
<if test="imei != null" >
imei = #{imei,jdbcType=VARCHAR},
</if>
<if test="isActivate != null" >
is_activate = #{isActivate,jdbcType=TINYINT},
</if>
... ... @@ -142,6 +152,7 @@
set app_id = #{appId,jdbcType=VARCHAR},
udid = #{udid,jdbcType=VARCHAR},
idfa = #{idfa,jdbcType=VARCHAR},
imei = #{imei,jdbcType=VARCHAR},
is_activate = #{isActivate,jdbcType=TINYINT},
union_type = #{unionType,jdbcType=TINYINT},
add_params = #{addParams,jdbcType=VARCHAR},
... ...
... ... @@ -17,6 +17,7 @@ import com.yoho.service.model.union.request.ActivateUnionRequestBO;
import com.yoho.service.model.union.request.ActivateUnionRequestVO;
import com.yoho.service.model.union.response.ActiveUnionResponseBO;
import com.yoho.unions.common.constant.UnionConstant;
import com.yoho.unions.common.enums.ClientTypeEnum;
import com.yoho.unions.common.utils.SpringContextUtil;
import com.yoho.unions.server.service.MainUnionService;
... ... @@ -44,31 +45,38 @@ public class ActivateUnionRest {
log.info("addUnion with param is {}", vo);
ActivateUnionRequestBO bo = new ActivateUnionRequestBO();
BeanUtils.copyProperties(vo, bo);
String clientType = vo.getClient_type();
if (!ClientTypeEnum.ANDROID.getName().equalsIgnoreCase(clientType) && !ClientTypeEnum.IOS.getName().equalsIgnoreCase(clientType)) {
log.warn("activateUnion error with param is {}", vo);
return new ActiveUnionResponseBO(600, "error");
}
//多线程处理
exe.execute(new Runnable() {
@Override
public void run() {
MainUnionService service = null;
//处理安卓的服务
for (String str : UnionConstant.andriodServiceList) {
//捕获异常,不影响后面的联盟
try {
service = SpringContextUtil.getBean(str, MainUnionService.class);
service.activeUnion(bo);
} catch (Exception e) {
log.warn("addUnion error with param is {}", vo);
if (ClientTypeEnum.ANDROID.getName().equalsIgnoreCase(clientType)) {
//处理安卓的服务
for (String str : UnionConstant.andriodServiceList) {
//捕获异常,不影响后面的联盟
try {
service = SpringContextUtil.getBean(str, MainUnionService.class);
service.activeUnion(bo);
} catch (Exception e) {
log.warn("addUnion error with param is {}", vo);
}
}
}
//处理iOS的服务
for (String str : UnionConstant.iOSServiceList) {
//捕获异常,不影响后面的联盟
try {
service = SpringContextUtil.getBean(str, MainUnionService.class);
service.activeUnion(bo);
} catch (Exception e) {
log.warn("addUnion error with param is {}", vo);
} else if (ClientTypeEnum.IOS.getName().equalsIgnoreCase(clientType)) {
//处理iOS的服务
for (String str : UnionConstant.iOSServiceList) {
//捕获异常,不影响后面的联盟
try {
service = SpringContextUtil.getBean(str, MainUnionService.class);
service.activeUnion(bo);
} catch (Exception e) {
log.warn("addUnion error with param is {}", vo);
}
}
}
}
... ...
... ... @@ -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());
}
... ...
... ... @@ -28,10 +28,14 @@ web.context=union
#元宵节抽签活动,定时写文件的周期(分)
draw.writeFile.delay=1
#广点通 加密密钥
encrypt_key=a9dc833b8a75c21f
#广点通 签名密钥
sign_key=bd80e4c0ecd5a150
#广点通 ios加密密钥
ios_encrypt_key=a9dc833b8a75c21f
#广点通 ios签名密钥
ios_sign_key=bd80e4c0ecd5a150
#广点通 android加密密钥
android_encrypt_key=BAAAAAAAAAAAE0FR
#广点通 android签名密钥
android_sign_key=d43ef6ef894e3c56
#广点通 url
url=http://t.gdt.qq.com/conv/app/
\ No newline at end of file
guangdiantong.url=http://t.gdt.qq.com/conv/app/
\ No newline at end of file
... ...
... ... @@ -28,4 +28,17 @@ redis.readonly.proxy.auth=${redis.readonly.proxy.auth}
web.context=union
#元宵节抽签活动,定时写文件的周期(分)
draw.writeFile.delay=${draw.writeFile.delay}
\ No newline at end of file
draw.writeFile.delay=${draw.writeFile.delay}
#广点通 ios加密密钥
ios_encrypt_key=a9dc833b8a75c21f
#广点通 ios签名密钥
ios_sign_key=bd80e4c0ecd5a150
#广点通 android加密密钥
android_encrypt_key=BAAAAAAAAAAAE0FR
#广点通 android签名密钥
android_sign_key=d43ef6ef894e3c56
#广点通 url
guangdiantong.url=http://t.gdt.qq.com/conv/app/
\ No newline at end of file
... ...