记得上下班打卡 | git大法好,push需谨慎
Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
liquidnet-bus-v1
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
董敬伟
liquidnet-bus-v1
Commits
cb347737
Commit
cb347737
authored
Nov 09, 2021
by
anjiabin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
提交unionpay代码
parent
97b35e40
Changes
9
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
369 additions
and
826 deletions
+369
-826
ServiceDragonApplication.java
.../java/com/liquidnet/service/ServiceDragonApplication.java
+3
-0
Acp6Service.java
...dnet/service/dragon/channel/unionpay/sdk/Acp6Service.java
+56
-46
AcpService.java
...idnet/service/dragon/channel/unionpay/sdk/AcpService.java
+89
-82
CertUtil.java
...quidnet/service/dragon/channel/unionpay/sdk/CertUtil.java
+109
-106
QrcService.java
...idnet/service/dragon/channel/unionpay/sdk/QrcService.java
+32
-25
SDKConfig.java
...uidnet/service/dragon/channel/unionpay/sdk/SDKConfig.java
+9
-536
SDKUtil.java
...iquidnet/service/dragon/channel/unionpay/sdk/SDKUtil.java
+21
-17
SecureUtil.java
...idnet/service/dragon/channel/unionpay/sdk/SecureUtil.java
+14
-14
TestSdkConfig.java
...pl/src/test/java/com/liquidnet/service/TestSdkConfig.java
+36
-0
No files found.
liquidnet-bus-service/liquidnet-service-dragon/liquidnet-service-dragon-impl/src/main/java/com/liquidnet/service/ServiceDragonApplication.java
View file @
cb347737
...
@@ -4,7 +4,9 @@ import lombok.extern.slf4j.Slf4j;
...
@@ -4,7 +4,9 @@ import lombok.extern.slf4j.Slf4j;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.CommandLineRunner
;
import
org.springframework.boot.CommandLineRunner
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.EnableAutoConfiguration
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.core.env.Environment
;
import
org.springframework.core.env.Environment
;
import
java.net.InetAddress
;
import
java.net.InetAddress
;
...
@@ -12,6 +14,7 @@ import java.util.Arrays;
...
@@ -12,6 +14,7 @@ import java.util.Arrays;
@Slf4j
@Slf4j
@SpringBootApplication
(
scanBasePackages
=
{
"com.liquidnet"
})
@SpringBootApplication
(
scanBasePackages
=
{
"com.liquidnet"
})
@EnableConfigurationProperties
public
class
ServiceDragonApplication
implements
CommandLineRunner
{
public
class
ServiceDragonApplication
implements
CommandLineRunner
{
@Autowired
@Autowired
private
Environment
environment
;
private
Environment
environment
;
...
...
liquidnet-bus-service/liquidnet-service-dragon/liquidnet-service-dragon-impl/src/main/java/com/liquidnet/service/dragon/channel/unionpay/sdk/Acp6Service.java
View file @
cb347737
This diff is collapsed.
Click to expand it.
liquidnet-bus-service/liquidnet-service-dragon/liquidnet-service-dragon-impl/src/main/java/com/liquidnet/service/dragon/channel/unionpay/sdk/AcpService.java
View file @
cb347737
This diff is collapsed.
Click to expand it.
liquidnet-bus-service/liquidnet-service-dragon/liquidnet-service-dragon-impl/src/main/java/com/liquidnet/service/dragon/channel/unionpay/sdk/CertUtil.java
View file @
cb347737
This diff is collapsed.
Click to expand it.
liquidnet-bus-service/liquidnet-service-dragon/liquidnet-service-dragon-impl/src/main/java/com/liquidnet/service/dragon/channel/unionpay/sdk/QrcService.java
View file @
cb347737
...
@@ -2,6 +2,8 @@ package com.liquidnet.service.dragon.channel.unionpay.sdk;
...
@@ -2,6 +2,8 @@ package com.liquidnet.service.dragon.channel.unionpay.sdk;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.codec.binary.Base64
;
import
org.apache.commons.codec.binary.Base64
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.nio.charset.Charset
;
import
java.nio.charset.Charset
;
...
@@ -16,8 +18,13 @@ import static com.liquidnet.service.dragon.channel.unionpay.sdk.SDKConstants.*;
...
@@ -16,8 +18,13 @@ import static com.liquidnet.service.dragon.channel.unionpay.sdk.SDKConstants.*;
* @date 2018-12-10 下午2:44:37
* @date 2018-12-10 下午2:44:37
*/
*/
@Slf4j
@Slf4j
@Component
public
class
QrcService
{
public
class
QrcService
{
@Autowired
private
SDKConfig
sdkConfig
;
@Autowired
private
CertUtil
certUtil
;
/**
/**
* 请求报文签名(使用配置文件中配置的私钥证书或者对称密钥签名)<br>
* 请求报文签名(使用配置文件中配置的私钥证书或者对称密钥签名)<br>
* 功能:对请求报文进行签名,并计算赋值certid,signature字段并返回<br>
* 功能:对请求报文进行签名,并计算赋值certid,signature字段并返回<br>
...
@@ -25,10 +32,10 @@ public class QrcService {
...
@@ -25,10 +32,10 @@ public class QrcService {
* @param encoding 上送请求报文域encoding字段的值<br>
* @param encoding 上送请求报文域encoding字段的值<br>
* @return 签名后的map对象<br>
* @return 签名后的map对象<br>
*/
*/
public
static
Map
<
String
,
String
>
sign
(
Map
<
String
,
String
>
reqData
,
String
encoding
)
{
public
Map
<
String
,
String
>
sign
(
Map
<
String
,
String
>
reqData
,
String
encoding
)
{
return
signByCertInfo
(
reqData
,
SDKConfig
.
getConfig
().
getSignCertPath
(),
SDKConfig
.
getConfig
()
.
getSignCertPwd
(),
encoding
);
return
signByCertInfo
(
reqData
,
sdkConfig
.
getSignCertPath
(),
sdkConfig
.
getSignCertPwd
(),
encoding
);
}
}
/**
/**
* 多证书签名(通过传入私钥证书路径和密码签名)<br>
* 多证书签名(通过传入私钥证书路径和密码签名)<br>
* 功能:如果有多个商户号接入银联,每个商户号对应不同的证书可以使用此方法:传入私钥证书和密码(并且在acp_sdk.properties中 配置 acpsdk.singleMode=false)<br>
* 功能:如果有多个商户号接入银联,每个商户号对应不同的证书可以使用此方法:传入私钥证书和密码(并且在acp_sdk.properties中 配置 acpsdk.singleMode=false)<br>
...
@@ -38,7 +45,7 @@ public class QrcService {
...
@@ -38,7 +45,7 @@ public class QrcService {
* @param encoding 上送请求报文域encoding字段的值<br>
* @param encoding 上送请求报文域encoding字段的值<br>
* @return 签名后的map对象<br>
* @return 签名后的map对象<br>
*/
*/
public
static
Map
<
String
,
String
>
signByCertInfo
(
Map
<
String
,
String
>
reqData
,
String
certPath
,
public
Map
<
String
,
String
>
signByCertInfo
(
Map
<
String
,
String
>
reqData
,
String
certPath
,
String
certPwd
,
String
encoding
)
{
String
certPwd
,
String
encoding
)
{
Map
<
String
,
String
>
data
=
SDKUtil
.
filterBlank
(
reqData
);
Map
<
String
,
String
>
data
=
SDKUtil
.
filterBlank
(
reqData
);
...
@@ -62,14 +69,14 @@ public class QrcService {
...
@@ -62,14 +69,14 @@ public class QrcService {
try
{
try
{
if
(
VERSION_1_0_0
.
equals
(
version
))
{
if
(
VERSION_1_0_0
.
equals
(
version
))
{
//被扫脱机码两个接口无视配置固定按sha256withrsa处理。下面两个ifelse别改变顺序。
//被扫脱机码两个接口无视配置固定按sha256withrsa处理。下面两个ifelse别改变顺序。
if
(
QRC_SIGNTYPE_SHA256WITHRSA
.
equals
(
signType
)
if
(
QRC_SIGNTYPE_SHA256WITHRSA
.
equals
(
signType
)
||
"0420000903"
.
equals
(
reqType
)
||
"0420000903"
.
equals
(
reqType
)
||
"0410000903"
.
equals
(
reqType
))
{
||
"0410000903"
.
equals
(
reqType
))
{
data
.
put
(
SDKConstants
.
param_certId
,
C
ertUtil
.
getCertIdByKeyStoreMap
(
certPath
,
certPwd
));
data
.
put
(
SDKConstants
.
param_certId
,
c
ertUtil
.
getCertIdByKeyStoreMap
(
certPath
,
certPwd
));
data
.
put
(
SDKConstants
.
param_signature
,
SDKUtil
.
signRsa2
(
data
,
certPath
,
certPwd
,
encoding
));
data
.
put
(
SDKConstants
.
param_signature
,
SDKUtil
.
signRsa2
(
data
,
certPath
,
certPwd
,
encoding
));
return
data
;
return
data
;
}
else
if
(
QRC_SIGNTYPE_SHA1WITHRSA
.
equals
(
signType
))
{
}
else
if
(
QRC_SIGNTYPE_SHA1WITHRSA
.
equals
(
signType
))
{
data
.
put
(
SDKConstants
.
param_certId
,
C
ertUtil
.
getCertIdByKeyStoreMap
(
certPath
,
certPwd
));
data
.
put
(
SDKConstants
.
param_certId
,
c
ertUtil
.
getCertIdByKeyStoreMap
(
certPath
,
certPwd
));
data
.
put
(
SDKConstants
.
param_signature
,
SDKUtil
.
signRsa
(
data
,
certPath
,
certPwd
,
encoding
));
data
.
put
(
SDKConstants
.
param_signature
,
SDKUtil
.
signRsa
(
data
,
certPath
,
certPwd
,
encoding
));
return
data
;
return
data
;
}
else
if
(
QRC_SIGNTYPE_SM3WITHSM2
.
equals
(
signType
))
{
}
else
if
(
QRC_SIGNTYPE_SM3WITHSM2
.
equals
(
signType
))
{
...
@@ -91,14 +98,14 @@ public class QrcService {
...
@@ -91,14 +98,14 @@ public class QrcService {
* @param encoding 上送请求报文域encoding字段的值<br>
* @param encoding 上送请求报文域encoding字段的值<br>
* @return true 通过 false 未通过<br>
* @return true 通过 false 未通过<br>
*/
*/
public
static
boolean
validate
(
Map
<
String
,
String
>
resData
,
String
encoding
)
{
public
boolean
validate
(
Map
<
String
,
String
>
resData
,
String
encoding
)
{
log
.
info
(
"验签处理开始"
);
log
.
info
(
"验签处理开始"
);
if
(
SDKUtil
.
isEmpty
(
encoding
))
{
if
(
SDKUtil
.
isEmpty
(
encoding
))
{
encoding
=
"UTF-8"
;
encoding
=
"UTF-8"
;
}
}
String
certId
=
resData
.
get
(
SDKConstants
.
param_certId
);
String
certId
=
resData
.
get
(
SDKConstants
.
param_certId
);
log
.
info
(
"对返回报文串验签使用的验签公钥序列号:["
+
certId
+
"]"
);
log
.
info
(
"对返回报文串验签使用的验签公钥序列号:["
+
certId
+
"]"
);
PublicKey
verifyKey
=
C
ertUtil
.
getValidatePublicKey
(
certId
);
PublicKey
verifyKey
=
c
ertUtil
.
getValidatePublicKey
(
certId
);
if
(
verifyKey
==
null
)
{
if
(
verifyKey
==
null
)
{
log
.
error
(
"未找到此序列号证书。"
);
log
.
error
(
"未找到此序列号证书。"
);
return
false
;
return
false
;
...
@@ -110,13 +117,13 @@ public class QrcService {
...
@@ -110,13 +117,13 @@ public class QrcService {
if
(
SDKUtil
.
isEmpty
(
signType
))
{
if
(
SDKUtil
.
isEmpty
(
signType
))
{
signType
=
QRC_SIGNTYPE_SHA1WITHRSA
;
signType
=
QRC_SIGNTYPE_SHA1WITHRSA
;
}
}
try
{
try
{
if
(
VERSION_1_0_0
.
equals
(
version
))
{
if
(
VERSION_1_0_0
.
equals
(
version
))
{
//被扫脱机码两个接口无视配置固定按sha256withrsa处理。下面两个ifelse别改变顺序。
//被扫脱机码两个接口无视配置固定按sha256withrsa处理。下面两个ifelse别改变顺序。
if
(
QRC_SIGNTYPE_SHA256WITHRSA
.
equals
(
signType
)
if
(
QRC_SIGNTYPE_SHA256WITHRSA
.
equals
(
signType
)
||
"0420000903"
.
equals
(
reqType
)
||
"0420000903"
.
equals
(
reqType
)
||
"0410000903"
.
equals
(
reqType
))
{
||
"0410000903"
.
equals
(
reqType
))
{
boolean
result
=
SDKUtil
.
verifyRsa2
(
resData
,
verifyKey
,
encoding
);
boolean
result
=
SDKUtil
.
verifyRsa2
(
resData
,
verifyKey
,
encoding
);
log
.
info
(
"验签"
+
(
result
?
"成功"
:
"失败"
)
+
"。"
);
log
.
info
(
"验签"
+
(
result
?
"成功"
:
"失败"
)
+
"。"
);
return
result
;
return
result
;
...
@@ -147,7 +154,7 @@ public class QrcService {
...
@@ -147,7 +154,7 @@ public class QrcService {
public
static
String
encryptPin
(
String
accNo
,
String
pin
,
String
encoding
)
{
public
static
String
encryptPin
(
String
accNo
,
String
pin
,
String
encoding
)
{
return
AcpService
.
encryptPin
(
accNo
,
pin
,
encoding
);
return
AcpService
.
encryptPin
(
accNo
,
pin
,
encoding
);
}
}
/**
/**
* 敏感信息加密并做base64(卡号,手机号,cvn2,有效期)<br>
* 敏感信息加密并做base64(卡号,手机号,cvn2,有效期)<br>
* @param data 送 phoneNo,cvn2,有效期<br>
* @param data 送 phoneNo,cvn2,有效期<br>
...
@@ -157,7 +164,7 @@ public class QrcService {
...
@@ -157,7 +164,7 @@ public class QrcService {
public
static
String
encryptData
(
String
data
,
String
encoding
)
{
public
static
String
encryptData
(
String
data
,
String
encoding
)
{
return
AcpService
.
encryptData
(
data
,
encoding
);
return
AcpService
.
encryptData
(
data
,
encoding
);
}
}
/**
/**
* 敏感信息解密,使用配置文件acp_sdk.properties解密<br>
* 敏感信息解密,使用配置文件acp_sdk.properties解密<br>
* @param base64EncryptedInfo 加密信息<br>
* @param base64EncryptedInfo 加密信息<br>
...
@@ -176,19 +183,19 @@ public class QrcService {
...
@@ -176,19 +183,19 @@ public class QrcService {
* @param encoding<br>
* @param encoding<br>
* @return
* @return
*/
*/
public
static
String
decryptData
(
String
base64EncryptedInfo
,
String
certPath
,
public
static
String
decryptData
(
String
base64EncryptedInfo
,
String
certPath
,
String
certPwd
,
String
encoding
)
{
String
certPwd
,
String
encoding
)
{
return
AcpService
.
decryptData
(
base64EncryptedInfo
,
certPath
,
certPwd
,
encoding
);
return
AcpService
.
decryptData
(
base64EncryptedInfo
,
certPath
,
certPwd
,
encoding
);
}
}
/**
/**
* 获取敏感信息加密证书的物理序列号<br>
* 获取敏感信息加密证书的物理序列号<br>
* @return
* @return
*/
*/
public
static
String
getEncryptCertId
(){
public
String
getEncryptCertId
(){
return
C
ertUtil
.
getEncryptCert
().
certId
;
return
c
ertUtil
.
getEncryptCert
().
certId
;
}
}
/**
/**
* 功能:后台交易提交请求报文并接收同步应答报文<br>
* 功能:后台交易提交请求报文并接收同步应答报文<br>
* @param reqData 请求报文<br>
* @param reqData 请求报文<br>
...
@@ -199,7 +206,7 @@ public class QrcService {
...
@@ -199,7 +206,7 @@ public class QrcService {
public
static
Map
<
String
,
String
>
post
(
Map
<
String
,
String
>
reqData
,
String
reqUrl
,
String
encoding
)
{
public
static
Map
<
String
,
String
>
post
(
Map
<
String
,
String
>
reqData
,
String
reqUrl
,
String
encoding
)
{
return
AcpService
.
post
(
reqData
,
reqUrl
,
encoding
);
return
AcpService
.
post
(
reqData
,
reqUrl
,
encoding
);
}
}
/**
/**
* base64({a=b&c=d})
* base64({a=b&c=d})
* @param map
* @param map
...
@@ -213,7 +220,7 @@ public class QrcService {
...
@@ -213,7 +220,7 @@ public class QrcService {
.
append
(
SDKConstants
.
RIGHT_BRACE
).
toString
();
.
append
(
SDKConstants
.
RIGHT_BRACE
).
toString
();
return
Base64
.
encodeBase64String
(
info
.
getBytes
(
Charset
.
forName
(
encoding
)));
return
Base64
.
encodeBase64String
(
info
.
getBytes
(
Charset
.
forName
(
encoding
)));
}
}
/**
/**
* base64(rsa({a=b&c=d}))
* base64(rsa({a=b&c=d}))
* @param map
* @param map
...
@@ -240,7 +247,7 @@ public class QrcService {
...
@@ -240,7 +247,7 @@ public class QrcService {
data
=
data
.
substring
(
1
,
data
.
length
()
-
1
);
data
=
data
.
substring
(
1
,
data
.
length
()
-
1
);
return
SDKUtil
.
parseRespString
(
data
);
return
SDKUtil
.
parseRespString
(
data
);
}
}
/**
/**
* base64(rsa({a=b&c=d}))
* base64(rsa({a=b&c=d}))
* 解析返回报文的payerInfo域,敏感信息加密时使用:<br>
* 解析返回报文的payerInfo域,敏感信息加密时使用:<br>
...
@@ -253,7 +260,7 @@ public class QrcService {
...
@@ -253,7 +260,7 @@ public class QrcService {
data
=
data
.
substring
(
1
,
data
.
length
()
-
1
);
data
=
data
.
substring
(
1
,
data
.
length
()
-
1
);
return
SDKUtil
.
parseRespString
(
data
);
return
SDKUtil
.
parseRespString
(
data
);
}
}
/**
/**
* base64(rsa({a=b&c=d}))
* base64(rsa({a=b&c=d}))
* 解析返回报文中的payerInfo域,敏感信息加密时使用,多证书方式。<br>
* 解析返回报文中的payerInfo域,敏感信息加密时使用,多证书方式。<br>
...
@@ -261,7 +268,7 @@ public class QrcService {
...
@@ -261,7 +268,7 @@ public class QrcService {
* @param encoding<br>
* @param encoding<br>
* @return
* @return
*/
*/
public
static
Map
<
String
,
String
>
parseKVEncBase64Field
(
String
base64data
,
String
certPath
,
public
static
Map
<
String
,
String
>
parseKVEncBase64Field
(
String
base64data
,
String
certPath
,
String
certPwd
,
String
encoding
){
String
certPwd
,
String
encoding
){
String
data
=
QrcService
.
decryptData
(
base64data
,
certPath
,
certPwd
,
encoding
);
String
data
=
QrcService
.
decryptData
(
base64data
,
certPath
,
certPwd
,
encoding
);
data
=
data
.
substring
(
1
,
data
.
length
()
-
1
);
data
=
data
.
substring
(
1
,
data
.
length
()
-
1
);
...
@@ -290,10 +297,10 @@ public class QrcService {
...
@@ -290,10 +297,10 @@ public class QrcService {
public
static
String
base64Decode
(
String
base64Str
,
String
encoding
){
public
static
String
base64Decode
(
String
base64Str
,
String
encoding
){
return
AcpService
.
base64Decode
(
base64Str
,
encoding
);
return
AcpService
.
base64Decode
(
base64Str
,
encoding
);
}
}
/**
/**
* luhn算法
* luhn算法
*
*
* @param number
* @param number
* @return
* @return
*/
*/
...
...
liquidnet-bus-service/liquidnet-service-dragon/liquidnet-service-dragon-impl/src/main/java/com/liquidnet/service/dragon/channel/unionpay/sdk/SDKConfig.java
View file @
cb347737
This diff is collapsed.
Click to expand it.
liquidnet-bus-service/liquidnet-service-dragon/liquidnet-service-dragon-impl/src/main/java/com/liquidnet/service/dragon/channel/unionpay/sdk/SDKUtil.java
View file @
cb347737
/**
/**
*
*
* Licensed Property to China UnionPay Co., Ltd.
* Licensed Property to China UnionPay Co., Ltd.
*
*
* (C) Copyright of China UnionPay Co., Ltd. 2010
* (C) Copyright of China UnionPay Co., Ltd. 2010
* All Rights Reserved.
* All Rights Reserved.
*
*
*
*
* Modification History:
* Modification History:
* =============================================================================
* =============================================================================
* Author Date Description
* Author Date Description
...
@@ -19,6 +19,8 @@ import lombok.extern.slf4j.Slf4j;
...
@@ -19,6 +19,8 @@ import lombok.extern.slf4j.Slf4j;
import
org.apache.commons.codec.DecoderException
;
import
org.apache.commons.codec.DecoderException
;
import
org.apache.commons.codec.binary.Base64
;
import
org.apache.commons.codec.binary.Base64
;
import
org.apache.commons.codec.binary.Hex
;
import
org.apache.commons.codec.binary.Hex
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
java.io.ByteArrayOutputStream
;
import
java.io.ByteArrayOutputStream
;
import
java.io.IOException
;
import
java.io.IOException
;
...
@@ -33,14 +35,16 @@ import java.util.zip.Inflater;
...
@@ -33,14 +35,16 @@ import java.util.zip.Inflater;
import
static
com
.
liquidnet
.
service
.
dragon
.
channel
.
unionpay
.
sdk
.
SDKConstants
.*;
import
static
com
.
liquidnet
.
service
.
dragon
.
channel
.
unionpay
.
sdk
.
SDKConstants
.*;
/**
/**
*
*
* @ClassName SDKUtil
* @ClassName SDKUtil
* @Description acpsdk工具类
* @Description acpsdk工具类
* @date 2016-7-22 下午4:06:18
* @date 2016-7-22 下午4:06:18
*/
*/
@Slf4j
@Slf4j
@Component
public
class
SDKUtil
{
public
class
SDKUtil
{
@Autowired
private
CertUtil
certUtil
;
/**
/**
* 全渠道5.0、二维码signType=01用。
* 全渠道5.0、二维码signType=01用。
* 1. 按ascii排序。【注意不是字母顺序】
* 1. 按ascii排序。【注意不是字母顺序】
...
@@ -55,14 +59,14 @@ public class SDKUtil {
...
@@ -55,14 +59,14 @@ public class SDKUtil {
* @param encoding
* @param encoding
* @return
* @return
*/
*/
public
static
String
signRsa
(
Map
<
String
,
String
>
data
,
String
certPath
,
String
certPwd
,
String
encoding
)
{
public
String
signRsa
(
Map
<
String
,
String
>
data
,
String
certPath
,
String
certPwd
,
String
encoding
)
{
try
{
try
{
String
stringData
=
createLinkString
(
data
,
true
,
false
,
encoding
);
String
stringData
=
createLinkString
(
data
,
true
,
false
,
encoding
);
log
.
info
(
"打印排序后待签名请求报文串(交易返回11验证签名失败时可以用来同正确的进行比对):["
+
stringData
+
"]"
);
log
.
info
(
"打印排序后待签名请求报文串(交易返回11验证签名失败时可以用来同正确的进行比对):["
+
stringData
+
"]"
);
byte
[]
sha1
=
SecureUtil
.
sha1
(
stringData
.
getBytes
(
encoding
));
byte
[]
sha1
=
SecureUtil
.
sha1
(
stringData
.
getBytes
(
encoding
));
String
sha1Hex
=
byteArrayToHexString
(
sha1
).
toLowerCase
();
String
sha1Hex
=
byteArrayToHexString
(
sha1
).
toLowerCase
();
log
.
info
(
"sha1结果(交易返回11验证签名失败可以用来同正确的进行比对):["
+
sha1Hex
+
"]"
);
log
.
info
(
"sha1结果(交易返回11验证签名失败可以用来同正确的进行比对):["
+
sha1Hex
+
"]"
);
return
Base64
.
encodeBase64String
(
SecureUtil
.
getSignature
(
C
ertUtil
.
getSignCertPrivateKeyByStoreMap
(
certPath
,
certPwd
),
sha1Hex
.
getBytes
()));
return
Base64
.
encodeBase64String
(
SecureUtil
.
getSignature
(
c
ertUtil
.
getSignCertPrivateKeyByStoreMap
(
certPath
,
certPwd
),
sha1Hex
.
getBytes
()));
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
log
.
error
(
"calcSignRsa Error"
,
e
);
log
.
error
(
"calcSignRsa Error"
,
e
);
return
null
;
return
null
;
...
@@ -83,14 +87,14 @@ public class SDKUtil {
...
@@ -83,14 +87,14 @@ public class SDKUtil {
* @param encoding
* @param encoding
* @return
* @return
*/
*/
public
static
String
signRsa2
(
Map
<
String
,
String
>
data
,
String
certPath
,
String
certPwd
,
String
encoding
)
{
public
String
signRsa2
(
Map
<
String
,
String
>
data
,
String
certPath
,
String
certPwd
,
String
encoding
)
{
try
{
try
{
String
stringData
=
createLinkString
(
data
,
true
,
false
,
encoding
);
String
stringData
=
createLinkString
(
data
,
true
,
false
,
encoding
);
log
.
info
(
"打印排序后待签名请求报文串(交易返回11验证签名失败时可以用来同正确的进行比对):["
+
stringData
+
"]"
);
log
.
info
(
"打印排序后待签名请求报文串(交易返回11验证签名失败时可以用来同正确的进行比对):["
+
stringData
+
"]"
);
byte
[]
sha256
=
SecureUtil
.
sha256
(
stringData
.
getBytes
(
encoding
));
byte
[]
sha256
=
SecureUtil
.
sha256
(
stringData
.
getBytes
(
encoding
));
String
sha256Hex
=
byteArrayToHexString
(
sha256
).
toLowerCase
();
String
sha256Hex
=
byteArrayToHexString
(
sha256
).
toLowerCase
();
log
.
info
(
"sha256(交易返回11验证签名失败可以用来同正确的进行比对):["
+
sha256Hex
+
"]"
);
log
.
info
(
"sha256(交易返回11验证签名失败可以用来同正确的进行比对):["
+
sha256Hex
+
"]"
);
return
Base64
.
encodeBase64String
(
SecureUtil
.
getSignatureSHA256
(
C
ertUtil
.
getSignCertPrivateKeyByStoreMap
(
certPath
,
certPwd
),
sha256Hex
.
getBytes
()));
return
Base64
.
encodeBase64String
(
SecureUtil
.
getSignatureSHA256
(
c
ertUtil
.
getSignCertPrivateKeyByStoreMap
(
certPath
,
certPwd
),
sha256Hex
.
getBytes
()));
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
log
.
error
(
"calcSignRsa2 Error"
,
e
);
log
.
error
(
"calcSignRsa2 Error"
,
e
);
return
null
;
return
null
;
...
@@ -426,15 +430,15 @@ public class SDKUtil {
...
@@ -426,15 +430,15 @@ public class SDKUtil {
* @param certType
* @param certType
* @return
* @return
*/
*/
public
static
int
updateEncryptCert
(
String
strCert
,
String
certType
)
{
public
int
updateEncryptCert
(
String
strCert
,
String
certType
)
{
if
(
isEmpty
(
strCert
)
||
isEmpty
(
certType
))
if
(
isEmpty
(
strCert
)
||
isEmpty
(
certType
))
return
-
1
;
return
-
1
;
if
(
CERTTYPE_01
.
equals
(
certType
))
{
if
(
CERTTYPE_01
.
equals
(
certType
))
{
// 更新敏感信息加密公钥
// 更新敏感信息加密公钥
return
C
ertUtil
.
resetEncryptCertPublicKey
(
strCert
);
return
c
ertUtil
.
resetEncryptCertPublicKey
(
strCert
);
}
else
if
(
CERTTYPE_02
.
equals
(
certType
))
{
}
else
if
(
CERTTYPE_02
.
equals
(
certType
))
{
// 更新pin敏感信息加密公钥
// 更新pin敏感信息加密公钥
return
C
ertUtil
.
resetPinEncryptCertPublicKey
(
strCert
);
return
c
ertUtil
.
resetPinEncryptCertPublicKey
(
strCert
);
}
else
{
}
else
{
log
.
info
(
"unknown cerType:"
+
certType
);
log
.
info
(
"unknown cerType:"
+
certType
);
return
-
1
;
return
-
1
;
...
@@ -449,7 +453,7 @@ public class SDKUtil {
...
@@ -449,7 +453,7 @@ public class SDKUtil {
public
static
Map
<
String
,
String
>
filterBlank
(
Map
<
String
,
String
>
contentData
){
public
static
Map
<
String
,
String
>
filterBlank
(
Map
<
String
,
String
>
contentData
){
Map
<
String
,
String
>
submitFromData
=
new
HashMap
<
String
,
String
>();
Map
<
String
,
String
>
submitFromData
=
new
HashMap
<
String
,
String
>();
Set
<
String
>
keyset
=
contentData
.
keySet
();
Set
<
String
>
keyset
=
contentData
.
keySet
();
for
(
String
key
:
keyset
){
for
(
String
key
:
keyset
){
String
value
=
contentData
.
get
(
key
);
String
value
=
contentData
.
get
(
key
);
if
(!
isEmpty
(
value
))
{
if
(!
isEmpty
(
value
))
{
...
@@ -458,10 +462,10 @@ public class SDKUtil {
...
@@ -458,10 +462,10 @@ public class SDKUtil {
}
}
return
submitFromData
;
return
submitFromData
;
}
}
/**
/**
* 解压缩.
* 解压缩.
*
*
* @param inputByte
* @param inputByte
* byte[]数组类型的数据
* byte[]数组类型的数据
* @return 解压缩后的数据
* @return 解压缩后的数据
...
@@ -492,7 +496,7 @@ public class SDKUtil {
...
@@ -492,7 +496,7 @@ public class SDKUtil {
/**
/**
* 压缩.
* 压缩.
*
*
* @param inputByte
* @param inputByte
* 需要解压缩的byte[]数组
* 需要解压缩的byte[]数组
* @return 压缩后的数据
* @return 压缩后的数据
...
@@ -516,10 +520,10 @@ public class SDKUtil {
...
@@ -516,10 +520,10 @@ public class SDKUtil {
compresser
.
end
();
compresser
.
end
();
return
o
.
toByteArray
();
return
o
.
toByteArray
();
}
}
/**
/**
* 判断字符串是否为NULL或空
* 判断字符串是否为NULL或空
*
*
* @param s
* @param s
* 待判断的字符串数据
* 待判断的字符串数据
* @return 判断结果 true-是 false-否
* @return 判断结果 true-是 false-否
...
...
liquidnet-bus-service/liquidnet-service-dragon/liquidnet-service-dragon-impl/src/main/java/com/liquidnet/service/dragon/channel/unionpay/sdk/SecureUtil.java
View file @
cb347737
/**
/**
*
*
* Licensed Property to China UnionPay Co., Ltd.
* Licensed Property to China UnionPay Co., Ltd.
*
*
* (C) Copyright of China UnionPay Co., Ltd. 2010
* (C) Copyright of China UnionPay Co., Ltd. 2010
* All Rights Reserved.
* All Rights Reserved.
*
*
*
*
* Modification History:
* Modification History:
* =============================================================================
* =============================================================================
* Author Date Description
* Author Date Description
...
@@ -210,7 +210,7 @@ public class SecureUtil {
...
@@ -210,7 +210,7 @@ public class SecureUtil {
return
null
;
return
null
;
}
}
}
}
// /**
// /**
// * ANSI X9.8格式(不带主账号信息)pinblock
// * ANSI X9.8格式(不带主账号信息)pinblock
// * @param pin
// * @param pin
...
@@ -238,29 +238,29 @@ public class SecureUtil {
...
@@ -238,29 +238,29 @@ public class SecureUtil {
// return null;
// return null;
// }
// }
// }
// }
public
static
byte
[]
tripleDesEncryptECBPKCS5Padding
(
byte
[]
key
,
byte
[]
data
)
{
public
static
byte
[]
tripleDesEncryptECBPKCS5Padding
(
byte
[]
key
,
byte
[]
data
)
{
try
{
try
{
if
(
data
==
null
||
data
.
length
%
8
!=
0
)
if
(
data
==
null
||
data
.
length
%
8
!=
0
)
throw
new
IllegalArgumentException
(
"data is null or error data length."
);
throw
new
IllegalArgumentException
(
"data is null or error data length."
);
SecretKey
sk
=
getTripleDesKey
(
key
);
SecretKey
sk
=
getTripleDesKey
(
key
);
Cipher
cipher
=
Cipher
.
getInstance
(
"DESede/ECB/PKCS5Padding"
);
Cipher
cipher
=
Cipher
.
getInstance
(
"DESede/ECB/PKCS5Padding"
);
cipher
.
init
(
Cipher
.
ENCRYPT_MODE
,
sk
);
cipher
.
init
(
Cipher
.
ENCRYPT_MODE
,
sk
);
return
cipher
.
doFinal
(
data
);
return
cipher
.
doFinal
(
data
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
log
.
error
(
"加密失败"
,
e
);
log
.
error
(
"加密失败"
,
e
);
return
null
;
return
null
;
}
}
}
}
/**
/**
* 后补0到位数为unitLength的整数倍
* 后补0到位数为unitLength的整数倍
* @param value
* @param value
* @return
* @return
*/
*/
public
static
byte
[]
rightPadZero
(
byte
[]
value
,
final
int
unitLength
){
public
static
byte
[]
rightPadZero
(
byte
[]
value
,
final
int
unitLength
){
if
(
value
.
length
%
unitLength
==
0
)
if
(
value
.
length
%
unitLength
==
0
)
...
@@ -268,7 +268,7 @@ public class SecureUtil {
...
@@ -268,7 +268,7 @@ public class SecureUtil {
int
len
=
(
value
.
length
/
unitLength
+
1
)
*
unitLength
;
int
len
=
(
value
.
length
/
unitLength
+
1
)
*
unitLength
;
return
Arrays
.
copyOf
(
value
,
len
);
return
Arrays
.
copyOf
(
value
,
len
);
}
}
/**
/**
* 通过byte数组得到SecretKey类型的密钥
* 通过byte数组得到SecretKey类型的密钥
* @param key
* @param key
...
@@ -276,12 +276,12 @@ public class SecureUtil {
...
@@ -276,12 +276,12 @@ public class SecureUtil {
* @throws IllegalArgumentException
* @throws IllegalArgumentException
*/
*/
private
static
SecretKey
getTripleDesKey
(
byte
[]
key
)
{
private
static
SecretKey
getTripleDesKey
(
byte
[]
key
)
{
if
(
key
==
null
||
!(
key
.
length
==
8
||
key
.
length
==
16
||
key
.
length
==
24
))
if
(
key
==
null
||
!(
key
.
length
==
8
||
key
.
length
==
16
||
key
.
length
==
24
))
throw
new
IllegalArgumentException
(
"key is null or error key length."
);
throw
new
IllegalArgumentException
(
"key is null or error key length."
);
byte
[]
specKey
=
new
byte
[
24
];
byte
[]
specKey
=
new
byte
[
24
];
try
{
try
{
switch
(
key
.
length
)
{
switch
(
key
.
length
)
{
case
16
:
case
16
:
...
...
liquidnet-bus-service/liquidnet-service-dragon/liquidnet-service-dragon-impl/src/test/java/com/liquidnet/service/TestSdkConfig.java
0 → 100644
View file @
cb347737
package
com
.
liquidnet
.
service
;
import
com.liquidnet.service.dragon.channel.unionpay.sdk.SDKConfig
;
import
lombok.extern.slf4j.Slf4j
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
/**
* @author AnJiabin <anjiabin@zhengzai.tv>
* @version V1.0
* @Description: TODO
* @class: TestSdkConfig
* @Package com.liquidnet.service
* @Copyright: LightNet @ Copyright (c) 2021
* @date 2021/11/9 10:57
*/
@Slf4j
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@SpringBootTest
public
class
TestSdkConfig
{
@Autowired
private
SDKConfig
sdkConfig
;
@Test
public
void
pringSdkConfigInfo
(){
System
.
out
.
println
(
sdkConfig
.
getFileTransUrl
());
System
.
out
.
println
(
sdkConfig
.
getSignCertPath
());
System
.
out
.
println
(
sdkConfig
.
getSignCertPwd
());
System
.
out
.
println
(
sdkConfig
.
getSignCertType
());
System
.
out
.
println
(
sdkConfig
.
getEncryptCertPath
());
System
.
out
.
println
(
sdkConfig
.
getMiddleCertPath
());
System
.
out
.
println
(
sdkConfig
.
getRootCertPath
());
}
}
Write
Preview
Markdown
is supported
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