Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
H
haoban-manage3.0
Overview
Overview
Details
Activity
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
haoban3.0
haoban-manage3.0
Commits
4b730ec5
Commit
4b730ec5
authored
Jun 28, 2023
by
jinxin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
随机字符串生成算法
parent
8240465d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
12 deletions
+12
-12
AppOrderApiServiceImpl.java
...vice/service/out/impl/licence/AppOrderApiServiceImpl.java
+2
-2
SignatureGetterUtil.java
...m/gic/haoban/manage/service/util/SignatureGetterUtil.java
+10
-10
No files found.
haoban-manage3-service/src/main/java/com/gic/haoban/manage/service/service/out/impl/licence/AppOrderApiServiceImpl.java
View file @
4b730ec5
...
...
@@ -140,7 +140,7 @@ public class AppOrderApiServiceImpl implements AppOrderApiService {
long
timeStamp
=
System
.
currentTimeMillis
()
/
1000
;
//签名算法
SignatureGetterUtil
signatureGetterUtil
=
new
SignatureGetterUtil
(
secret
);
String
nonceStr
=
signatureGetterUtil
.
gen
Nonce
(
);
String
nonceStr
=
signatureGetterUtil
.
gen
erateRandomString
(
12
);
String
sig
=
null
;
map2
.
put
(
"order_type"
,
qdto
.
getOrderType
());
map2
.
put
(
"case_id"
,
promotionCaseId
);
...
...
@@ -201,7 +201,7 @@ public class AppOrderApiServiceImpl implements AppOrderApiService {
long
timeStamp
=
System
.
currentTimeMillis
()
/
1000
;
//签名算法
SignatureGetterUtil
signatureGetterUtil
=
new
SignatureGetterUtil
(
secret
);
String
nonceStr
=
signatureGetterUtil
.
gen
Nonce
(
);
String
nonceStr
=
signatureGetterUtil
.
gen
erateRandomString
(
12
);
String
sig
=
null
;
JSONObject
json
=
new
JSONObject
();
json
.
put
(
"order_id"
,
appOrder
.
getOrderId
());
...
...
haoban-manage3-service/src/main/java/com/gic/haoban/manage/service/util/SignatureGetterUtil.java
View file @
4b730ec5
...
...
@@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONObject;
import
javax.crypto.Mac
;
import
javax.crypto.spec.SecretKeySpec
;
import
java.nio.charset.StandardCharsets
;
import
java.security.SecureRandom
;
import
java.util.*
;
public
class
SignatureGetterUtil
{
...
...
@@ -61,17 +62,16 @@ public class SignatureGetterUtil {
*
* @return 随机字符串
*/
public
String
genNonce
()
{
return
bytesToHex
(
Long
.
toString
(
System
.
nanoTime
()).
getBytes
(
StandardCharsets
.
UTF_8
));
}
private
String
bytesToHex
(
final
byte
[]
hash
)
{
Formatter
formatter
=
new
Formatter
();
for
(
byte
b
:
hash
)
{
formatter
.
format
(
"%02x"
,
b
);
private
static
final
String
CHARACTERS
=
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
;
public
static
String
generateRandomString
(
int
length
)
{
SecureRandom
random
=
new
SecureRandom
();
StringBuilder
sb
=
new
StringBuilder
(
length
);
for
(
int
i
=
0
;
i
<
length
;
i
++)
{
int
randomIndex
=
random
.
nextInt
(
CHARACTERS
.
length
());
char
randomChar
=
CHARACTERS
.
charAt
(
randomIndex
);
sb
.
append
(
randomChar
);
}
String
result
=
formatter
.
toString
();
formatter
.
close
();
return
result
;
return
sb
.
toString
();
}
}
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