Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
W
windows
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
zhanhai
windows
Commits
6a2bdb01
Commit
6a2bdb01
authored
Oct 23, 2023
by
张庆
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
新增挡板规则
parent
f89391bd
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
211 additions
and
13 deletions
+211
-13
ZNPostUrlEnum.java
.../java/com/jqtx/windows/component/enums/ZNPostUrlEnum.java
+3
-3
ZyHttpBaseResponse.java
.../com/jqtx/windows/component/model/ZyHttpBaseResponse.java
+24
-0
ZyHttpBaseRquest.java
...va/com/jqtx/windows/component/model/ZyHttpBaseRquest.java
+20
-0
AbcHttpClient.java
src/main/java/com/jqtx/windows/utils/AbcHttpClient.java
+32
-10
EncryptUtil.java
src/main/java/com/jqtx/windows/utils/EncryptUtil.java
+87
-0
SignUtil.java
src/main/java/com/jqtx/windows/utils/SignUtil.java
+45
-0
No files found.
src/main/java/com/jqtx/windows/component/enums/ZNPostUrlEnum.java
View file @
6a2bdb01
...
...
@@ -2,9 +2,9 @@ package com.jqtx.windows.component.enums;
public
enum
ZNPostUrlEnum
{
CREDIT_CALL
(
"
/test_1
"
,
"授信状态推送Url"
),
LOAN_CALL
(
"
/test_2
"
,
"借款状态推送Url"
),
PROTOCOL_CALL
(
"
/test_3
"
,
"协议状态推送Url"
),
CREDIT_CALL
(
"
creditNotify
"
,
"授信状态推送Url"
),
LOAN_CALL
(
"
loadNotify
"
,
"借款状态推送Url"
),
PROTOCOL_CALL
(
"
guaranteeSign
"
,
"协议状态推送Url"
),
;
ZNPostUrlEnum
(
String
code
,
String
msg
)
{
...
...
src/main/java/com/jqtx/windows/component/model/ZyHttpBaseResponse.java
0 → 100644
View file @
6a2bdb01
package
com
.
jqtx
.
windows
.
component
.
model
;
import
lombok.Data
;
@Data
public
class
ZyHttpBaseResponse
{
private
String
clientld
;
private
String
serviceld
;
private
String
segNo
;
private
String
transDateTime
;
private
String
data
;
private
String
sign
;
private
String
returnCode
;
private
String
returnMsg
;
}
src/main/java/com/jqtx/windows/component/model/ZyHttpBaseRquest.java
0 → 100644
View file @
6a2bdb01
package
com
.
jqtx
.
windows
.
component
.
model
;
import
lombok.Data
;
@Data
public
class
ZyHttpBaseRquest
{
private
String
clientld
;
private
String
serviceld
;
private
String
segNo
;
private
String
transDateTime
;
private
String
data
;
private
String
sign
;
}
src/main/java/com/jqtx/windows/utils/AbcHttpClient.java
View file @
6a2bdb01
package
com
.
jqtx
.
windows
.
utils
;
import
cn.hutool.core.lang.UUID
;
import
cn.hutool.http.HttpRequest
;
import
cn.hutool.http.HttpResponse
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
com.jqtx.windows.component.model.ZyHttpBaseResponse
;
import
com.jqtx.windows.component.model.ZyHttpBaseRquest
;
import
com.jqtx.windows.web.request.AbcRequest
;
import
com.jqtx.windows.web.response.JsonResult
;
import
lombok.extern.slf4j.Slf4j
;
...
...
@@ -11,6 +14,8 @@ import org.apache.commons.lang.StringUtils;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Component
;
import
java.time.LocalDateTime
;
@Slf4j
@Component
public
class
AbcHttpClient
{
...
...
@@ -23,25 +28,41 @@ public class AbcHttpClient {
@Value
(
"${zhenong.publicKey}"
)
private
String
ypdPublicKey
;
private
String
appId
=
"660010"
;
public
JsonResult
postRequest
(
String
paramJson
,
String
method
)
{
@Value
(
"${zhenong.clientId}"
)
private
String
clientId
;
public
ZyHttpBaseResponse
postRequest
(
String
paramJson
,
String
method
)
{
try
{
final
String
url
=
posetUrl
+
method
;
AbcRequest
request
=
AbcRsaUtil
.
encodeParam
(
paramJson
,
ypdPublicKey
,
appId
,
privateKey
);
final
String
url
=
posetUrl
;
ZyHttpBaseRquest
zyHttpBaseRquest
=
new
ZyHttpBaseRquest
();
zyHttpBaseRquest
.
setClientld
(
clientId
);
zyHttpBaseRquest
.
setServiceld
(
method
);
zyHttpBaseRquest
.
setSegNo
(
UUID
.
fastUUID
().
toString
());
zyHttpBaseRquest
.
setTransDateTime
(
LocalDateTime
.
now
().
toString
());
String
responseParam
=
EncryptUtil
.
encrypt
(
paramJson
,
AbcRsaUtil
.
getPublicKey
(
ypdPublicKey
));
String
responseSign
=
SignUtil
.
sign
(
responseParam
,
AbcRsaUtil
.
getPrivateKey
(
privateKey
));
zyHttpBaseRquest
.
setData
(
responseParam
);
zyHttpBaseRquest
.
setSign
(
responseSign
);
log
.
info
(
"请求浙农未加密数据:{}"
,
JSON
.
toJSONString
(
paramJson
));
log
.
info
(
"请求浙农加密数据:{}"
,
JSON
.
toJSONString
(
re
quest
));
log
.
info
(
"请求浙农加密数据:{}"
,
JSON
.
toJSONString
(
zyHttpBaseR
quest
));
log
.
info
(
"请求浙农url:{}"
,
url
);
HttpResponse
response
=
HttpRequest
.
post
(
url
).
body
(
JSON
.
toJSONString
(
re
quest
)).
setConnectionTimeout
(
5000
).
execute
();
HttpResponse
response
=
HttpRequest
.
post
(
url
).
body
(
JSON
.
toJSONString
(
zyHttpBaseR
quest
)).
setConnectionTimeout
(
5000
).
execute
();
log
.
info
(
"请求浙农加密返回数据:{}"
,
JSON
.
toJSONString
(
response
.
body
()));
if
(
response
.
getStatus
()
==
200
&&
StringUtils
.
isNotBlank
(
response
.
body
()))
{
final
String
body
=
response
.
body
();
JSONObject
responseJson
=
JSONObject
.
parseObject
(
body
);
String
content
=
responseJson
.
getString
(
"content
"
);
String
data
=
responseJson
.
getString
(
"data
"
);
String
sign
=
responseJson
.
getString
(
"sign"
);
String
responseParam
=
AbcRsaUtil
.
decodeParam
(
content
,
sign
,
privateKey
,
ypdPublicKey
);
log
.
info
(
"请求浙农解密返回数据:{}"
,
JSON
.
toJSONString
(
responseParam
));
return
JSONObject
.
parseObject
(
responseParam
,
JsonResult
.
class
);
boolean
f
=
SignUtil
.
veriSign
(
data
,
sign
,
AbcRsaUtil
.
getPublicKey
(
ypdPublicKey
));
if
(
f
)
{
String
dec
=
EncryptUtil
.
decrypt
(
data
,
AbcRsaUtil
.
getPrivateKey
(
privateKey
));
log
.
info
(
"请求浙农解密返回数据:{}"
,
JSON
.
toJSONString
(
dec
));
return
JSONObject
.
parseObject
(
dec
,
ZyHttpBaseResponse
.
class
);
}
else
{
log
.
info
(
"验签异常"
);
}
}
else
{
throw
new
Exception
(
"请求异常"
);
}
...
...
@@ -49,5 +70,6 @@ public class AbcHttpClient {
log
.
error
(
"请求浙农异常:{}"
,
e
.
getMessage
(),
e
);
return
null
;
}
return
null
;
}
}
src/main/java/com/jqtx/windows/utils/EncryptUtil.java
0 → 100644
View file @
6a2bdb01
package
com
.
jqtx
.
windows
.
utils
;
import
org.springframework.util.Base64Utils
;
import
org.springframework.util.StringUtils
;
import
javax.crypto.Cipher
;
import
java.io.ByteArrayOutputStream
;
import
java.security.PrivateKey
;
import
java.security.PublicKey
;
/**
* @author: maweijun
* @description:
* @create: 2021/1/12
*/
public
class
EncryptUtil
{
private
static
final
String
encryptAlgorithm
=
"RSA"
;
// 加密算法
private
static
final
String
decryptAlgorithm
=
"RSA"
;
// 解密算法
private
static
final
String
charset
=
"UTF-8"
;
private
static
final
int
maxEncryptBlock
=
234
;
//2048位rsa单次最大加密长度
private
static
final
int
max_decrypt_block
=
256
;
//2048位rsa单次最大解密长度
public
static
String
encrypt
(
String
param
,
PublicKey
publicKey
)
{
if
(
publicKey
==
null
)
{
throw
new
RuntimeException
(
"公钥未初始化"
);
}
if
(
StringUtils
.
isEmpty
(
param
))
{
throw
new
IllegalArgumentException
(
"待加密数据为空"
);
}
try
(
ByteArrayOutputStream
out
=
new
ByteArrayOutputStream
())
{
Cipher
cipher
=
Cipher
.
getInstance
(
encryptAlgorithm
);
cipher
.
init
(
Cipher
.
ENCRYPT_MODE
,
publicKey
);
byte
[]
data
=
param
.
getBytes
(
charset
);
int
inputLen
=
data
.
length
;
int
offSet
=
0
;
byte
[]
cache
;
int
i
=
0
;
// 对数据分段加密
while
(
inputLen
-
offSet
>
0
)
{
if
(
inputLen
>
maxEncryptBlock
+
offSet
)
{
cache
=
cipher
.
doFinal
(
data
,
offSet
,
maxEncryptBlock
);
}
else
{
cache
=
cipher
.
doFinal
(
data
,
offSet
,
inputLen
-
offSet
);
}
out
.
write
(
cache
,
0
,
cache
.
length
);
i
++;
offSet
=
i
*
maxEncryptBlock
;
}
return
Base64Utils
.
encodeToString
(
out
.
toByteArray
());
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
"加密异常"
,
e
);
}
}
public
static
String
decrypt
(
String
param
,
PrivateKey
partnerPrivateKey
)
{
if
(
partnerPrivateKey
==
null
)
{
throw
new
RuntimeException
(
"私钥未初始化"
);
}
if
(
StringUtils
.
isEmpty
(
param
))
{
throw
new
IllegalArgumentException
(
"待解密数据为空"
);
}
try
(
ByteArrayOutputStream
out
=
new
ByteArrayOutputStream
())
{
Cipher
cipher
=
Cipher
.
getInstance
(
decryptAlgorithm
);
cipher
.
init
(
Cipher
.
DECRYPT_MODE
,
partnerPrivateKey
);
byte
[]
data
=
Base64Utils
.
decodeFromString
(
param
);
int
inputLen
=
data
.
length
;
int
offSet
=
0
;
byte
[]
cache
;
int
i
=
0
;
// 对数据分段解密
while
(
inputLen
-
offSet
>
0
)
{
if
(
inputLen
>
max_decrypt_block
+
offSet
)
{
cache
=
cipher
.
doFinal
(
data
,
offSet
,
max_decrypt_block
);
}
else
{
cache
=
cipher
.
doFinal
(
data
,
offSet
,
inputLen
-
offSet
);
}
i
++;
out
.
write
(
cache
,
0
,
cache
.
length
);
offSet
=
i
*
max_decrypt_block
;
}
return
new
String
(
out
.
toByteArray
(),
charset
);
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
"解密处理异常"
,
e
);
}
}
}
src/main/java/com/jqtx/windows/utils/SignUtil.java
0 → 100644
View file @
6a2bdb01
package
com
.
jqtx
.
windows
.
utils
;
import
org.springframework.util.Base64Utils
;
import
java.security.PrivateKey
;
import
java.security.PublicKey
;
import
java.security.Signature
;
/**
* @author: maweijun
* @description:
* @create: 2021/1/12
*/
public
class
SignUtil
{
private
static
final
String
signature_algorithm
=
"SHA256withRSA"
;
// 签名算法
private
static
final
String
charset
=
"UTF-8"
;
public
static
String
sign
(
String
param
,
PrivateKey
partnerPrivateKey
)
{
try
{
if
(
partnerPrivateKey
==
null
)
{
throw
new
RuntimeException
(
"私钥未初始化"
);
}
Signature
signature
=
Signature
.
getInstance
(
signature_algorithm
);
signature
.
initSign
(
partnerPrivateKey
);
signature
.
update
(
param
.
getBytes
(
charset
));
return
Base64Utils
.
encodeToString
(
signature
.
sign
());
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
"签名异常"
,
e
);
}
}
public
static
boolean
veriSign
(
String
param
,
String
sign
,
PublicKey
signPartnerPublicKey
)
{
try
{
if
(
signPartnerPublicKey
==
null
)
{
return
false
;
}
Signature
signature
=
Signature
.
getInstance
(
signature_algorithm
);
signature
.
initVerify
(
signPartnerPublicKey
);
signature
.
update
(
param
.
getBytes
(
charset
));
return
signature
.
verify
(
Base64Utils
.
decodeFromString
(
sign
));
}
catch
(
Exception
e
)
{
}
return
false
;
}
}
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