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
2b28471a
Commit
2b28471a
authored
Oct 24, 2023
by
shiyu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
消息回调解析
parent
fa8ab204
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
3 deletions
+24
-3
ch-wx-api/src/main/java/com/wwdz/ch/wx/api/IMCallbackController.java
...rc/main/java/com/wwdz/ch/wx/api/IMCallbackController.java
+24
-3
No files found.
ch-wx-api/src/main/java/com/wwdz/ch/wx/api/IMCallbackController.java
View file @
2b28471a
package
com.wwdz.ch.wx.api
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
com.wwdz.ch.core.consts.IMEnum
;
import
com.wwdz.ch.db.domain.ImRecord
;
...
...
@@ -12,6 +14,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.web.bind.annotation.*
;
import
java.io.IOException
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.Map
;
...
...
@@ -64,9 +67,9 @@ public class IMCallbackController {
//消息体
String
msgBody
=
JsonUtils
.
getValueByPath
(
jsonStr
,
"MsgBody"
);
List
<
Map
<
String
,
Object
>>
msgBodyList
=
JsonUtils
.
toMapList
(
msgBody
);
String
msgType
=
msgBodyList
.
get
(
0
).
get
(
"MsgType"
).
toString
(
);
String
contentJsonStr
=
msgBodyList
.
get
(
0
).
get
(
"MsgContent"
).
toString
(
);
JSONArray
jsonArray
=
JSON
.
parseArray
(
msgBody
);
String
msgType
=
JsonUtils
.
getValueByPath
(
jsonArray
.
get
(
0
).
toString
(),
"MsgType"
);
String
contentJsonStr
=
JsonUtils
.
getValueByPath
(
jsonArray
.
get
(
0
).
toString
(),
"MsgContent"
);
String
content
=
null
;
if
(
IMEnum
.
MsgTypeEnum
.
TIMTextElem
.
getValue
().
equals
(
msgType
))
{
content
=
JsonUtils
.
getValueByPath
(
contentJsonStr
,
"Text"
);
...
...
@@ -90,4 +93,22 @@ public class IMCallbackController {
return
"success"
;
}
public
static
void
main
(
String
[]
args
)
throws
IOException
{
String
jsonStr
=
" {\"OnlineOnlyFlag\":0,\"SupportMessageExtension\":0,\"SendMsgResult\":0,\"CallbackCommand\":\"C2C.CallbackAfterSendMsg\","
+
"\"ErrorInfo\":\"send msg succeed\",\"To_Account\":\"cjxc-applet-dev_241\",\"MsgBody\":[{\"MsgType\":\"TIMTextElem\","
+
"\"MsgContent\":{\"Text\":\"秦始皇并没有发行货币,而是统一了货币。他颁布了统一的货币,即圆形方孔钱,也称为“秦钱”。这种货币由铜制成,大小不一,但一般都呈圆形,中间有一个孔,方便钱货交流。\"}}],"
+
"\"UnreadMsgNum\":151,\"MsgVersion\":0,\"MsgRandom\":730361011,\"EventTime\":1698131421787,\"MsgSeq\":164841877,\"MsgKey\":\"164841877_730361011_1698131421\","
+
"\"From_Account\":\"cjxc-applet-dev_ai10002\",\"MsgTime\":1698131421}"
;
//消息体
String
msgBody
=
JsonUtils
.
getValueByPath
(
jsonStr
,
"MsgBody"
);
System
.
out
.
println
(
"msgBody = "
+
msgBody
);
JSONArray
jsonArray
=
JSON
.
parseArray
(
msgBody
);
String
msgType
=
JsonUtils
.
getValueByPath
(
jsonArray
.
get
(
0
).
toString
(),
"MsgType"
);
System
.
out
.
println
(
"msgType = "
+
msgType
);
String
contentJsonStr
=
JsonUtils
.
getValueByPath
(
jsonArray
.
get
(
0
).
toString
(),
"MsgContent"
);
System
.
out
.
println
(
"contentJsonStr = "
+
contentJsonStr
);
String
content
=
JsonUtils
.
toMap
(
contentJsonStr
).
get
(
"Text"
).
toString
();
System
.
out
.
println
(
"content = "
+
content
);
}
}
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