Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
jinli gu
Jeepay
Commits
eb533493
Commit
eb533493
authored
Sep 10, 2017
by
jmdhappy
Browse files
提交dubbo版本
parent
ddae755c
Changes
56
Hide whitespace changes
Inline
Side-by-side
pom.xml
View file @
eb533493
...
@@ -16,6 +16,7 @@
...
@@ -16,6 +16,7 @@
<module>
xxpay-mgr
</module>
<module>
xxpay-mgr
</module>
<module>
xxpay-shop
</module>
<module>
xxpay-shop
</module>
<module>
xxpay4spring-cloud
</module>
<module>
xxpay4spring-cloud
</module>
<module>
xxpay4dubbo
</module>
</modules>
</modules>
<properties>
<properties>
...
...
xxpay-common/pom.xml
View file @
eb533493
...
@@ -11,10 +11,14 @@
...
@@ -11,10 +11,14 @@
<description>
xxpay-common
</description>
<description>
xxpay-common
</description>
<properties>
<properties>
<project.build.sourceEncoding>
UTF-8
</project.build.sourceEncoding>
<java.version>
1.8
</java.version>
<fastjson.version>
1.2.7
</fastjson.version>
<fastjson.version>
1.2.7
</fastjson.version>
<logback-classic.version>
1.1.7
</logback-classic.version>
<logback-classic.version>
1.1.7
</logback-classic.version>
<slf4j-api.version>
1.7.7
</slf4j-api.version>
<slf4j-api.version>
1.7.7
</slf4j-api.version>
<commons-lang3.version>
3.4
</commons-lang3.version>
<commons-lang3.version>
3.5
</commons-lang3.version>
<commons.beanutils.version>
1.7.0
</commons.beanutils.version>
<commons.collections.version>
3.2.2
</commons.collections.version>
</properties>
</properties>
<dependencies>
<dependencies>
...
@@ -43,6 +47,16 @@
...
@@ -43,6 +47,16 @@
<artifactId>
commons-lang3
</artifactId>
<artifactId>
commons-lang3
</artifactId>
<version>
${commons-lang3.version}
</version>
<version>
${commons-lang3.version}
</version>
</dependency>
</dependency>
<dependency>
<groupId>
commons-beanutils
</groupId>
<artifactId>
commons-beanutils
</artifactId>
<version>
${commons.beanutils.version}
</version>
</dependency>
<dependency>
<groupId>
commons-collections
</groupId>
<artifactId>
commons-collections
</artifactId>
<version>
${commons.collections.version}
</version>
</dependency>
</dependencies>
</dependencies>
<build>
<build>
...
...
xxpay-common/src/main/java/org/xxpay/common/constant/Constant.java
0 → 100644
View file @
eb533493
package
org.xxpay.common.constant
;
/**
* Created by admin on 2016/4/27.
*/
public
class
Constant
{
// 账户业务模块流水号前缀(account)
public
static
final
String
AC_BIZ_SEQUENCE_NO_PREFIX
=
"ac"
;
// 账户业务模块流水号前缀(config)
public
static
final
String
CF_BIZ_SEQUENCE_NO_PREFIX
=
"cf"
;
// 账户业务模块流水号前缀(metadata)
public
static
final
String
MD_BIZ_SEQUENCE_NO_PREFIX
=
"md"
;
public
static
final
String
ME_BIZ_SEQUENCE_NO_PREFIX
=
"me"
;
// 认证业务模块流水号前缀(auth)
public
static
final
String
AU_BIZ_SEQUENCE_NO_PREFIX
=
"au"
;
// 交易业务模块流水号前缀(trans)
public
static
final
String
TRANS_BIZ_SEQUENCE_NO_PREFIX
=
"tn"
;
// 日志业务模块流水号前缀(log)
public
static
final
String
LG_BIZ_SEQUENCE_NO_PREFIX
=
"lg"
;
// zookeeper监控业务模块流水号前缀(zk)
public
static
final
String
ZK_BIZ_SEQUENCE_NO_PREFIX
=
"zk"
;
// 朋友圈流水号前缀(moments)
public
static
final
String
MM_BIZ_SEQUENCE_NO_PREFIX
=
"mm"
;
// 背包流水号前缀(pack)
public
static
final
String
PK_BIZ_SEQUENCE_NO_PREFIX
=
"pk"
;
// 随机通讯码不重复的时间间隔(ms)
public
static
final
long
RPC_SEQ_NO_NOT_REPEAT_INTERVAL
=
5
*
1000
;
// 服务端返回map中业务数据结果对应的key名称
public
static
final
String
BIZ_RESULT_KEY
=
"bizResult"
;
}
xxpay-common/src/main/java/org/xxpay/common/domain/BaseParam.java
0 → 100644
View file @
eb533493
package
org.xxpay.common.domain
;
import
org.apache.commons.lang3.StringUtils
;
import
org.xxpay.common.enumm.RpcSignTypeEnum
;
import
org.xxpay.common.util.*
;
import
java.util.*
;
/**
* Created by admin on 2016/7/11.
*/
public
class
BaseParam
extends
RpcBaseParam
{
private
Map
<
String
,
Object
>
bizParamMap
;
public
BaseParam
()
{}
/**
* 不需要业务签名的构造器
* @param rpcSrcSysId
* @param rpcSignKey
* @param bizSeqNoPrefix
*/
public
BaseParam
(
String
rpcSrcSysId
,
String
rpcSignKey
,
String
bizSeqNoPrefix
)
{
super
.
rpcSrcSysId
=
rpcSrcSysId
;
super
.
rpcDateTime
=
DateUtils
.
getCurrentTimeStrDefault
();
super
.
rpcSeqNo
=
RandomStrUtils
.
getInstance
().
getRandomString
();
super
.
rpcSignType
=
RpcSignTypeEnum
.
SHA1_SIGN
.
getCode
();
super
.
bizSeqNo
=
BizSequenceUtils
.
getInstance
().
generateBizSeqNo
(
bizSeqNoPrefix
);
StringBuffer
decriptBuffer
=
new
StringBuffer
();
decriptBuffer
.
append
(
rpcSignKey
)
.
append
(
super
.
rpcSrcSysId
)
.
append
(
super
.
rpcDateTime
)
.
append
(
super
.
rpcSignType
)
.
append
(
super
.
bizSeqNo
);
super
.
rpcSign
=
RpcSignUtils
.
sha1
(
decriptBuffer
.
toString
());
this
.
bizParamMap
=
new
HashMap
<
String
,
Object
>();
}
/**
* 需要业务签名的构造器
* @param rpcSrcSysId
* @param rpcSignKey
* @param bizSeqNoPrefix
* @param bizSign
*/
public
BaseParam
(
String
rpcSrcSysId
,
String
rpcSignKey
,
String
bizSeqNoPrefix
,
String
bizSign
)
{
super
.
rpcSrcSysId
=
rpcSrcSysId
;
super
.
rpcDateTime
=
DateUtils
.
getCurrentTimeStrDefault
();
super
.
rpcSeqNo
=
RandomStrUtils
.
getInstance
().
getRandomString
();
super
.
rpcSignType
=
RpcSignTypeEnum
.
SHA1_SIGN
.
getCode
();
super
.
bizSeqNo
=
BizSequenceUtils
.
getInstance
().
generateBizSeqNo
(
bizSeqNoPrefix
);
super
.
bizSign
=
bizSign
;
StringBuffer
decriptBuffer
=
new
StringBuffer
();
decriptBuffer
.
append
(
rpcSignKey
)
.
append
(
super
.
rpcSrcSysId
)
.
append
(
super
.
rpcDateTime
)
.
append
(
super
.
rpcSignType
)
.
append
(
super
.
bizSeqNo
)
.
append
(
super
.
bizSign
);
super
.
rpcSign
=
RpcSignUtils
.
sha1
(
decriptBuffer
.
toString
());
this
.
bizParamMap
=
new
HashMap
<
String
,
Object
>();
}
public
Map
<
String
,
Object
>
getBizParamMap
()
{
return
bizParamMap
;
}
public
void
setBizParamMap
(
Map
<
String
,
Object
>
bizParamMap
)
{
this
.
bizParamMap
=
bizParamMap
;
}
public
String
toJson
()
{
return
JsonUtil
.
object2Json
(
this
);
}
@Override
public
String
toString
()
{
final
StringBuffer
sb
=
new
StringBuffer
(
"BaseParam{"
);
sb
.
append
(
"rpcSrcSysId='"
).
append
(
rpcSrcSysId
).
append
(
'\''
);
sb
.
append
(
", rpcDateTime='"
).
append
(
rpcDateTime
).
append
(
'\''
);
sb
.
append
(
", rpcSeqNo='"
).
append
(
rpcSeqNo
).
append
(
'\''
);
sb
.
append
(
", rpcSignType="
).
append
(
rpcSignType
);
sb
.
append
(
", rpcSign='"
).
append
(
rpcSign
).
append
(
'\''
);
sb
.
append
(
", bizSeqNo='"
).
append
(
bizSeqNo
).
append
(
'\''
);
sb
.
append
(
", bizSign='"
).
append
(
bizSign
).
append
(
'\''
);
sb
.
append
(
", bizParamMap="
).
append
(
bizParamMap
);
sb
.
append
(
'}'
);
return
sb
.
toString
();
}
public
boolean
isNullValue
(
String
key
)
{
Object
objValue
=
this
.
bizParamMap
.
get
(
key
);
return
objValue
==
null
||
StringUtils
.
isBlank
(
objValue
.
toString
());
}
/**
* 判断bizParamMap中的参数是否全部为空,是则返回true,否则返回false
* @param excludeKeys
* @return
*/
public
boolean
isInvalidMapValue
(
Object
...
excludeKeys
)
{
if
(
this
.
bizParamMap
==
null
||
this
.
bizParamMap
.
isEmpty
())
{
return
true
;
}
List
<
Object
>
list
=
Arrays
.
asList
(
excludeKeys
);
for
(
Map
.
Entry
<
String
,
Object
>
entry
:
this
.
bizParamMap
.
entrySet
())
{
if
(
list
.
contains
(
entry
.
getKey
()))
{
continue
;
}
Object
value
=
entry
.
getValue
();
if
(
value
!=
null
)
{
if
(
value
instanceof
String
)
{
if
(
StringUtils
.
isNotBlank
(
value
.
toString
()))
{
return
false
;
}
}
else
{
return
false
;
}
}
}
return
true
;
}
/**
* 获取long类型参数
* @param name
* @return
*/
public
Long
getLongBizParam
(
String
name
)
{
if
(
isNullValue
(
name
))
{
return
null
;
}
return
Long
.
valueOf
(
bizParamMap
.
get
(
name
).
toString
());
}
/**
* 获取int类型参数
* @param name
* @return
*/
public
Integer
getIntBizParam
(
String
name
)
{
if
(
isNullValue
(
name
))
{
return
null
;
}
return
Integer
.
valueOf
(
bizParamMap
.
get
(
name
).
toString
());
}
/**
* 获取int类型参数,如果为空返回defaultValue
* @param name
* @param defaultValue
* @return
*/
public
Integer
getIntBizParam
(
String
name
,
int
defaultValue
)
{
if
(
isNullValue
(
name
))
{
return
defaultValue
;
}
return
Integer
.
valueOf
(
bizParamMap
.
get
(
name
).
toString
());
}
/**
* 获取short类型参数
* @param name
* @return
*/
public
Short
getShortBizParam
(
String
name
)
{
if
(
isNullValue
(
name
))
{
return
null
;
}
return
Short
.
valueOf
(
bizParamMap
.
get
(
name
).
toString
());
}
/**
* 获取string类型参数,如果为空返回defaultValue
* @param name
* @param
* @return
*/
public
String
getStringBizParam
(
String
name
,
String
defaultValue
){
if
(
isNullValue
(
name
))
{
return
defaultValue
;
}
return
bizParamMap
.
get
(
name
).
toString
();
}
/**
* 获取string类型参数
* @param name
* @param
* @return
*/
public
String
getStringBizParam
(
String
name
){
if
(
isNullValue
(
name
))
{
return
null
;
}
return
bizParamMap
.
get
(
name
).
toString
();
}
public
List
<
Short
>
getShortListBizParam
(
String
name
)
{
if
(
isNullValue
(
name
))
{
return
null
;
}
List
<
Number
>
numberList
=
(
List
<
Number
>)
bizParamMap
.
get
(
name
);
if
(
numberList
==
null
)
{
return
null
;
}
List
<
Short
>
shortList
=
new
ArrayList
<
Short
>(
numberList
.
size
());
for
(
Number
number
:
numberList
)
{
Short
value
=
number
.
shortValue
();
shortList
.
add
(
value
);
}
return
shortList
;
}
public
List
<
Integer
>
getIntegerListBizParam
(
String
name
)
{
if
(
isNullValue
(
name
))
{
return
null
;
}
List
<
Number
>
numberList
=
(
List
<
Number
>)
bizParamMap
.
get
(
name
);
if
(
numberList
==
null
)
{
return
null
;
}
List
<
Integer
>
integerList
=
new
ArrayList
<
Integer
>(
numberList
.
size
());
for
(
Number
number
:
numberList
)
{
Integer
value
=
number
.
intValue
();
integerList
.
add
(
value
);
}
return
integerList
;
}
public
List
<
Long
>
getLongListBizParam
(
String
name
)
{
if
(
isNullValue
(
name
))
{
return
null
;
}
List
<
Number
>
numberList
=
(
List
<
Number
>)
bizParamMap
.
get
(
name
);
if
(
numberList
==
null
)
{
return
null
;
}
List
<
Long
>
longList
=
new
ArrayList
<
Long
>(
numberList
.
size
());
for
(
Number
number
:
numberList
)
{
Long
value
=
number
.
longValue
();
longList
.
add
(
value
);
}
return
longList
;
}
public
static
void
main
(
String
[]
args
)
{
BaseParam
baseParam
=
new
BaseParam
();
Map
<
String
,
Object
>
map
=
new
HashMap
<
String
,
Object
>();
map
.
put
(
"a"
,
null
);
map
.
put
(
"b"
,
""
);
baseParam
.
setBizParamMap
(
map
);
System
.
out
.
println
(
baseParam
.
isInvalidMapValue
(
""
));
}
}
xxpay-common/src/main/java/org/xxpay/common/domain/RpcBaseParam.java
0 → 100644
View file @
eb533493
package
org.xxpay.common.domain
;
import
org.xxpay.common.enumm.RpcSignTypeEnum
;
import
org.xxpay.common.util.*
;
import
java.io.Serializable
;
import
java.util.HashMap
;
import
java.util.Map
;
/**
* 服务接口调用入参基类
* Created by admin on 2016/4/27.
*/
public
class
RpcBaseParam
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
/**
* 调用方ID(由RPC服务端分配)
*/
protected
String
rpcSrcSysId
;
/**
* 业务调用当前时间(格式:yyyyMMddHHmmssSSS)
*/
protected
String
rpcDateTime
;
/**
* 随机通讯码(要求一定时间段内不重复)
*/
protected
String
rpcSeqNo
;
/**
* 签名计算方法
* 参见RpcSignTypeEnum
* 0: 明文
* 1: SHA-1
*/
protected
Integer
rpcSignType
;
/**
* 签名(用于验证调用方的合法性)
* 签名计算方法: 签名方法(key(由RPC服务端分配,不在通讯中传递)+scrSysId+rpcDateTime(yyyyMMddHHmmssSSS)+rpcSignType+bizSeqNo+bizSign),如果字段为null则不参与
* eg. sha1(key+srcSysId+curDateTime+rpcSignType+bizSeqNo+bizSign)
*/
protected
String
rpcSign
;
/**
* 业务流水号(唯一标示一笔业务)
* 由业务前缀(2字符,参见Constant.MP_BIZ_SEQUENCE_NO_PREFIX)+日期时间(yyyyMMddHHmmss)+流水号(6位数字)组成
* eg. Constant.MP_BIZ_SEQUENCE_NO_PREFIX)+DateUtils.getCurrentTimeStr("yyyyMMddHHmmss")
* +BizSequenceUtils.getInstance().generateBizSeqNo()
*/
protected
String
bizSeqNo
;
/**
* 业务签名(计算由各业务系统定义)
*/
protected
String
bizSign
;
public
RpcBaseParam
()
{}
/**
* 不需要业务签名的构造器
* @param rpcSrcSysId
* @param rpcSignKey
* @param bizSeqNoPrefix
*/
public
RpcBaseParam
(
String
rpcSrcSysId
,
String
rpcSignKey
,
String
bizSeqNoPrefix
)
{
this
.
rpcSrcSysId
=
rpcSrcSysId
;
this
.
rpcDateTime
=
DateUtils
.
getCurrentTimeStrDefault
();
this
.
rpcSeqNo
=
RandomStrUtils
.
getInstance
().
getRandomString
();
this
.
rpcSignType
=
RpcSignTypeEnum
.
SHA1_SIGN
.
getCode
();
this
.
bizSeqNo
=
BizSequenceUtils
.
getInstance
().
generateBizSeqNo
(
bizSeqNoPrefix
);
StringBuffer
decriptBuffer
=
new
StringBuffer
();
decriptBuffer
.
append
(
rpcSignKey
)
.
append
(
this
.
rpcSrcSysId
)
.
append
(
this
.
rpcDateTime
)
.
append
(
this
.
rpcSignType
)
.
append
(
this
.
bizSeqNo
);
this
.
rpcSign
=
RpcSignUtils
.
sha1
(
decriptBuffer
.
toString
());
}
/**
* 需要业务签名的构造器
* @param rpcSrcSysId
* @param rpcSignKey
* @param bizSeqNoPrefix
* @param bizSign
*/
public
RpcBaseParam
(
String
rpcSrcSysId
,
String
rpcSignKey
,
String
bizSeqNoPrefix
,
String
bizSign
)
{
this
.
rpcSrcSysId
=
rpcSrcSysId
;
this
.
rpcDateTime
=
DateUtils
.
getCurrentTimeStrDefault
();
this
.
rpcSeqNo
=
RandomStrUtils
.
getInstance
().
getRandomString
();
this
.
rpcSignType
=
RpcSignTypeEnum
.
SHA1_SIGN
.
getCode
();
this
.
bizSeqNo
=
BizSequenceUtils
.
getInstance
().
generateBizSeqNo
(
bizSeqNoPrefix
);
this
.
bizSign
=
bizSign
;
StringBuffer
decriptBuffer
=
new
StringBuffer
();
decriptBuffer
.
append
(
rpcSignKey
)
.
append
(
this
.
rpcSrcSysId
)
.
append
(
this
.
rpcDateTime
)
.
append
(
this
.
rpcSignType
)
.
append
(
this
.
bizSeqNo
)
.
append
(
this
.
bizSign
);
this
.
rpcSign
=
RpcSignUtils
.
sha1
(
decriptBuffer
.
toString
());
}
public
String
getRpcSrcSysId
()
{
return
rpcSrcSysId
;
}
public
void
setRpcSrcSysId
(
String
rpcSrcSysId
)
{
this
.
rpcSrcSysId
=
rpcSrcSysId
;
}
public
String
getRpcDateTime
()
{
return
rpcDateTime
;
}
public
void
setRpcDateTime
(
String
rpcDateTime
)
{
this
.
rpcDateTime
=
rpcDateTime
;
}
public
String
getRpcSeqNo
()
{
return
rpcSeqNo
;
}
public
void
setRpcSeqNo
(
String
rpcSeqNo
)
{
this
.
rpcSeqNo
=
rpcSeqNo
;
}
public
Integer
getRpcSignType
()
{
return
rpcSignType
;
}
public
void
setRpcSignType
(
Integer
rpcSignType
)
{
this
.
rpcSignType
=
rpcSignType
;
}
public
String
getBizSeqNo
()
{
return
bizSeqNo
;
}
public
void
setBizSeqNo
(
String
bizSeqNo
)
{
this
.
bizSeqNo
=
bizSeqNo
;
}
public
String
getBizSign
()
{
return
bizSign
;
}
public
void
setBizSign
(
String
bizSign
)
{
this
.
bizSign
=
bizSign
;
}
public
String
getRpcSign
()
{
return
rpcSign
;
}
public
void
setRpcSign
(
String
rpcSign
)
{
this
.
rpcSign
=
rpcSign
;
}
/*public Map<String, Object> convert2Map() {
if (this == null) {
return null;
}
return BeanConvertUtils.bean2Map(this);
}*/
public
static
RpcBaseParam
convert2Bean
(
Map
<
String
,
Object
>
map
)
{
return
BeanConvertUtils
.
map2Bean
(
map
,
RpcBaseParam
.
class
);
}
@Override
public
String
toString
()
{
final
StringBuffer
sb
=
new
StringBuffer
(
"RpcBaseParam{"
);
sb
.
append
(
"rpcSrcSysId='"
).
append
(
rpcSrcSysId
).
append
(
'\''
);
sb
.
append
(
", rpcDateTime='"
).
append
(
rpcDateTime
).
append
(
'\''
);
sb
.
append
(
", rpcSeqNo='"
).
append
(
rpcSeqNo
).
append
(
'\''
);
sb
.
append
(
", rpcSignType="
).
append
(
rpcSignType
);
sb
.
append
(
", rpcSign='"
).
append
(
rpcSign
).
append
(
'\''
);
sb
.
append
(
", bizSeqNo='"
).
append
(
bizSeqNo
).
append
(
'\''
);
sb
.
append
(
", bizSign='"
).
append
(
bizSign
).
append
(
'\''
);
sb
.
append
(
'}'
);
return
sb
.
toString
();
}
public
Map
<
String
,
Object
>
convert2Map
()
{
Map
<
String
,
Object
>
rpcMap
=
new
HashMap
<
String
,
Object
>();
rpcMap
.
put
(
"rpcSrcSysId"
,
rpcSrcSysId
);
rpcMap
.
put
(
"rpcDateTime"
,
rpcDateTime
);
rpcMap
.
put
(
"rpcSeqNo"
,
rpcSeqNo
);
rpcMap
.
put
(
"rpcSignType"
,
rpcSignType
);
rpcMap
.
put
(
"rpcSign"
,
rpcSign
);
rpcMap
.
put
(
"bizSeqNo"
,
bizSeqNo
);
rpcMap
.
put
(
"bizSign"
,
bizSign
);
return
rpcMap
;
}
}
xxpay-common/src/main/java/org/xxpay/common/domain/RpcBaseResult.java
0 → 100644
View file @
eb533493
package
org.xxpay.common.domain
;
import
java.util.HashMap
;
import
java.util.Map
;
/**
* 服务接口调用返回值基类
* Created by admin on 2016/4/27.
*/
public
class
RpcBaseResult
extends
RpcBaseParam
{
/**
* RPC调用返回码
* 0000: 成功
* 其他: 失败(00开始标示通讯层相关错误码)
*/
protected
String
rpcRetCode
;
/**
* RPC调用返回错误描述
*/
protected
String
rpcRetMsg
;
/**
* DB返回的错误码
*/
protected
String
dbErrorCode
;
/**
* DB返回的错误信息
*/
protected
String
dbErrorMsg
;
public
String
getRpcRetCode
()
{
return
rpcRetCode
;
}
public
void
setRpcRetCode
(
String
rpcRetCode
)
{
this
.
rpcRetCode
=
rpcRetCode
;
}
public
String
getRpcRetMsg
()
{
return
rpcRetMsg
;
}
public
void
setRpcRetMsg
(
String
rpcRetMsg
)
{
this
.
rpcRetMsg
=
rpcRetMsg
;
}
@Override
public
String
toString
()
{
final
StringBuffer
sb
=
new
StringBuffer
(
"RpcBaseResult{"
);
sb
.
append
(
"rpcSrcSysId='"
).
append
(
rpcSrcSysId
).
append
(
'\''
);
sb
.
append
(
", rpcDateTime='"
).
append
(
rpcDateTime
).
append
(
'\''
);
sb
.
append
(
", rpcSeqNo='"
).
append
(
rpcSeqNo
).
append
(
'\''
);
sb
.
append
(
", rpcSignType="
).
append
(
rpcSignType
);
sb
.
append
(
", rpcSign='"
).
append
(
rpcSign
).
append
(
'\''
);
sb
.
append
(
", bizSeqNo='"
).
append
(
bizSeqNo
).
append
(
'\''
);
sb
.
append
(
", bizSign='"
).
append
(
bizSign
).
append
(
'\''
);
sb
.
append
(
", rpcRetCode='"
).
append
(
rpcRetCode
).
append
(
'\''
);
sb
.
append
(
", rpcRetMsg='"
).
append
(
rpcRetMsg
).
append
(
'\''
);
sb
.
append
(
", dbErrorCode='"
).
append
(
dbErrorCode
).
append
(
'\''
);
sb
.
append
(
", dbErrorMsg='"
).
append
(
dbErrorMsg
).
append
(
'\''
);
sb
.
append
(
'}'
);
return
sb
.
toString
();
}
public
Map
<
String
,
Object
>
convert2Map
()
{
Map
<
String
,
Object
>
rpcMap
=
new
HashMap
<
String
,
Object
>();
rpcMap
.
put
(
"rpcSrcSysId"
,
rpcSrcSysId
);
rpcMap
.
put
(
"rpcDateTime"
,
rpcDateTime
);
rpcMap
.
put
(
"rpcSeqNo"
,
rpcSeqNo
);
rpcMap
.
put
(
"rpcSignType"
,
rpcSignType
);
rpcMap
.
put
(
"rpcSign"
,
rpcSign
);
rpcMap
.
put
(
"bizSeqNo"
,
bizSeqNo
);
rpcMap
.
put
(
"bizSign"
,
bizSign
);
rpcMap
.
put
(
"rpcRetCode"
,
rpcRetCode
);
rpcMap
.
put
(
"rpcRetMsg"
,
rpcRetMsg
);
rpcMap
.
put
(
"dbErrorCode"
,
dbErrorCode
);
rpcMap
.
put
(
"dbErrorMsg"
,
dbErrorMsg
);
return
rpcMap
;
}
}
xxpay-common/src/main/java/org/xxpay/common/enumm/RetEnum.java
0 → 100644
View file @
eb533493
package
org.xxpay.common.enumm
;
/**
* RPC调用返回码枚举类
* 对应方法调用返回值中的rpcRetCode和rpcRetMsg
* Created by admin on 2016/4/27.
*/
public
enum
RetEnum
{
// 0000: 成功
RET_SUCCESS
(
"0000"
,
""
),
// 失败(00开始标示通讯层相关错误码)
RET_REMOTE_UNUSABLE
(
"0001"
,
"远程服务不可用"
),
RET_REMOTE_INVALID
(
"0002"
,
"客户端非法调用"
),
RET_NO_BIZ_SEQUENCE_NO
(
"0003"
,
"远程服务调用业务流水号不存在"
),
RET_REMOTE_CHECK_SIGN_FAIL
(
"0004"
,
"远程服务调用签名验证失败"
),
RET_REMOTE_RPC_SEQ_NO_REPEATED
(
"0005"
,
"随机通讯码在指定时间内重复"
),
RET_REMOTE_SIGN_INVALID
(
"0006"
,
"远程服务调用签名计算方式错误"
),
RET_REMOTE_DEAL_EXCEPTION
(
"0007"
,
"远程服务调用处理异常"
),
RET_REMOTE_PROTOCOL_INVALID
(
"0008"
,
"客户端调用协议非法"
),
RET_REMOTE_HTTP_METHOD_INVALID
(
"0009"
,
"客户端请求方式非法"
),
// 失败(01开始标示参数校验相关错误码)
RET_PARAM_NOT_FOUND
(
"0101"
,
"参数不存在"
),
RET_PARAM_INVALID
(
"0102"
,
"无效的参数"
),
RET_PARAM_TOO_LARGE_LIST
(
"0103"
,
"列表超长"
),
RET_PARAM_TYPE_INVALID
(
"0104"
,
"参数类型错误"
),
RET_CURRENT_PAGE_INVALID
(
"0105"
,
"当前页码非法"
),
RET_VIEW_NUMBER_INVALID
(
"0106"
,
"分页显示数目非法"
),
RET_VIEW_LIMIT_INVALID
(
"0107"
,
"数据排列显示数目非法"
),
// 失败(02开始标示DB操作相关错误码)
RET_DB_FAIL
(
"0201"
,
"数据库操作失败"
),
// 业务相关
RET_BIZ_DATA_NOT_EXISTS
(
"1001"
,
"数据不存在"
),
RET_BIZ_SING_DATA_FAIL
(
"1002"
,
"商户签名数据不正确"
),
RET_BIZ_WX_PAY_CREATE_FAIL
(
"1003"
,
"微信支付下单失败"
),
RET_BIZ_ALI_PAY_CREATE_FAIL
(
"1004"
,
"支付宝支付下单失败"
),
RET_BIZ_PAY_NOTIFY_VERIFY_FAIL
(
"1005"
,
"支付通知数据验证不正确"
),
// 未知错误
RET_UNKNOWN_ERROR
(
"9999"
,
"未知错误"
);
private
String
code
;
private
String
message
;
private
RetEnum
(
String
code
,
String
message
)
{
this
.
code
=
code
;
this
.
message
=
message
;
}
public
String
getCode
()
{
return
this
.
code
;
}
public
String
getMessage
()
{
return
this
.
message
;
}
public
static
RetEnum
getRetEnum
(
String
code
)
{
if
(
code
==
null
)
{
return
null
;
}
RetEnum
[]
values
=
RetEnum
.
values
();
for
(
RetEnum
e
:
values
)
{
if
(
e
.
getCode
().
equals
(
code
))
{
return
e
;
}
}
return
null
;
}
}
xxpay-common/src/main/java/org/xxpay/common/enumm/RpcSignTypeEnum.java
0 → 100644
View file @
eb533493
package
org.xxpay.common.enumm
;
/**
* RPC通讯层签名计算方法枚举类
* Created by admin on 2016/5/4.
*/
public
enum
RpcSignTypeEnum
{
NOT_SIGN
(
0
),
// 明文
SHA1_SIGN
(
1
);
// SHA-1签名
private
Integer
code
;
private
RpcSignTypeEnum
(
Integer
code
)
{
this
.
code
=
code
;
}
public
Integer
getCode
()
{
return
this
.
code
;
}
public
static
RpcSignTypeEnum
getRpcSignTypeEnum
(
Integer
code
)
{
if
(
code
==
null
)
{
return
null
;
}
RpcSignTypeEnum
[]
values
=
RpcSignTypeEnum
.
values
();
for
(
RpcSignTypeEnum
e
:
values
)
{
if
(
e
.
getCode
().
equals
(
code
))
{
return
e
;
}
}
return
null
;
}
}
xxpay-common/src/main/java/org/xxpay/common/util/BeanConvertUtils.java
0 → 100644
View file @
eb533493
package
org.xxpay.common.util
;
import
org.apache.commons.beanutils.BeanUtils
;
import
org.apache.commons.beanutils.ConvertUtils
;
import
org.apache.commons.beanutils.converters.*
;
import
java.lang.reflect.InvocationTargetException
;
import
java.math.BigDecimal
;
import
java.util.Date
;
import
java.util.Map
;
/**
* Created by admin on 2016/5/4.
*/
public
class
BeanConvertUtils
{
static
{
// 在封装之前 注册转换器
ConvertUtils
.
register
(
new
DateTimeConverter
(),
Date
.
class
);
ConvertUtils
.
register
(
new
DateTimeConverter
(),
java
.
sql
.
Date
.
class
);
ConvertUtils
.
register
(
new
LongConverter
(
null
),
Long
.
class
);
ConvertUtils
.
register
(
new
ShortConverter
(
null
),
Short
.
class
);
ConvertUtils
.
register
(
new
IntegerConverter
(
null
),
Integer
.
class
);
ConvertUtils
.
register
(
new
DoubleConverter
(
null
),
Double
.
class
);
ConvertUtils
.
register
(
new
BigDecimalConverter
(
null
),
BigDecimal
.
class
);
}
/**
* 将javabean转换为Map
* @param obj
* @return
*/
public
static
Map
<
String
,
Object
>
bean2Map
(
Object
obj
)
{
try
{
Map
<
String
,
Object
>
map
=
BeanUtils
.
describe
(
obj
);
map
.
remove
(
"class"
);
return
map
;
}
catch
(
IllegalAccessException
e
)
{
e
.
printStackTrace
();
}
catch
(
InvocationTargetException
e
)
{
e
.
printStackTrace
();
}
catch
(
NoSuchMethodException
e
)
{
e
.
printStackTrace
();
}
return
null
;
}
/**
* 将Map转换为javabean
* @param map
* @param clazz
* @param <T>
* @return
*/
public
static
<
T
>
T
map2Bean
(
Map
<
String
,
Object
>
map
,
Class
<
T
>
clazz
)
{
if
(
map
==
null
||
clazz
==
null
)
{
return
null
;
}
T
bean
=
null
;
try
{
bean
=
clazz
.
newInstance
();
BeanUtils
.
populate
(
bean
,
map
);
}
catch
(
InstantiationException
e
)
{
e
.
printStackTrace
();
}
catch
(
IllegalAccessException
e
)
{
e
.
printStackTrace
();
}
catch
(
InvocationTargetException
e
)
{
e
.
printStackTrace
();
}
return
bean
;
}
/**
* 对象间的属性值拷贝
*
* @param dest 目标对象
* @param src 源对象
*/
public
static
void
copyProperties
(
Object
dest
,
Object
src
)
{
if
(
src
==
null
||
dest
==
null
)
{
return
;
}
try
{
BeanUtils
.
copyProperties
(
dest
,
src
);
}
catch
(
IllegalAccessException
e
)
{
e
.
printStackTrace
();
}
catch
(
InvocationTargetException
e
)
{
e
.
printStackTrace
();
}
catch
(
IllegalArgumentException
e
)
{
e
.
printStackTrace
();
}
}
}
xxpay-common/src/main/java/org/xxpay/common/util/BizSequenceUtils.java
0 → 100644
View file @
eb533493
package
org.xxpay.common.util
;
import
java.text.DecimalFormat
;
import
java.text.FieldPosition
;
import
java.text.NumberFormat
;
import
java.util.concurrent.atomic.AtomicInteger
;
/**
* 业务流水号工具类
* Created by admin on 2016/4/28.
*/
public
class
BizSequenceUtils
{
private
static
Object
lock
=
new
Object
();
private
static
BizSequenceUtils
instance
;
/**
* The FieldPosition.
*/
private
static
final
FieldPosition
HELPER_POSITION
=
new
FieldPosition
(
0
);
/**
* This Format for format the number to special format.
*/
private
final
static
NumberFormat
numberFormat
=
new
DecimalFormat
(
"00000000"
);
/**
* This int is the sequence number ,the default value is 1.
*/
private
static
AtomicInteger
seq
=
new
AtomicInteger
(
1
);
private
static
final
int
MAX
=
99999999
;
private
BizSequenceUtils
()
{
}
public
static
BizSequenceUtils
getInstance
()
{
if
(
instance
==
null
)
{
synchronized
(
lock
)
{
if
(
instance
==
null
)
{
instance
=
new
BizSequenceUtils
();
}
}
}
return
instance
;
}
/**
* 生成业务流水号(唯一标示一笔业务)
*
* @param bizSeqNoPrefix 业务前缀(2字符,参见Constant.**_BIZ_SEQUENCE_NO_PREFIX)
* @return
*/
public
String
generateBizSeqNo
(
String
bizSeqNoPrefix
)
{
StringBuffer
bizSeqNo
=
new
StringBuffer
();
bizSeqNo
.
append
(
bizSeqNoPrefix
)
.
append
(
DateUtils
.
getCurrentTimeStr
(
"yyMMddHHmmss"
))
.
append
(
getSeq
());
return
bizSeqNo
.
toString
();
}
private
String
getSeq
()
{
StringBuffer
sb
=
new
StringBuffer
();
numberFormat
.
format
(
seq
,
sb
,
HELPER_POSITION
);
if
(!
seq
.
compareAndSet
(
MAX
,
0
))
{
seq
.
incrementAndGet
();
}
return
sb
.
toString
();
}
}
xxpay-common/src/main/java/org/xxpay/common/util/DateTimeConverter.java
0 → 100644
View file @
eb533493
package
org.xxpay.common.util
;
import
org.apache.commons.beanutils.Converter
;
import
java.text.DateFormat
;
import
java.text.DateFormatSymbols
;
import
java.text.SimpleDateFormat
;
import
java.util.Locale
;
/**
* Created by admin on 2016/5/10.
*/
public
class
DateTimeConverter
implements
Converter
{
private
static
final
String
DATE
=
"yyyy-MM-dd"
;
private
static
final
String
DATETIME
=
"yyyy-MM-dd HH:mm:ss"
;
private
static
final
String
TIMESTAMP
=
"yyyy-MM-dd HH:mm:ss.SSS"
;
@Override
public
Object
convert
(
Class
type
,
Object
value
)
{
return
toDate
(
type
,
value
);
}
public
static
Object
toDate
(
Class
type
,
Object
value
)
{
if
(
value
==
null
||
""
.
equals
(
value
))
return
null
;
if
(
value
instanceof
String
)
{
String
dateValue
=
value
.
toString
().
trim
();
int
length
=
dateValue
.
length
();
if
(
type
.
equals
(
java
.
util
.
Date
.
class
))
{
try
{
DateFormat
formatter
=
null
;
if
(
length
<=
10
)
{
formatter
=
new
SimpleDateFormat
(
DATE
,
new
DateFormatSymbols
(
Locale
.
CHINA
));
return
formatter
.
parse
(
dateValue
);
}
if
(
length
<=
19
)
{
formatter
=
new
SimpleDateFormat
(
DATETIME
,
new
DateFormatSymbols
(
Locale
.
CHINA
));
return
formatter
.
parse
(
dateValue
);
}
if
(
length
<=
23
)
{
formatter
=
new
SimpleDateFormat
(
TIMESTAMP
,
new
DateFormatSymbols
(
Locale
.
CHINA
));
return
formatter
.
parse
(
dateValue
);
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
}
return
value
;
}
}
xxpay-common/src/main/java/org/xxpay/common/util/DateUtils.java
0 → 100644
View file @
eb533493
package
org.xxpay.common.util
;
import
java.text.SimpleDateFormat
;
import
java.util.Date
;
/**
* 时间格式化工具
* Created by admin on 2016/5/4.
*/
public
class
DateUtils
{
private
static
final
String
DEFAULT_CONVERT_PATTERN
=
"yyyyMMddHHmmssSSS"
;
/**
* 获取当前时间字符串(默认格式:yyyyMMddHHmmssSSS)
*
* @return
*/
public
static
String
getCurrentTimeStrDefault
()
{
return
getCurrentTimeStr
(
DEFAULT_CONVERT_PATTERN
);
}
/**
* 获取指定时间字符串(默认格式:yyyyMMddHHmmssSSS)
* @param date
* @return
*/
public
static
String
getTimeStrDefault
(
Date
date
)
{
SimpleDateFormat
dateFormat
=
new
SimpleDateFormat
(
DEFAULT_CONVERT_PATTERN
);
return
dateFormat
.
format
(
date
);
}
/**
* 获取当前时间字符串
*
* @param pattern 转换格式
* @return
*/
public
static
String
getCurrentTimeStr
(
String
pattern
)
{
SimpleDateFormat
dateFormat
=
new
SimpleDateFormat
(
pattern
);
return
dateFormat
.
format
(
new
Date
());
}
/**
* 获取指定时间字符串
* @param date
* @return
*/
public
static
String
getTimeStr
(
Date
date
,
String
pattern
)
{
SimpleDateFormat
dateFormat
=
new
SimpleDateFormat
(
pattern
);
return
dateFormat
.
format
(
date
);
}
/**
* 判断时间字符串是否为默认格式
* @param dateTimeStr
* @return
*/
public
static
boolean
isValidDefaultFormat
(
String
dateTimeStr
)
{
SimpleDateFormat
dateFormat
=
new
SimpleDateFormat
(
DEFAULT_CONVERT_PATTERN
);
try
{
dateFormat
.
parse
(
dateTimeStr
);
return
true
;
}
catch
(
Exception
e
)
{
// 如果抛出异常,说明格式不正确
return
false
;
}
}
}
xxpay-common/src/main/java/org/xxpay/common/util/JsonUtil.java
0 → 100644
View file @
eb533493
package
org.xxpay.common.util
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
java.util.List
;
/**
* Created by admin on 2016/4/13.
*/
public
class
JsonUtil
{
static
{
System
.
setProperty
(
"fastjson.compatibleWithJavaBean"
,
"true"
);
}
public
static
String
object2Json
(
Object
object
)
{
if
(
object
==
null
)
{
return
null
;
}
return
JSONObject
.
toJSONString
(
object
);
}
public
static
<
T
>
T
getObjectFromJson
(
String
json
,
Class
<
T
>
clazz
)
{
if
(
json
==
null
)
{
return
null
;
}
return
JSON
.
parseObject
(
json
,
clazz
);
}
public
static
<
T
>
List
<
T
>
getObjectListFromJson
(
String
json
,
Class
<
T
>
clazz
)
{
if
(
json
==
null
)
{
return
null
;
}
return
JSON
.
parseArray
(
json
,
clazz
);
}
public
static
JSONObject
getJSONObjectFromJson
(
String
json
)
{
if
(
json
==
null
)
{
return
null
;
}
return
JSONObject
.
parseObject
(
json
);
}
public
static
JSONObject
getJSONObjectFromObj
(
Object
object
)
{
if
(
object
==
null
)
{
return
null
;
}
return
(
JSONObject
)
JSONObject
.
toJSON
(
object
);
}
}
xxpay-common/src/main/java/org/xxpay/common/util/ObjectValidUtil.java
0 → 100644
View file @
eb533493
package
org.xxpay.common.util
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
java.math.BigDecimal
;
import
java.util.List
;
import
java.util.Map
;
/**
* Created by admin on 2016/6/23.
*/
public
class
ObjectValidUtil
{
public
static
boolean
isValid
(
Object
...
objs
)
{
if
(
objs
==
null
||
objs
.
length
<
1
)
{
return
false
;
}
for
(
Object
obj
:
objs
)
{
if
(
obj
instanceof
Short
)
{
if
(
isNull
(
obj
))
{
return
false
;
}
}
else
if
(
obj
instanceof
Integer
)
{
if
(
isInvalidInteger
((
Integer
)
obj
))
{
return
false
;
}
}
else
if
(
obj
instanceof
Long
)
{
if
(
isInvalidLong
((
Long
)
obj
))
{
return
false
;
}
}
else
if
(
obj
instanceof
String
)
{
if
(
isInvalidString
(
obj
.
toString
()))
{
return
false
;
}
}
else
if
(
obj
instanceof
List
)
{
if
(
CollectionUtils
.
isEmpty
((
List
)
obj
))
{
return
false
;
}
}
else
if
(
obj
instanceof
Map
)
{
if
(
isNull
(
obj
)
||
((
Map
)
obj
).
isEmpty
())
{
return
false
;
}
}
else
{
if
(
isNull
(
obj
))
{
return
false
;
}
}
}
return
true
;
}
public
static
boolean
isInvalid
(
Object
...
objs
)
{
return
!
isValid
(
objs
);
}
/**
* 判断是否为有效Short值
* @param num
* @return
*/
public
static
boolean
isValidShort
(
Short
num
)
{
if
(
num
==
null
||
num
.
compareTo
((
short
)
0
)
<=
0
)
{
return
false
;
}
return
true
;
}
public
static
boolean
isInvalidShort
(
Short
num
)
{
return
!
isValidShort
(
num
);
}
/**
* 判断是否为有效Integer值
* @param num
* @return
*/
public
static
boolean
isValidInteger
(
Integer
num
)
{
if
(
num
==
null
||
num
.
compareTo
(
0
)
<=
0
)
{
return
false
;
}
return
true
;
}
public
static
boolean
isInvalidInteger
(
Integer
num
)
{
return
!
isValidInteger
(
num
);
}
/**
* 判断是否为有效Long值
* @param num
* @return
*/
public
static
boolean
isValidLong
(
Long
num
)
{
if
(
num
==
null
||
num
.
compareTo
(
0L
)
<=
0
)
{
return
false
;
}
return
true
;
}
public
static
boolean
isInvalidLong
(
Long
num
)
{
return
!
isValidLong
(
num
);
}
/**
* 判断是否为有效BigDecimal值
* @param num
* @return
*/
public
static
boolean
isValidBigDecimal
(
BigDecimal
num
)
{
if
(
num
==
null
||
num
.
compareTo
(
BigDecimal
.
ZERO
)
<=
0
)
{
return
false
;
}
return
true
;
}
public
static
boolean
isInvalidBigDecimal
(
BigDecimal
num
)
{
return
!
isValidBigDecimal
(
num
);
}
/**
* 判断是否为有效String值
* @param str
* @return
*/
public
static
boolean
isValidString
(
String
str
)
{
return
StringUtils
.
isNotBlank
(
str
);
}
public
static
boolean
isInvalidString
(
String
str
)
{
return
StringUtils
.
isBlank
(
str
);
}
public
static
boolean
isNull
(
Object
obj
)
{
if
(
obj
==
null
)
{
return
true
;
}
return
false
;
}
public
static
boolean
isNotNull
(
Object
obj
)
{
return
!
isNull
(
obj
);
}
public
static
boolean
isValidCurPage
(
Integer
curPage
)
{
if
(
curPage
==
null
)
{
return
false
;
}
if
(
curPage
.
compareTo
(
1
)
<
0
)
{
return
false
;
}
return
true
;
}
public
static
boolean
isValidCurPage
(
Long
curPage
)
{
if
(
curPage
==
null
)
{
return
false
;
}
if
(
curPage
.
compareTo
(
1L
)
<
0
)
{
return
false
;
}
return
true
;
}
public
static
boolean
isInvalidCurPage
(
Integer
curPage
)
{
return
!
isValidCurPage
(
curPage
);
}
public
static
boolean
isInvalidCurPage
(
Long
curPage
)
{
return
!
isValidCurPage
(
curPage
);
}
public
static
boolean
isValidViewNumber
(
Integer
viewNumber
)
{
if
(
viewNumber
==
null
)
{
return
false
;
}
if
(
viewNumber
.
compareTo
(
0
)
<=
0
)
{
return
false
;
}
return
true
;
}
public
static
boolean
isValidViewNumber
(
Long
viewNumber
)
{
if
(
viewNumber
==
null
)
{
return
false
;
}
if
(
viewNumber
.
compareTo
(
0L
)
<=
0
)
{
return
false
;
}
return
true
;
}
public
static
boolean
isInvalidViewNumber
(
Integer
viewNumber
)
{
return
!
isValidViewNumber
(
viewNumber
);
}
public
static
boolean
isInvalidViewNumber
(
Long
viewNumber
)
{
return
!
isValidViewNumber
(
viewNumber
);
}
public
static
boolean
isValidLimit
(
Integer
limit
)
{
if
(
limit
==
null
)
{
return
false
;
}
if
(
limit
.
compareTo
(
0
)
<=
0
)
{
return
false
;
}
return
true
;
}
public
static
boolean
isInvalidLimit
(
Integer
limit
)
{
return
!
isValidLimit
(
limit
);
}
public
static
boolean
isAllNull
(
Object
...
objs
)
{
if
(
objs
==
null
||
objs
.
length
<
1
)
{
return
true
;
}
int
nullcount
=
0
;
for
(
Object
obj
:
objs
)
{
if
(
isNull
(
obj
))
{
nullcount
++;
}
}
return
objs
.
length
==
nullcount
;
}
}
xxpay-common/src/main/java/org/xxpay/common/util/RandomStrUtils.java
0 → 100644
View file @
eb533493
package
org.xxpay.common.util
;
import
org.xxpay.common.constant.Constant
;
import
java.util.Iterator
;
import
java.util.Map
;
import
java.util.Random
;
import
java.util.concurrent.ConcurrentHashMap
;
/**
* 生成随机通讯码工具类
* Created by admin on 2016/5/4.
*/
public
class
RandomStrUtils
{
private
static
Object
lock
=
new
Object
();
private
static
RandomStrUtils
instance
;
private
Map
<
String
,
Long
>
randomStrMap
=
new
ConcurrentHashMap
<
String
,
Long
>();
private
static
final
String
[]
BASE_STRING
=
new
String
[]{
"0"
,
"1"
,
"2"
,
"3"
,
"4"
,
"5"
,
"6"
,
"7"
,
"8"
,
"9"
,
"a"
,
"b"
,
"c"
,
"d"
,
"e"
,
"f"
,
"g"
,
"h"
,
"i"
,
"j"
,
"k"
,
"l"
,
"m"
,
"n"
,
"o"
,
"p"
,
"q"
,
"r"
,
"s"
,
"t"
,
"u"
,
"v"
,
"w"
,
"x"
,
"y"
,
"z"
,
"A"
,
"B"
,
"C"
,
"D"
,
"E"
,
"F"
,
"G"
,
"H"
,
"I"
,
"J"
,
"K"
,
"L"
,
"M"
,
"N"
,
"O"
,
"P"
,
"Q"
,
"R"
,
"S"
,
"T"
,
"U"
,
"V"
,
"W"
,
"X"
,
"Y"
,
"Z"
};
private
static
final
int
RANDOM_STRING_LENGTH
=
6
;
private
RandomStrUtils
()
{
}
public
static
RandomStrUtils
getInstance
()
{
synchronized
(
lock
)
{
if
(
instance
==
null
)
{
instance
=
new
RandomStrUtils
();
}
}
return
instance
;
}
public
String
getRandomString
()
{
Long
nowTime
=
System
.
currentTimeMillis
();
String
randomStr
=
null
;
synchronized
(
lock
)
{
// 生成随机字符串
randomStr
=
createRandomString
(
RANDOM_STRING_LENGTH
,
nowTime
);
// 删除一分钟前的随机字符串
Iterator
<
Map
.
Entry
<
String
,
Long
>>
it
=
randomStrMap
.
entrySet
().
iterator
();
while
(
it
.
hasNext
())
{
Map
.
Entry
<
String
,
Long
>
entry
=
it
.
next
();
Long
value
=
entry
.
getValue
();
if
(
nowTime
-
value
>
Constant
.
RPC_SEQ_NO_NOT_REPEAT_INTERVAL
)
{
it
.
remove
();
}
}
}
return
randomStr
;
}
private
String
createRandomString
(
int
len
,
Long
nowTime
)
{
Random
random
=
new
Random
();
int
length
=
BASE_STRING
.
length
;
String
randomString
=
""
;
for
(
int
i
=
0
;
i
<
length
;
i
++)
{
randomString
+=
BASE_STRING
[
random
.
nextInt
(
length
)];
}
random
=
new
Random
(
System
.
currentTimeMillis
());
String
resultStr
=
""
;
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
resultStr
+=
randomString
.
charAt
(
random
.
nextInt
(
randomString
.
length
()
-
1
));
}
// 判断一分钟内是否重复
Long
randomStrCreateTime
=
randomStrMap
.
get
(
resultStr
);
if
(
randomStrCreateTime
!=
null
&&
nowTime
-
randomStrCreateTime
<
Constant
.
RPC_SEQ_NO_NOT_REPEAT_INTERVAL
)
{
resultStr
=
createRandomString
(
len
,
nowTime
);
}
randomStrMap
.
put
(
resultStr
,
nowTime
);
return
resultStr
;
}
}
xxpay-common/src/main/java/org/xxpay/common/util/RpcSignUtils.java
0 → 100644
View file @
eb533493
package
org.xxpay.common.util
;
import
java.security.MessageDigest
;
import
java.security.NoSuchAlgorithmException
;
/**
* RPC通讯层签名工具类
* Created by admin on 2016/5/3.
*/
public
class
RpcSignUtils
{
public
static
String
sha1
(
String
decript
)
{
try
{
MessageDigest
digest
=
MessageDigest
.
getInstance
(
"SHA-1"
);
digest
.
update
(
decript
.
getBytes
());
byte
messageDigest
[]
=
digest
.
digest
();
// Create Hex String
StringBuffer
hexString
=
new
StringBuffer
();
// 字节数组转换为 十六进制 数
for
(
int
i
=
0
;
i
<
messageDigest
.
length
;
i
++)
{
String
shaHex
=
Integer
.
toHexString
(
messageDigest
[
i
]
&
0xFF
);
if
(
shaHex
.
length
()
<
2
)
{
hexString
.
append
(
0
);
}
hexString
.
append
(
shaHex
);
}
return
hexString
.
toString
();
}
catch
(
NoSuchAlgorithmException
e
)
{
e
.
printStackTrace
();
}
return
""
;
}
}
xxpay-common/src/main/java/org/xxpay/common/util/RpcUtil.java
0 → 100644
View file @
eb533493
package
org.xxpay.common.util
;
import
org.xxpay.common.constant.Constant
;
import
org.xxpay.common.domain.BaseParam
;
import
org.xxpay.common.domain.RpcBaseParam
;
import
org.xxpay.common.enumm.RetEnum
;
import
java.util.HashMap
;
import
java.util.Map
;
/**
* @author: dingzhiwei
* @date: 17/9/9
* @description:
*/
public
class
RpcUtil
{
public
static
BaseParam
getBaseParam
(
Map
<
String
,
Object
>
paramMap
)
{
if
(
paramMap
==
null
||
paramMap
.
isEmpty
())
{
return
null
;
}
BaseParam
baseParam
=
BeanConvertUtils
.
map2Bean
(
paramMap
,
BaseParam
.
class
);
paramMap
.
remove
(
"rpcSrcSysId"
);
paramMap
.
remove
(
"rpcDateTime"
);
paramMap
.
remove
(
"rpcSeqNo"
);
paramMap
.
remove
(
"rpcSignType"
);
paramMap
.
remove
(
"rpcSign"
);
paramMap
.
remove
(
"bizSeqNo"
);
paramMap
.
remove
(
"bizSign"
);
baseParam
.
setBizParamMap
(
paramMap
);
return
baseParam
;
}
/**
* 构建成功返回结果
* @param baseParam
* @param obj
* @return
*/
public
static
Map
<
String
,
Object
>
createBizResult
(
RpcBaseParam
baseParam
,
Object
obj
)
{
Map
<
String
,
Object
>
resultMap
=
createResultMap
(
baseParam
,
RetEnum
.
RET_SUCCESS
);
resultMap
.
put
(
Constant
.
BIZ_RESULT_KEY
,
obj
);
return
resultMap
;
}
public
static
Map
<
String
,
Object
>
createBizResultWithDBError
(
RpcBaseParam
baseParam
,
Object
obj
,
String
dbErrorCode
,
String
dbErrorMsg
)
{
Map
<
String
,
Object
>
resultMap
=
createResultMapWithDBError
(
baseParam
,
RetEnum
.
RET_SUCCESS
,
dbErrorCode
,
dbErrorMsg
);
resultMap
.
put
(
Constant
.
BIZ_RESULT_KEY
,
obj
);
return
resultMap
;
}
/**
* 构建失败返回结果
* @param rpcBaseParam
* @param retEnum
* @return
*/
public
static
Map
<
String
,
Object
>
createFailResult
(
RpcBaseParam
rpcBaseParam
,
RetEnum
retEnum
)
{
if
(
retEnum
==
null
)
{
retEnum
=
RetEnum
.
RET_PARAM_NOT_FOUND
;
}
return
createResultMap
(
rpcBaseParam
,
retEnum
);
}
public
static
Map
<
String
,
Object
>
createFailResultWithDBError
(
RpcBaseParam
rpcBaseParam
,
RetEnum
retEnum
,
String
dbErrorCode
,
String
dbErrorMsg
)
{
if
(
retEnum
==
null
)
{
retEnum
=
RetEnum
.
RET_PARAM_NOT_FOUND
;
}
return
createResultMapWithDBError
(
rpcBaseParam
,
retEnum
,
dbErrorCode
,
dbErrorMsg
);
}
private
static
Map
<
String
,
Object
>
createResultMap
(
RpcBaseParam
rpcBaseParam
,
RetEnum
retEnum
)
{
Map
<
String
,
Object
>
resultMap
=
null
;
if
(
rpcBaseParam
!=
null
)
{
resultMap
=
rpcBaseParam
.
convert2Map
();
}
else
{
resultMap
=
new
HashMap
<
String
,
Object
>();
}
resultMap
.
put
(
"rpcRetCode"
,
retEnum
.
getCode
());
resultMap
.
put
(
"rpcRetMsg"
,
retEnum
.
getMessage
());
return
resultMap
;
}
private
static
Map
<
String
,
Object
>
createResultMapWithDBError
(
RpcBaseParam
rpcBaseParam
,
RetEnum
retEnum
,
String
dbErrorCode
,
String
dbErrorMsg
)
{
Map
<
String
,
Object
>
resultMap
=
null
;
if
(
rpcBaseParam
!=
null
)
{
resultMap
=
rpcBaseParam
.
convert2Map
();
}
else
{
resultMap
=
new
HashMap
<
String
,
Object
>();
}
resultMap
.
put
(
"rpcRetCode"
,
retEnum
.
getCode
());
resultMap
.
put
(
"rpcRetMsg"
,
retEnum
.
getMessage
());
resultMap
.
put
(
"dbErrorCode"
,
dbErrorCode
);
resultMap
.
put
(
"dbErrorMsg"
,
dbErrorMsg
);
return
resultMap
;
}
public
static
String
createBaseParam
(
Map
<
String
,
Object
>
paramMap
)
{
BaseParam
baseParam
=
new
BaseParam
(
"102"
,
"rpc-src-sys-vvlive-config-key"
,
Constant
.
CF_BIZ_SEQUENCE_NO_PREFIX
);
baseParam
.
setBizParamMap
(
paramMap
);
return
baseParam
.
toJson
();
}
public
static
String
mkRet
(
Map
<
String
,
Object
>
result
)
{
//_log.info("调用dal返回result={}", result);
if
(
result
==
null
)
return
null
;
String
retCode
=
(
String
)
result
.
get
(
"rpcRetCode"
);
if
(
"0000"
.
equals
(
retCode
))
{
if
(
result
.
get
(
"bizResult"
)
==
null
)
return
null
;
return
result
.
get
(
"bizResult"
).
toString
();
}
return
null
;
}
}
xxpay4dubbo/pom.xml
0 → 100755
View file @
eb533493
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<modelVersion>
4.0.0
</modelVersion>
<groupId>
org.xxpay
</groupId>
<artifactId>
xxpay4dubbo
</artifactId>
<version>
1.0.0
</version>
<packaging>
pom
</packaging>
<name>
xxpay4dubbo
</name>
<description>
xxpay4dubbo
</description>
<modules>
<module>
xxpay4dubbo-api
</module>
<module>
xxpay4dubbo-web
</module>
<module>
xxpay4dubbo-service
</module>
</modules>
<parent>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-parent
</artifactId>
<version>
1.5.6.RELEASE
</version>
</parent>
<properties>
<project.build.sourceEncoding>
UTF-8
</project.build.sourceEncoding>
<project.reporting.outputEncoding>
UTF-8
</project.reporting.outputEncoding>
<java.version>
1.8
</java.version>
<springboot.version>
1.5.6.RELEASE
</springboot.version>
<springboot.dubbo.version>
1.5.6.RELEASE
</springboot.dubbo.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>
io.dubbo.springboot
</groupId>
<artifactId>
spring-boot-starter-dubbo
</artifactId>
<version>
${springboot.dubbo.version}
</version>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-web
</artifactId>
<version>
${springboot.version}
</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>
\ No newline at end of file
xxpay4dubbo/xxpay4dubbo-api/pom.xml
0 → 100755
View file @
eb533493
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<modelVersion>
4.0.0
</modelVersion>
<groupId>
org.xxpay
</groupId>
<artifactId>
xxpay4dubbo-api
</artifactId>
<version>
1.0.0
</version>
<packaging>
jar
</packaging>
<name>
xxpay4dubbo-api
</name>
<description>
xxpay4dubbo-api
</description>
<parent>
<groupId>
org.xxpay
</groupId>
<artifactId>
xxpay4dubbo
</artifactId>
<version>
1.0.0
</version>
</parent>
<properties>
<commons.beanutils.version>
1.7.0
</commons.beanutils.version>
</properties>
<dependencies>
<dependency>
<groupId>
org.xxpay
</groupId>
<artifactId>
xxpay-common
</artifactId>
<version>
1.0.0
</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
xxpay4dubbo/xxpay4dubbo-api/src/main/java/org/xxpay/dubbo/api/service/IMchInfoService.java
0 → 100644
View file @
eb533493
package
org.xxpay.dubbo.api.service
;
import
java.util.Map
;
/**
* @author: dingzhiwei
* @date: 17/9/8
* @description:
*/
public
interface
IMchInfoService
{
public
Map
selectMchInfo
(
String
jsonParam
);
}
Prev
1
2
3
Next
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment