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
76c5cb18
Commit
76c5cb18
authored
Oct 12, 2023
by
shiyu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
公众号
parent
7ac8cf71
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
73 additions
and
3 deletions
+73
-3
ch-wx-api/src/main/java/com/wwdz/ch/wx/api/OfficialAccountApi.java
.../src/main/java/com/wwdz/ch/wx/api/OfficialAccountApi.java
+1
-0
ch-wx-api/src/main/java/com/wwdz/ch/wx/api/OfficialAccountController.java
...in/java/com/wwdz/ch/wx/api/OfficialAccountController.java
+50
-3
ch-wx-api/src/test/java/com/wwdz/ch/wx/api/OfficialAccountApiTest.java
.../test/java/com/wwdz/ch/wx/api/OfficialAccountApiTest.java
+22
-0
No files found.
ch-wx-api/src/main/java/com/wwdz/ch/wx/api/OfficialAccountApi.java
View file @
76c5cb18
...
...
@@ -54,4 +54,5 @@ public class OfficialAccountApi {
redisUtils
.
set
(
APPID
,
token
,
Long
.
valueOf
(
expires_in
)
-
10
,
TimeUnit
.
SECONDS
);
return
token
;
}
}
ch-wx-api/src/main/java/com/wwdz/ch/wx/api/OfficialAccountController.java
View file @
76c5cb18
...
...
@@ -4,10 +4,16 @@ package com.wwdz.ch.wx.api;
import
com.xxdxxs.utils.XmlUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.ByteArrayOutputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.Map
;
...
...
@@ -22,11 +28,25 @@ public class OfficialAccountController {
private
final
static
String
UNSUBSCRIBE_EVENT
=
"unsubscribe"
;
@Autowired
OfficialAccountApi
officialAccountApi
;
@RequestMapping
(
value
=
"/getSubscribeNotice"
)
public
String
getSubscribeNotice
(
@RequestBody
String
xmlInfo
){
logger
.
info
(
"微信通知回调接口原文:{}"
,
xmlInfo
);
@RequestMapping
(
value
=
"/getNotice"
)
public
String
getSubscribeNotice
(
HttpServletRequest
request
,
HttpServletResponse
response
){
ByteArrayOutputStream
output
=
null
;
InputStream
input
=
null
;
try
{
output
=
new
ByteArrayOutputStream
();
input
=
request
.
getInputStream
();
byte
[]
by
=
new
byte
[
1024
];
int
length
=
0
;
while
((
length
=
input
.
read
(
by
))
!=
-
1
){
output
.
write
(
by
,
0
,
length
);
}
String
xmlInfo
=
new
String
(
output
.
toByteArray
(),
"UTF-8"
);
logger
.
info
(
"微信通知回调接口原文:{}"
,
xmlInfo
);
List
<
Map
<
String
,
String
>>
list
=
XmlUtils
.
fromXml
(
xmlInfo
,
"xml"
);
Map
<
String
,
String
>
contentMap
=
list
.
get
(
0
);
...
...
@@ -39,7 +59,34 @@ public class OfficialAccountController {
}
}
catch
(
Exception
e
)
{
logger
.
error
(
"微信通知回调接口 error : {}"
,
e
);
}
finally
{
if
(
output
!=
null
)
{
try
{
output
.
close
();
}
catch
(
IOException
e
)
{
throw
new
RuntimeException
(
e
);
}
}
if
(
input
!=
null
)
{
try
{
input
.
close
();
}
catch
(
IOException
e
)
{
throw
new
RuntimeException
(
e
);
}
}
}
return
""
;
}
@RequestMapping
(
value
=
"/getToken"
)
public
String
getToken
(){
String
token
=
null
;
try
{
token
=
officialAccountApi
.
getAccessToken
();
}
catch
(
Exception
e
)
{
logger
.
error
(
"微信通知回调接口 error : {}"
,
e
);
}
return
token
;
}
}
ch-wx-api/src/test/java/com/wwdz/ch/wx/api/OfficialAccountApiTest.java
0 → 100644
View file @
76c5cb18
package
com.wwdz.ch.wx.api
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
static
org
.
junit
.
Assert
.*;
@SpringBootTest
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
public
class
OfficialAccountApiTest
{
@Autowired
OfficialAccountApi
officialAccountApi
;
@Test
public
void
refreshAccessToken
()
{
officialAccountApi
.
getAccessToken
();
}
}
\ No newline at end of file
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