Toggle navigation
Toggle navigation
This project
Loading...
Sign in
YOHOBUY
/
yohobuy-union
·
Commits
Go to a project
GitLab
Go to group
Project
Activity
Files
Commits
Pipelines
0
Builds
0
Graphs
Milestones
Issues
0
Merge Requests
0
Members
Labels
Wiki
Forks
Network
Create a new issue
Download as
Email Patches
Plain Diff
Browse Files
Authored by
zhengwen.ge
9 years ago
Commit
dcc8b9f7b9f75f192a174ad0bc02ad07129bee95
1 parent
21330828
广点通需求
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
882 additions
and
5 deletions
common/src/main/java/com/yoho/unions/common/enums/UnionTypeEnum.java
dal/src/main/java/com/yoho/unions/dal/IUnionLogsDAO.java
dal/src/main/java/com/yoho/unions/dal/model/UnionLogs.java
dal/src/main/resources/META-INF/mybatis/UnionLogsMapper.xml
pom.xml
server/src/main/java/com/yoho/unions/server/service/impl/DingdangServiceImpl_OLD.java
server/src/main/java/com/yoho/unions/server/service/impl/GDTServiceImpl.java
web/src/main/resources/config.properties
web/src/main/resources/databases.yml
web/src/main/webapp/META-INF/autoconf/databases.yml
web/src/test/java/com/test/Test.java
common/src/main/java/com/yoho/unions/common/enums/UnionTypeEnum.java
View file @
dcc8b9f
package
com
.
yoho
.
unions
.
common
.
enums
;
import
com.yoho.service.model.union.request.ActivateDingdangRequestBO
;
import
com.yoho.service.model.union.request.ActivateGDTRequestBO
;
import
com.yoho.service.model.union.request.AddDingdangRequestBO
;
import
com.yoho.service.model.union.request.MainUnionRequestBO
;
...
...
@@ -14,8 +15,9 @@ import com.yoho.service.model.union.request.MainUnionRequestBO;
public
enum
UnionTypeEnum
{
DINGDANG
(
1
,
"dingdang"
,
"顶当互动"
,
"dingdangServiceImpl2"
,
AddDingdangRequestBO
.
class
,
ActivateDingdangRequestBO
.
class
),
DUOMENG
(
2
,
"duomeng"
,
"多盟"
,
"dingdangServiceImpl2"
,
AddDingdangRequestBO
.
class
,
ActivateDingdangRequestBO
.
class
),
DINGDANG
(
1
,
"dingdang"
,
"顶当互动"
,
"dingdangServiceImpl"
,
AddDingdangRequestBO
.
class
,
ActivateDingdangRequestBO
.
class
),
DUOMENG
(
2
,
"duomeng"
,
"多盟"
,
"dingdangServiceImpl"
,
AddDingdangRequestBO
.
class
,
ActivateDingdangRequestBO
.
class
),
GUANGDIANTONG
(
3
,
"guangdiantong"
,
"广点通"
,
"gdtServiceImpl"
,
ActivateGDTRequestBO
.
class
,
ActivateGDTRequestBO
.
class
),
;
private
int
value
;
...
...
dal/src/main/java/com/yoho/unions/dal/IUnionLogsDAO.java
0 → 100644
View file @
dcc8b9f
package
com
.
yoho
.
unions
.
dal
;
import
com.yoho.unions.dal.model.UnionLogs
;
public
interface
IUnionLogsDAO
{
int
deleteByPrimaryKey
(
Integer
id
);
int
insert
(
UnionLogs
record
);
int
insertSelective
(
UnionLogs
record
);
UnionLogs
selectByPrimaryKey
(
Integer
id
);
int
updateByPrimaryKeySelective
(
UnionLogs
record
);
int
updateByPrimaryKey
(
UnionLogs
record
);
}
...
...
dal/src/main/java/com/yoho/unions/dal/model/UnionLogs.java
0 → 100644
View file @
dcc8b9f
package
com
.
yoho
.
unions
.
dal
.
model
;
public
class
UnionLogs
{
private
Integer
id
;
private
String
appId
;
private
String
udid
;
private
String
idfa
;
private
Byte
isActivate
;
private
Byte
unionType
;
private
String
addParams
;
private
String
activateParams
;
private
Integer
createTime
;
private
Integer
updateTime
;
public
Integer
getId
()
{
return
id
;
}
public
void
setId
(
Integer
id
)
{
this
.
id
=
id
;
}
public
String
getAppId
()
{
return
appId
;
}
public
void
setAppId
(
String
appId
)
{
this
.
appId
=
appId
==
null
?
null
:
appId
.
trim
();
}
public
String
getUdid
()
{
return
udid
;
}
public
void
setUdid
(
String
udid
)
{
this
.
udid
=
udid
==
null
?
null
:
udid
.
trim
();
}
public
String
getIdfa
()
{
return
idfa
;
}
public
void
setIdfa
(
String
idfa
)
{
this
.
idfa
=
idfa
==
null
?
null
:
idfa
.
trim
();
}
public
Byte
getIsActivate
()
{
return
isActivate
;
}
public
void
setIsActivate
(
Byte
isActivate
)
{
this
.
isActivate
=
isActivate
;
}
public
Byte
getUnionType
()
{
return
unionType
;
}
public
void
setUnionType
(
Byte
unionType
)
{
this
.
unionType
=
unionType
;
}
public
String
getAddParams
()
{
return
addParams
;
}
public
void
setAddParams
(
String
addParams
)
{
this
.
addParams
=
addParams
==
null
?
null
:
addParams
.
trim
();
}
public
String
getActivateParams
()
{
return
activateParams
;
}
public
void
setActivateParams
(
String
activateParams
)
{
this
.
activateParams
=
activateParams
==
null
?
null
:
activateParams
.
trim
();
}
public
Integer
getCreateTime
()
{
return
createTime
;
}
public
void
setCreateTime
(
Integer
createTime
)
{
this
.
createTime
=
createTime
;
}
public
Integer
getUpdateTime
()
{
return
updateTime
;
}
public
void
setUpdateTime
(
Integer
updateTime
)
{
this
.
updateTime
=
updateTime
;
}
}
\ No newline at end of file
...
...
dal/src/main/resources/META-INF/mybatis/UnionLogsMapper.xml
0 → 100644
View file @
dcc8b9f
<?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.IUnionLogsDAO"
>
<resultMap
id=
"BaseResultMap"
type=
"com.yoho.unions.dal.model.UnionLogs"
>
<id
column=
"id"
property=
"id"
jdbcType=
"INTEGER"
/>
<result
column=
"app_id"
property=
"appId"
jdbcType=
"VARCHAR"
/>
<result
column=
"udid"
property=
"udid"
jdbcType=
"VARCHAR"
/>
<result
column=
"idfa"
property=
"idfa"
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"
/>
<result
column=
"activate_params"
property=
"activateParams"
jdbcType=
"VARCHAR"
/>
<result
column=
"create_time"
property=
"createTime"
jdbcType=
"INTEGER"
/>
<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
</sql>
<select
id=
"selectByPrimaryKey"
resultMap=
"BaseResultMap"
parameterType=
"java.lang.Integer"
>
select
<include
refid=
"Base_Column_List"
/>
from union_logs
where id = #{id,jdbcType=INTEGER}
</select>
<delete
id=
"deleteByPrimaryKey"
parameterType=
"java.lang.Integer"
>
delete from union_logs
where id = #{id,jdbcType=INTEGER}
</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)
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})
</insert>
<insert
id=
"insertSelective"
parameterType=
"com.yoho.unions.dal.model.UnionLogs"
>
insert into union_logs
<trim
prefix=
"("
suffix=
")"
suffixOverrides=
","
>
<if
test=
"id != null"
>
id,
</if>
<if
test=
"appId != null"
>
app_id,
</if>
<if
test=
"udid != null"
>
udid,
</if>
<if
test=
"idfa != null"
>
idfa,
</if>
<if
test=
"isActivate != null"
>
is_activate,
</if>
<if
test=
"unionType != null"
>
union_type,
</if>
<if
test=
"addParams != null"
>
add_params,
</if>
<if
test=
"activateParams != null"
>
activate_params,
</if>
<if
test=
"createTime != null"
>
create_time,
</if>
<if
test=
"updateTime != null"
>
update_time,
</if>
</trim>
<trim
prefix=
"values ("
suffix=
")"
suffixOverrides=
","
>
<if
test=
"id != null"
>
#{id,jdbcType=INTEGER},
</if>
<if
test=
"appId != null"
>
#{appId,jdbcType=VARCHAR},
</if>
<if
test=
"udid != null"
>
#{udid,jdbcType=VARCHAR},
</if>
<if
test=
"idfa != null"
>
#{idfa,jdbcType=VARCHAR},
</if>
<if
test=
"isActivate != null"
>
#{isActivate,jdbcType=TINYINT},
</if>
<if
test=
"unionType != null"
>
#{unionType,jdbcType=TINYINT},
</if>
<if
test=
"addParams != null"
>
#{addParams,jdbcType=VARCHAR},
</if>
<if
test=
"activateParams != null"
>
#{activateParams,jdbcType=VARCHAR},
</if>
<if
test=
"createTime != null"
>
#{createTime,jdbcType=INTEGER},
</if>
<if
test=
"updateTime != null"
>
#{updateTime,jdbcType=INTEGER},
</if>
</trim>
</insert>
<update
id=
"updateByPrimaryKeySelective"
parameterType=
"com.yoho.unions.dal.model.UnionLogs"
>
update union_logs
<set
>
<if
test=
"appId != null"
>
app_id = #{appId,jdbcType=VARCHAR},
</if>
<if
test=
"udid != null"
>
udid = #{udid,jdbcType=VARCHAR},
</if>
<if
test=
"idfa != null"
>
idfa = #{idfa,jdbcType=VARCHAR},
</if>
<if
test=
"isActivate != null"
>
is_activate = #{isActivate,jdbcType=TINYINT},
</if>
<if
test=
"unionType != null"
>
union_type = #{unionType,jdbcType=TINYINT},
</if>
<if
test=
"addParams != null"
>
add_params = #{addParams,jdbcType=VARCHAR},
</if>
<if
test=
"activateParams != null"
>
activate_params = #{activateParams,jdbcType=VARCHAR},
</if>
<if
test=
"createTime != null"
>
create_time = #{createTime,jdbcType=INTEGER},
</if>
<if
test=
"updateTime != null"
>
update_time = #{updateTime,jdbcType=INTEGER},
</if>
</set>
where id = #{id,jdbcType=INTEGER}
</update>
<update
id=
"updateByPrimaryKey"
parameterType=
"com.yoho.unions.dal.model.UnionLogs"
>
update union_logs
set app_id = #{appId,jdbcType=VARCHAR},
udid = #{udid,jdbcType=VARCHAR},
idfa = #{idfa,jdbcType=VARCHAR},
is_activate = #{isActivate,jdbcType=TINYINT},
union_type = #{unionType,jdbcType=TINYINT},
add_params = #{addParams,jdbcType=VARCHAR},
activate_params = #{activateParams,jdbcType=VARCHAR},
create_time = #{createTime,jdbcType=INTEGER},
update_time = #{updateTime,jdbcType=INTEGER}
where id = #{id,jdbcType=INTEGER}
</update>
</mapper>
\ No newline at end of file
...
...
pom.xml
View file @
dcc8b9f
...
...
@@ -5,7 +5,7 @@
<parent>
<groupId>
com.yoho
</groupId>
<artifactId>
parent
</artifactId>
<version>
1.0.
5
-SNAPSHOT
</version>
<version>
1.0.
6
-SNAPSHOT
</version>
</parent>
<groupId>
com.yoho.dsf
</groupId>
<artifactId>
yoho-unions
</artifactId>
...
...
server/src/main/java/com/yoho/unions/server/service/impl/DingdangServiceImpl_OLD.java
0 → 100644
View file @
dcc8b9f
package
com
.
yoho
.
unions
.
server
.
service
.
impl
;
import
javax.annotation.Resource
;
import
org.apache.commons.lang.StringUtils
;
import
org.apache.commons.lang3.tuple.Pair
;
import
org.apache.http.HttpStatus
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.stereotype.Service
;
import
com.alibaba.fastjson.JSONObject
;
import
com.netflix.config.DynamicIntProperty
;
import
com.netflix.config.DynamicPropertyFactory
;
import
com.yoho.core.cache.CacheClient
;
import
com.yoho.service.model.union.request.ActiveUnionRequestBO
;
import
com.yoho.service.model.union.request.AddUnionRequestBO
;
import
com.yoho.service.model.union.response.UnionResponseBO
;
import
com.yoho.unions.common.enums.SourceEnum
;
import
com.yoho.unions.common.utils.DateUtil
;
import
com.yoho.unions.common.utils.HttpUtils
;
import
com.yoho.unions.dal.IUnionsActiveRecordDAO
;
import
com.yoho.unions.dal.model.UnionsActiveRecord
;
import
com.yoho.unions.server.service.DingdangService
;
@Service
public
class
DingdangServiceImpl_OLD
implements
DingdangService
{
static
Logger
log
=
LoggerFactory
.
getLogger
(
DingdangServiceImpl_OLD
.
class
);
static
Logger
addDingdang
=
LoggerFactory
.
getLogger
(
"addDingdang"
);
static
Logger
activeDingdang
=
LoggerFactory
.
getLogger
(
"activeDingdang"
);
@Resource
CacheClient
cacheClient
;
@Resource
IUnionsActiveRecordDAO
unionsActiveRecordDAO
;
private
static
final
String
unions_KEY
=
"yh:unions:dingdang_"
;
@Override
public
UnionResponseBO
addUnion
(
AddUnionRequestBO
request
)
throws
Exception
{
log
.
debug
(
"addunions with param is {}"
,
request
);
UnionResponseBO
bo
=
new
UnionResponseBO
();
if
(
StringUtils
.
isEmpty
(
request
.
getApp
()))
{
log
.
warn
(
"addunions error app is null with param is {}"
,
request
);
bo
.
setIsSuccess
(
false
);
bo
.
setMsg
(
"APP IS NULL"
);
return
bo
;
// throw new ServiceException(ServiceError.APP_IS_NULL);
}
if
(
StringUtils
.
isEmpty
(
request
.
getUdid
()))
{
log
.
warn
(
"addunions error udid is null with param is {}"
,
request
);
bo
.
setIsSuccess
(
false
);
bo
.
setMsg
(
"UDID IS NULL"
);
return
bo
;
// throw new ServiceException(ServiceError.UDID_IS_NULL);
}
if
(
StringUtils
.
isEmpty
(
request
.
getCallbackurl
()))
{
log
.
warn
(
"addunions error callbackurl is null with param is {}"
,
request
);
bo
.
setIsSuccess
(
false
);
bo
.
setMsg
(
"CALLBACKURL IS NULL"
);
return
bo
;
// throw new ServiceException(ServiceError.CALLBACKURL_IS_NULL);
}
//检查memcached中是否已经有该udid
String
cacheUdid
=
cacheClient
.
get
(
unions_KEY
+
request
.
getApp
()
+
"_"
+
request
.
getUdid
(),
String
.
class
);
log
.
info
(
"addunions get cache key={}, cacheUdid={}"
,
unions_KEY
+
request
.
getApp
()
+
"_"
+
request
.
getUdid
(),
cacheUdid
);
if
(
StringUtils
.
isNotEmpty
(
cacheUdid
))
{
log
.
warn
(
"addunions error app and udid is added with param is {}"
,
request
);
bo
.
setIsSuccess
(
false
);
bo
.
setMsg
(
"APP UDID IS EXISTS"
);
return
bo
;
// throw new ServiceException(ServiceError.APP_UDID_IS_EXISTS);
}
//保存到memcached,时间,一个小时
DynamicIntProperty
activeTime
=
DynamicPropertyFactory
.
getInstance
().
getIntProperty
(
"activeTime"
,
60
*
60
);
cacheClient
.
set
(
unions_KEY
+
request
.
getApp
()
+
"_"
+
request
.
getUdid
(),
activeTime
.
get
(),
request
.
getUdid
());
log
.
debug
(
"addunions set cache success"
);
//插入数据库
try
{
UnionsActiveRecord
unions
=
new
UnionsActiveRecord
();
unions
.
setApp
(
request
.
getApp
());
unions
.
setUdid
(
request
.
getUdid
());
unions
.
setCallbackurl
(
request
.
getCallbackurl
());
unions
.
setType
(
request
.
getType
());
log
.
debug
(
"add to unionsLog db with param is {}"
,
unions
);
unionsActiveRecordDAO
.
insert
(
unions
);
}
catch
(
Exception
e
)
{
log
.
error
(
""
,
e
);
}
log
.
info
(
"addunions success with param is {}"
,
request
);
addDingdang
.
info
(
"addunions success with param is {}"
,
request
);
bo
.
setMsg
(
"成功"
);
bo
.
setIsSuccess
(
true
);
return
bo
;
}
@Override
public
UnionResponseBO
activeUnion
(
ActiveUnionRequestBO
request
)
throws
Exception
{
log
.
debug
(
"activeunions with param is {}"
,
request
);
UnionResponseBO
bo
=
new
UnionResponseBO
();
if
(
StringUtils
.
isEmpty
(
request
.
getAppid
()))
{
log
.
warn
(
"activeunions error app is null with param is {}"
,
request
);
bo
.
setIsSuccess
(
false
);
bo
.
setMsg
(
"APP IS NULL"
);
return
bo
;
//throw new ServiceException(500, "APP_IS_NULL");
}
if
(
StringUtils
.
isEmpty
(
request
.
getUdid
()))
{
log
.
warn
(
"activeunions error udid is null with param is {}"
,
request
);
bo
.
setIsSuccess
(
false
);
bo
.
setMsg
(
"UDID IS NULL"
);
return
bo
;
// throw new ServiceException(500, "UDID_IS_NULL");
}
String
memKey
=
unions_KEY
+
request
.
getAppid
()
+
"_"
+
request
.
getUdid
();
//检查memcached中是否已经有该udid
String
cacheUdid
=
cacheClient
.
get
(
memKey
,
String
.
class
);
log
.
info
(
"activeUnion get cache key={}, cacheUdid={}"
,
memKey
,
cacheUdid
);
if
(
StringUtils
.
isEmpty
(
cacheUdid
))
{
log
.
warn
(
"activeunions error app and udid is not exists with param is {}"
,
request
);
bo
.
setIsSuccess
(
false
);
bo
.
setMsg
(
"APP UDID IS NOT EXISTS IN CACHE"
);
return
bo
;
}
//检查该app和udid是否已经激活
UnionsActiveRecord
unions
=
new
UnionsActiveRecord
();
unions
.
setApp
(
request
.
getAppid
());
unions
.
setUdid
(
request
.
getUdid
());
unions
.
setType
(
request
.
getApptype
());
UnionsActiveRecord
u
=
unionsActiveRecordDAO
.
selectByUdidAndApp
(
unions
);
if
(
u
==
null
)
{
log
.
warn
(
"activeunions error app and udid is not exists with param is {}"
,
request
);
bo
.
setIsSuccess
(
false
);
bo
.
setMsg
(
"database has not exists this udid but cache exists"
);
return
bo
;
}
//已经激活
if
(
"1"
.
equals
(
u
.
getIsActive
()))
{
log
.
warn
(
"activeunions error app is actived with param is {}"
,
request
);
bo
.
setIsSuccess
(
false
);
bo
.
setMsg
(
"app udid had actived"
);
return
bo
;
}
//调用联盟激活接口
int
repeatCount
=
0
;
Pair
<
Integer
,
String
>
pair
=
null
;
JSONObject
json
=
null
;
boolean
isSuccess
=
false
;
String
url
=
""
;
while
(
true
)
{
//如果已经成功,或者重试次数大于3次,则不再调用
if
(
isSuccess
||
repeatCount
>=
3
)
{
break
;
}
try
{
url
=
u
.
getCallbackurl
();
pair
=
HttpUtils
.
httpGet
(
url
);
if
(
pair
.
getLeft
()
==
HttpStatus
.
SC_OK
)
{
log
.
debug
(
"call "
+
u
.
getCallbackurl
()
+
" url success return message is {}"
,
pair
.
getRight
());
json
=
JSONObject
.
parseObject
(
pair
.
getRight
());
isSuccess
=
json
.
getBooleanValue
(
"isSuccess"
);
}
}
catch
(
Exception
e
)
{
log
.
error
(
""
,
e
);
}
repeatCount
++;
}
log
.
info
(
"call "
+
u
.
getCallbackurl
()
+
" url return message is {}"
,
pair
.
getRight
());
//更新数据库
if
(
isSuccess
)
{
unions
.
setIsActive
(
"1"
);
unions
.
setId
(
u
.
getId
());
unionsActiveRecordDAO
.
updateByPrimaryKey
(
unions
);
//激活成功,从memcached中删除
cacheClient
.
delete
(
memKey
);
log
.
debug
(
"activeUnion delete cache success key={}"
,
memKey
);
bo
.
setMsg
(
"激活成功"
);
bo
.
setIsSuccess
(
true
);
}
else
{
unions
.
setIsActive
(
"0"
);
unions
.
setId
(
u
.
getId
());
unionsActiveRecordDAO
.
updateByPrimaryKey
(
unions
);
bo
.
setMsg
(
"激活失败"
);
bo
.
setIsSuccess
(
false
);
}
try
{
//组装大数据分析的日志
JSONObject
j
=
new
JSONObject
();
j
.
put
(
"apptype"
,
request
.
getApptype
());
j
.
put
(
"appid"
,
request
.
getAppid
());
j
.
put
(
"udid"
,
request
.
getUdid
());
j
.
put
(
"dateid"
,
DateUtil
.
getcurrentDateTime
());
SourceEnum
e
=
SourceEnum
.
getSourceEnumByValue
(
u
.
getType
());
j
.
put
(
"source"
,
e
==
null
?
""
:
e
.
getName
());
j
.
put
(
"ip"
,
request
.
getClientIP
());
j
.
put
(
"collect_ip"
,
""
);
activeDingdang
.
info
(
j
.
toString
());
}
catch
(
Exception
e
)
{
log
.
error
(
""
,
e
);
}
return
bo
;
}
}
...
...
server/src/main/java/com/yoho/unions/server/service/impl/GDTServiceImpl.java
0 → 100644
View file @
dcc8b9f
package
com
.
yoho
.
unions
.
server
.
service
.
impl
;
import
java.io.UnsupportedEncodingException
;
import
java.net.URLEncoder
;
import
javax.annotation.Resource
;
import
org.apache.commons.codec.binary.Base64
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.lang3.tuple.Pair
;
import
org.apache.http.HttpStatus
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.stereotype.Service
;
import
com.alibaba.fastjson.JSON
;
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.unions.common.utils.DateUtil
;
import
com.yoho.unions.common.utils.HttpUtils
;
import
com.yoho.unions.dal.IUnionLogsDAO
;
import
com.yoho.unions.dal.model.UnionLogs
;
import
com.yoho.unions.server.service.MainUnionService
;
/**
* 广点通接口
* @author yoho
*
*/
@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
)
{
// 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"
);
}
if
(
requestBO
.
getUid
()==
0
){
log
.
warn
(
"activateUnionCheck error because uid is{}"
,
requestBO
.
getUid
());
return
new
ActivateGDTResponseBO
(
false
,
"uid is null"
);
}
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
(
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
(
StringUtils
.
isEmpty
(
requestBO
.
getMuid
()))
{
log
.
warn
(
"activateUnionCheck error becauls muid is{}"
,
requestBO
.
getMuid
());
return
new
ActivateGDTResponseBO
(
false
,
"muid is null"
);
}
return
new
ActivateGDTResponseBO
();
}
@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
;
String
msg
=
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(400, "{\"ret\":-1,\"msg\":\"请求非法参数\"}");
// Pair<Integer, String> pair = Pair.of(789, "adsfasdfasd");
UnionLogs
unionLogs
=
new
UnionLogs
();
unionLogs
.
setAppId
(
String
.
valueOf
(
requestBO
.
getAppid
()));
unionLogs
.
setUdid
(
requestBO
.
getMuid
());
unionLogs
.
setUnionType
((
byte
)
requestBO
.
getUnionType
());
unionLogs
.
setActivateParams
(
JSON
.
toJSONString
(
requestBO
));
if
(
pair
.
getLeft
()
==
HttpStatus
.
SC_OK
){
log
.
debug
(
"url return message is {}"
,
pair
.
getRight
());
//激活成功
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
,
"成功"
);
}
else
{
//激活失败
unionLogs
.
setIsActivate
((
byte
)
0
);
unionLogs
.
setCreateTime
(
DateUtil
.
getCurrentTimeSecond
());
unionLogs
.
setUpdateTime
(
DateUtil
.
getCurrentTimeSecond
());
JSONObject
json
=
JSONObject
.
parseObject
(
pair
.
getRight
());
msg
=
json
.
getString
(
"msg"
);
response
=
new
ActivateDingdangResponseBO
(
false
,
msg
);
}
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
();
/**
* 对设备id进行MD5加密,获取32位小写加密串
*/
String
muid4MD5
=
requestBO
.
getMuid
();
String
muid
=
MD5
.
md5
(
muid4MD5
);
log
.
info
(
"activateUnion muid is{}"
,
muid
);
/**
* 对url进行拼接,并进行加密
*/
// 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
();
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
();
}
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进行加密
String
urlEncoder
=
null
;
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
();
//对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
();
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
);
}
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
);
return
url
;
}
/**
* 简单异或
* @param source
* @param key
* @return
*/
private
static
String
simpleXorByGdt
(
String
source
,
String
key
)
{
String
result
=
""
;
int
j
=
0
;
for
(
int
i
=
0
;
i
<
source
.
length
();
i
++)
{
int
c1
=
source
.
charAt
(
i
);
int
c2
=
key
.
charAt
(
j
);
result
=
result
+
(
char
)(
c1
^
c2
);
j
=
j
+
1
;
j
=
j
%
(
key
.
length
());
}
return
result
;
}
}
...
...
web/src/main/resources/config.properties
View file @
dcc8b9f
...
...
@@ -26,4 +26,12 @@ redis.proxy.auth=
web.context
=
union
#元宵节抽签活动,定时写文件的周期(分)
draw.writeFile.delay
=
1
\ No newline at end of file
draw.writeFile.delay
=
1
#广点通 加密密钥
encrypt_key
=
a9dc833b8a75c21f
#广点通 签名密钥
sign_key
=
bd80e4c0ecd5a150
#广点通 url
url
=
http://t.gdt.qq.com/conv/app/
\ No newline at end of file
...
...
web/src/main/resources/databases.yml
View file @
dcc8b9f
...
...
@@ -6,4 +6,12 @@ datasources:
username
:
yh_test
password
:
9nm0icOwt6bMHjMusIfMLw==
yohobuy_logs
:
servers
:
-
192.168.50.69:9980
-
192.168.102.219:3306
username
:
yh_test
password
:
9nm0icOwt6bMHjMusIfMLw==
daos
:
-
com.yoho.unions.dal.IUnionLogsDAO
readOnlyInSlave
:
true
\ No newline at end of file
...
...
web/src/main/webapp/META-INF/autoconf/databases.yml
View file @
dcc8b9f
...
...
@@ -4,4 +4,11 @@ datasources:
-
${jdbc.mysql.yohopassport.master}
-
${jdbc.mysql.yohopassport.slave}
username
:
${jdbc.mysql.yohopassport.username}
password
:
${jdbc.mysql.yohopassport.password}
\ No newline at end of file
password
:
${jdbc.mysql.yohopassport.password}
yohobuy_logs
:
servers
:
-
${jdbc.mysql.yohobuylogs.master}
-
${jdbc.mysql.yohobuylogs.slave}
username
:
${jdbc.mysql.yohobuylogs.username}
password
:
${jdbc.mysql.yohobuylogs.password}
...
...
web/src/test/java/com/test/Test.java
0 → 100644
View file @
dcc8b9f
package
com
.
test
;
import
java.io.UnsupportedEncodingException
;
import
java.net.URLEncoder
;
import
org.apache.commons.codec.binary.Base64
;
import
org.apache.commons.lang3.StringUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
com.netflix.config.DynamicPropertyFactory
;
import
com.netflix.config.DynamicStringProperty
;
import
com.yoho.core.common.utils.MD5
;
import
com.yoho.unions.server.service.impl.GDTServiceImpl
;
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
);
/**
* 对设备id进行MD5加密,获取32位小写加密串
*/
String
muid4MD5
=
"354649050046412"
;
String
muid
=
MD5
.
md5
(
muid4MD5
);
muid
=
"0f074dc8e1f0547310e729032ac0730b"
;
System
.
out
.
println
(
muid
);
/**
* 对url进行拼接,并进行加密
*/
String
url
=
"http://t.gdt.qq.com/conv/app/"
;
int
conv_time
=
1422263664
;
String
client_ip
=
"10.11.12.13"
;
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
();
}
System
.
out
.
println
(
"url4Encoude: "
+
url4Encoude
);
System
.
out
.
println
(
"query_string: "
+
query_string
);
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
();
}
}
/**
* 简单异或
* @param source
* @param key
* @return
*/
private
static
String
simpleXorByGdt
(
String
source
,
String
key
)
{
String
result
=
""
;
int
j
=
0
;
for
(
int
i
=
0
;
i
<
source
.
length
();
i
++)
{
int
c1
=
source
.
charAt
(
i
);
int
c2
=
key
.
charAt
(
j
);
result
=
result
+
(
char
)(
c1
^
c2
);
j
=
j
+
1
;
j
=
j
%
(
key
.
length
());
}
return
result
;
}
}
...
...
Please
register
or
login
to post a comment