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
c2e39e1b
Commit
c2e39e1b
authored
Oct 23, 2023
by
BlackJokerCJ
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/master'
parents
984f2f90
6a2bdb01
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
228 additions
and
25 deletions
+228
-25
CreditResultListener.java
...java/com/jqtx/windows/common/mq/CreditResultListener.java
+12
-10
LoanResultListener.java
...n/java/com/jqtx/windows/common/mq/LoanResultListener.java
+1
-1
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
+36
-11
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/common/mq/CreditResultListener.java
View file @
c2e39e1b
...
...
@@ -20,7 +20,7 @@ import org.springframework.beans.factory.annotation.Autowired;
* @Date 2021/2/27
*/
@Slf4j
@MQConsumerComponent
(
tags
=
"cr
iusCreditResul
t"
,
topic
=
"$mq.creditTopic"
)
@MQConsumerComponent
(
tags
=
"cr
edi
t"
,
topic
=
"$mq.creditTopic"
)
public
class
CreditResultListener
extends
AbstractMQConsumerHandler
<
CreditResultModel
>
{
@Autowired
...
...
@@ -28,9 +28,6 @@ public class CreditResultListener extends AbstractMQConsumerHandler<CreditResult
@Autowired
private
AbcHttpClient
abcHttpClient
;
@Autowired
private
GetCreditCommand
getCreditCommand
;
@Override
public
Class
getClazz
()
{
return
CreditResultModel
.
class
;
...
...
@@ -38,24 +35,29 @@ public class CreditResultListener extends AbstractMQConsumerHandler<CreditResult
@Override
public
void
run
(
CreditResultModel
creditResultModel
)
throws
Exception
{
CreditModel
byOrderNo
=
creditComponent
.
getByOrderNo
(
creditResultModel
.
getOrderNo
());
if
(
ObjectUtil
.
isNull
(
byOrderNo
)
||
!
CreditResultStatusEnum
.
INIT
.
name
().
equals
(
byOrderNo
.
getCreditResult
())){
CreditModel
creditModel
=
creditComponent
.
getByOrderNo
(
creditResultModel
.
getOrderNo
());
if
(
ObjectUtil
.
isNull
(
creditModel
)
||
!
CreditResultStatusEnum
.
INIT
.
name
().
equals
(
creditModel
.
getCreditResult
())){
return
;
}
CreditModel
update
=
new
CreditModel
();
CreditDetailResponse
creditDetailResponse
=
new
CreditDetailResponse
();
if
(
"YES"
.
equalsIgnoreCase
(
creditResultModel
.
getCreditStatus
()))
{
update
.
setCreditResult
(
CreditResultStatusEnum
.
PASS
.
getCode
());
//通过
creditDetailResponse
.
setStatus
(
"1"
);
creditDetailResponse
.
setApprovalAmount
(
creditResultModel
.
getCreditAmt
().
toEngineeringString
());
}
if
(
"RETRIAL"
.
equalsIgnoreCase
(
creditResultModel
.
getCreditStatus
()))
{
update
.
setCreditResult
(
CreditResultStatusEnum
.
INIT
.
getCode
());
}
if
(
"REJECT"
.
equalsIgnoreCase
(
creditResultModel
.
getCreditStatus
()))
{
update
.
setCreditResult
(
CreditResultStatusEnum
.
REFUSED
.
getCode
());
creditDetailResponse
.
setStatus
(
"2"
);
}
creditComponent
.
updateByOrderNo
(
byOrderNo
.
getOrderNo
(),
update
);
CreditDetailResponse
convert
=
getCreditCommand
.
convert
(
byOrderNo
.
getOrderN
o
());
c
onvert
.
setTransNo
(
IdUtil
.
fastSimpleUUID
());
abcHttpClient
.
postRequest
(
JSON
.
toJSONString
(
c
onvert
),
ZNPostUrlEnum
.
CREDIT_CALL
.
getCode
());
creditComponent
.
updateByOrderNo
(
creditModel
.
getOrderNo
(),
update
);
creditDetailResponse
.
setRemark
(
creditResultModel
.
getMem
o
());
c
reditDetailResponse
.
setTransNo
(
IdUtil
.
fastSimpleUUID
());
abcHttpClient
.
postRequest
(
JSON
.
toJSONString
(
c
reditDetailResponse
),
ZNPostUrlEnum
.
CREDIT_CALL
.
getCode
());
}
}
src/main/java/com/jqtx/windows/common/mq/LoanResultListener.java
View file @
c2e39e1b
...
...
@@ -20,7 +20,7 @@ import java.time.LocalDateTime;
* 提现审核结果
*/
@Slf4j
@MQConsumerComponent
(
tags
=
"withdraw"
,
topic
=
"$mq.
loan
Topic"
)
@MQConsumerComponent
(
tags
=
"withdraw"
,
topic
=
"$mq.
credit
Topic"
)
public
class
LoanResultListener
extends
AbstractMQConsumerHandler
<
CreditResultModel
>
{
@Autowired
...
...
src/main/java/com/jqtx/windows/component/enums/ZNPostUrlEnum.java
View file @
c2e39e1b
...
...
@@ -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 @
c2e39e1b
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 @
c2e39e1b
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 @
c2e39e1b
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,28 +28,48 @@ 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
);
log
.
info
(
"请求浙农request:{}, url:{}"
,
JSON
.
toJSONString
(
request
),
url
);
HttpResponse
response
=
HttpRequest
.
post
(
url
).
body
(
JSON
.
toJSONString
(
request
)).
setConnectionTimeout
(
5000
).
execute
();
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
(
zyHttpBaseRquest
));
log
.
info
(
"请求浙农url:{}"
,
url
);
HttpResponse
response
=
HttpRequest
.
post
(
url
).
body
(
JSON
.
toJSONString
(
zyHttpBaseRquest
)).
setConnectionTimeout
(
5000
).
execute
();
log
.
info
(
"请求浙农加密返回数据:{}"
,
JSON
.
toJSONString
(
response
.
body
()));
if
(
response
.
getStatus
()
==
200
&&
StringUtils
.
isNotBlank
(
response
.
body
()))
{
final
String
body
=
response
.
body
();
log
.
info
(
"请求浙农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
);
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
(
"请求异常"
);
}
}
catch
(
Exception
e
)
{
log
.
error
(
"请求浙农异常:{}"
,
e
.
getMessage
(),
e
);
log
.
error
(
"请求浙农异常:{}"
,
e
.
getMessage
(),
e
);
return
null
;
}
return
null
;
}
}
src/main/java/com/jqtx/windows/utils/EncryptUtil.java
0 → 100644
View file @
c2e39e1b
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 @
c2e39e1b
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