Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Q
qk_backend
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
quanku
qk_backend
Commits
bf0c628f
Commit
bf0c628f
authored
Oct 13, 2023
by
shiyu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
公众号
parent
7da05a0f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
3 deletions
+40
-3
ch-wx-api/src/main/java/com/wwdz/ch/wx/api/OfficialAccountController.java
...in/java/com/wwdz/ch/wx/api/OfficialAccountController.java
+27
-3
ch-wx-api/src/main/java/com/wwdz/ch/wx/api/aes/WXBizMsgCrypt.java
...i/src/main/java/com/wwdz/ch/wx/api/aes/WXBizMsgCrypt.java
+13
-0
No files found.
ch-wx-api/src/main/java/com/wwdz/ch/wx/api/OfficialAccountController.java
View file @
bf0c628f
...
...
@@ -2,11 +2,13 @@ package com.wwdz.ch.wx.api;
import
com.alibaba.fastjson.JSONObject
;
import
com.wwdz.ch.wx.api.aes.AesException
;
import
com.wwdz.ch.wx.api.aes.WXBizMsgCrypt
;
import
com.wwdz.ch.wx.util.StringUtil
;
import
com.xxdxxs.utils.JsonUtils
;
import
com.xxdxxs.utils.StringUtils
;
import
com.xxdxxs.utils.XmlUtils
;
import
org.dom4j.DocumentException
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -62,7 +64,6 @@ public class OfficialAccountController {
InputStream
input
=
null
;
try
{
logger
.
info
(
"接收公众号推送信息校验 -> appid: {}, signature:{}, timestamp:{}, nonce:{}, echostr : {}"
,
APPID
,
signature
,
timestamp
,
nonce
,
echostr
);
WXBizMsgCrypt
wxBizMsgCrypt
=
new
WXBizMsgCrypt
(
OFFICIALACCOUNTTOKEN
,
OFFICIALACCOUNTKEY
,
APPID
);
output
=
new
ByteArrayOutputStream
();
input
=
request
.
getInputStream
();
byte
[]
by
=
new
byte
[
1024
];
...
...
@@ -72,8 +73,8 @@ public class OfficialAccountController {
}
String
xmlInfo
=
new
String
(
output
.
toByteArray
(),
"UTF-8"
);
logger
.
info
(
"微信通知回调接口原文:{}"
,
xmlInfo
);
String
xmlStr
=
wxBizMsgCrypt
.
decryptMsg
(
signature
,
timestamp
,
nonce
,
xmlInfo
);
logger
.
info
(
"解密后获取公众号推送的信息内容 : {}"
,
xmlStr
);
WXBizMsgCrypt
wxBizMsgCrypt
=
new
WXBizMsgCrypt
(
OFFICIALACCOUNTTOKEN
,
OFFICIALACCOUNTKEY
,
APPID
);
String
xmlStr
=
wxBizMsgCrypt
.
decryptXmlMsg
(
signature
,
timestamp
,
nonce
,
xmlInfo
);
List
<
Map
<
String
,
String
>>
list
=
XmlUtils
.
fromXml
(
xmlStr
,
"xml"
);
Map
<
String
,
String
>
contentMap
=
list
.
get
(
0
);
String
event
=
contentMap
.
get
(
"Event"
);
...
...
@@ -105,6 +106,29 @@ public class OfficialAccountController {
}
public
static
void
main
(
String
[]
args
)
throws
AesException
,
DocumentException
{
String
xml
=
"<xml><ToUserName><![CDATA[gh_075dfbc935ef]]></ToUserName>\n"
+
"<FromUserName><![CDATA[oNPTN6QaVliZfKB53OzZRPBZr_r8]]></FromUserName>\n"
+
"<CreateTime>1697165124</CreateTime>\n"
+
"<MsgType><![CDATA[event]]></MsgType>\n"
+
"<Event><![CDATA[subscribe]]></Event>\n"
+
"<EventKey><![CDATA[]]></EventKey>\n"
+
"</xml>"
;
WXBizMsgCrypt
wxBizMsgCrypt
=
new
WXBizMsgCrypt
(
"Uu6GHYOiP1xJ6GaBMyXfnITufAGJTe3Q"
,
"noeN1amYRvzrVmE2GnC5VnsIfgPEmv6bhX54wJOARlM"
,
"wx7db8eb146a194083"
);
List
<
Map
<
String
,
String
>>
list
=
XmlUtils
.
fromXml
(
xml
,
"xml"
);
Map
<
String
,
String
>
contentMap
=
list
.
get
(
0
);
System
.
out
.
println
(
contentMap
.
get
(
"Event"
)
+
">>"
+
contentMap
.
get
(
"FromUserName"
)
+
">>"
+
contentMap
.
get
(
"CreateTime"
));
String
event
=
wxBizMsgCrypt
.
decrypt
(
contentMap
.
get
(
"Event"
));
if
(
SUBSCRIBE_EVENT
.
equals
(
event
)
||
UNSUBSCRIBE_EVENT
.
equals
(
event
))
{
String
userOpenId
=
wxBizMsgCrypt
.
decrypt
(
contentMap
.
get
(
"FromUserName"
));
String
createTime
=
wxBizMsgCrypt
.
decrypt
(
contentMap
.
get
(
"CreateTime"
));
Date
date
=
new
Date
(
createTime
);
System
.
out
.
println
(
userOpenId
+
">>"
+
event
+
">>"
+
date
);
}
}
@RequestMapping
(
value
=
"/getSubscribeNotice"
,
consumes
=
"text/xml"
)
public
Object
getSubscribeNotice
(
@RequestParam
(
required
=
false
,
name
=
"signature"
)
String
signature
,
@RequestParam
(
required
=
false
,
name
=
"timestamp"
)
String
timestamp
,
...
...
ch-wx-api/src/main/java/com/wwdz/ch/wx/api/aes/WXBizMsgCrypt.java
View file @
bf0c628f
...
...
@@ -15,13 +15,17 @@ package com.wwdz.ch.wx.api.aes;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
com.xxdxxs.utils.XmlUtils
;
import
org.apache.commons.codec.binary.Base64
;
import
org.dom4j.DocumentException
;
import
javax.crypto.Cipher
;
import
javax.crypto.spec.IvParameterSpec
;
import
javax.crypto.spec.SecretKeySpec
;
import
java.nio.charset.Charset
;
import
java.util.Arrays
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Random
;
/**
...
...
@@ -267,6 +271,15 @@ public class WXBizMsgCrypt {
}
public
String
decryptXmlMsg
(
String
msgSignature
,
String
timeStamp
,
String
nonce
,
String
postData
)
throws
AesException
,
DocumentException
{
Object
[]
encrypt
=
XMLParse
.
extract
(
postData
);
String
result
=
decrypt
(
encrypt
[
1
].
toString
());
return
result
;
}
public
String
decryptJsonMsg
(
String
msgSignature
,
String
timeStamp
,
String
nonce
,
String
postData
)
throws
AesException
{
JSONObject
jsonObject
=
JSON
.
parseObject
(
postData
);
...
...
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