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
7da05a0f
Commit
7da05a0f
authored
Oct 13, 2023
by
shiyu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
公众号
parent
ca818d19
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
7 deletions
+20
-7
ch-wx-api/pom.xml
ch-wx-api/pom.xml
+5
-0
ch-wx-api/src/main/java/com/wwdz/ch/wx/api/OfficialAccountController.java
...in/java/com/wwdz/ch/wx/api/OfficialAccountController.java
+15
-7
No files found.
ch-wx-api/pom.xml
View file @
7da05a0f
...
...
@@ -82,6 +82,11 @@
<version>
1.18.24
</version>
</dependency>
<dependency>
<groupId>
com.fasterxml.jackson.dataformat
</groupId>
<artifactId>
jackson-dataformat-xml
</artifactId>
<version>
2.9.6
</version>
</dependency>
</dependencies>
<build>
...
...
ch-wx-api/src/main/java/com/wwdz/ch/wx/api/OfficialAccountController.java
View file @
7da05a0f
...
...
@@ -50,11 +50,19 @@ public class OfficialAccountController {
@RequestMapping
(
value
=
"/getNotice"
)
public
String
getNotice
(
HttpServletRequest
request
,
HttpServletResponse
response
){
logger
.
info
(
"1111111111111111"
);
public
Object
getNotice
(
@RequestParam
(
required
=
false
,
name
=
"signature"
)
String
signature
,
@RequestParam
(
required
=
false
,
name
=
"timestamp"
)
String
timestamp
,
@RequestParam
(
required
=
false
,
name
=
"nonce"
)
String
nonce
,
@RequestParam
(
required
=
false
,
name
=
"echostr"
)
String
echostr
,
HttpServletRequest
request
,
HttpServletResponse
response
){
if
(
StringUtils
.
hasLength
(
echostr
))
{
return
Long
.
valueOf
(
echostr
.
trim
());
}
ByteArrayOutputStream
output
=
null
;
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
];
...
...
@@ -64,10 +72,10 @@ public class OfficialAccountController {
}
String
xmlInfo
=
new
String
(
output
.
toByteArray
(),
"UTF-8"
);
logger
.
info
(
"微信通知回调接口原文:{}"
,
xmlInfo
);
List
<
Map
<
String
,
String
>>
list
=
XmlUtils
.
fromXml
(
xmlInfo
,
"xml"
);
String
xmlStr
=
wxBizMsgCrypt
.
decryptMsg
(
signature
,
timestamp
,
nonce
,
xmlInfo
);
logger
.
info
(
"解密后获取公众号推送的信息内容 : {}"
,
xmlStr
);
List
<
Map
<
String
,
String
>>
list
=
XmlUtils
.
fromXml
(
xmlStr
,
"xml"
);
Map
<
String
,
String
>
contentMap
=
list
.
get
(
0
);
String
event
=
contentMap
.
get
(
"Event"
);
if
(
SUBSCRIBE_EVENT
.
equals
(
event
)
||
UNSUBSCRIBE_EVENT
.
equals
(
event
))
{
String
userOpenId
=
contentMap
.
get
(
"FromUserName"
);
...
...
@@ -76,7 +84,7 @@ public class OfficialAccountController {
logger
.
info
(
"openId:{}, event :{}, time:{}"
,
userOpenId
,
event
,
date
);
}
}
catch
(
Exception
e
)
{
logger
.
error
(
"微信通知回调接口 error : {}"
,
e
);
logger
.
error
(
"微信
公众号
通知回调接口 error : {}"
,
e
);
}
finally
{
if
(
output
!=
null
)
{
try
{
...
...
@@ -97,7 +105,7 @@ public class OfficialAccountController {
}
@RequestMapping
(
value
=
"/getSubscribeNotice"
)
@RequestMapping
(
value
=
"/getSubscribeNotice"
,
consumes
=
"text/xml"
)
public
Object
getSubscribeNotice
(
@RequestParam
(
required
=
false
,
name
=
"signature"
)
String
signature
,
@RequestParam
(
required
=
false
,
name
=
"timestamp"
)
String
timestamp
,
@RequestParam
(
required
=
false
,
name
=
"nonce"
)
String
nonce
,
...
...
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