Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
V
volunteer_service
Project
Project
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
licc
volunteer_service
Commits
9b72bf16
Commit
9b72bf16
authored
Feb 03, 2021
by
licc
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改图片上传
parent
26c9a457
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
0 additions
and
52 deletions
+0
-52
Sign.java
...service/src/main/java/cn/wisenergy/service/util/Sign.java
+0
-52
No files found.
wisenergy-service/src/main/java/cn/wisenergy/service/util/Sign.java
deleted
100644 → 0
View file @
26c9a457
package
cn
.
wisenergy
.
service
.
util
;
import
okhttp3.HttpUrl
;
import
java.io.UnsupportedEncodingException
;
import
java.security.*
;
import
java.util.Base64
;
public
class
Sign
{
String
schema
=
"WECHATPAY2-SHA256-RSA2048"
;
String
url
=
"https://api.mch.weixin.qq.com/v3/certificates"
;
HttpUrl
httpurl
=
HttpUrl
.
parse
(
url
);
String
yourMerchantId
=
""
;
String
yourCertificateSerialNo
=
""
;
String
getToken
(
String
method
,
HttpUrl
url
,
String
body
)
throws
UnsupportedEncodingException
,
SignatureException
,
NoSuchAlgorithmException
,
InvalidKeyException
{
String
nonceStr
=
"your nonce string"
;
long
timestamp
=
System
.
currentTimeMillis
()
/
1000
;
String
message
=
buildMessage
(
method
,
url
,
timestamp
,
nonceStr
,
body
);
String
signature
=
sign
(
message
.
getBytes
(
"utf-8"
));
return
"mchid=\""
+
yourMerchantId
+
"\","
+
"nonce_str=\""
+
nonceStr
+
"\","
+
"timestamp=\""
+
timestamp
+
"\","
+
"serial_no=\""
+
yourCertificateSerialNo
+
"\","
+
"signature=\""
+
signature
+
"\""
;
}
String
sign
(
byte
[]
message
)
throws
NoSuchAlgorithmException
,
SignatureException
,
InvalidKeyException
{
Signature
sign
=
Signature
.
getInstance
(
"SHA256withRSA"
);
PrivateKey
yourPrivateKey
=
null
;
sign
.
initSign
(
yourPrivateKey
);
sign
.
update
(
message
);
return
Base64
.
getEncoder
().
encodeToString
(
sign
.
sign
());
}
String
buildMessage
(
String
method
,
HttpUrl
url
,
long
timestamp
,
String
nonceStr
,
String
body
)
{
String
canonicalUrl
=
url
.
encodedPath
();
if
(
url
.
encodedQuery
()
!=
null
)
{
canonicalUrl
+=
"?"
+
url
.
encodedQuery
();
}
return
method
+
"\n"
+
canonicalUrl
+
"\n"
+
timestamp
+
"\n"
+
nonceStr
+
"\n"
+
body
+
"\n"
;
}
}
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