Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gk
Project
Project
Details
Activity
Releases
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
micro_app
gk
Commits
1adc68f8
Commit
1adc68f8
authored
Oct 17, 2025
by
daniel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(websocket): sessionId一致问题修复
parent
92f20b9f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
2 deletions
+38
-2
WebSocketController.java
...java/com/dlbridge/jadp/websocket/WebSocketController.java
+5
-2
WebSocketTestController.java
.../com/dlbridge/jadp/websocket/WebSocketTestController.java
+33
-0
No files found.
src/main/java/com/dlbridge/jadp/websocket/WebSocketController.java
View file @
1adc68f8
...
...
@@ -4,6 +4,7 @@ import lombok.RequiredArgsConstructor;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.messaging.handler.annotation.MessageMapping
;
import
org.springframework.messaging.handler.annotation.Payload
;
import
org.springframework.messaging.simp.SimpMessageHeaderAccessor
;
import
org.springframework.messaging.simp.annotation.SubscribeMapping
;
import
org.springframework.stereotype.Controller
;
import
java.util.Map
;
...
...
@@ -29,9 +30,11 @@ public class WebSocketController {
* 处理客户端订阅特定票号
*/
@MessageMapping
(
"/ticket/subscribe"
)
public
void
handleTicketSubscribe
(
@Payload
Map
<
String
,
Object
>
message
)
{
String
sessionId
=
(
String
)
message
.
get
(
"sessionId"
);
public
void
handleTicketSubscribe
(
@Payload
Map
<
String
,
Object
>
message
,
SimpMessageHeaderAccessor
headerAccessor
)
{
// String sessionId = (String) message.get("sessionId");
String
sessionId
=
headerAccessor
.
getSessionId
();
String
userId
=
(
String
)
message
.
get
(
"userId"
);
String
ticketNo
=
(
String
)
message
.
get
(
"ticketNo"
);
log
.
info
(
"客户端订阅票号 - 会话ID: {}, 用户ID: {}, 票号: {}"
,
sessionId
,
userId
,
ticketNo
);
...
...
src/main/java/com/dlbridge/jadp/websocket/WebSocketTestController.java
0 → 100644
View file @
1adc68f8
package
com
.
dlbridge
.
jadp
.
websocket
;
import
org.springframework.messaging.handler.annotation.MessageMapping
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.Map
;
@RestController
@RequestMapping
(
"/api/test"
)
public
class
WebSocketTestController
{
private
final
WebSocketSessionService
sessionService
;
public
WebSocketTestController
(
WebSocketSessionService
sessionService
)
{
this
.
sessionService
=
sessionService
;
}
/**
* 测试接口:向指定用户发送票号核销消息
*/
@PostMapping
(
"/sendTicket"
)
public
String
sendTicketMessage
(
@RequestBody
Map
<
String
,
String
>
body
)
{
String
userId
=
body
.
get
(
"userId"
);
String
ticketNo
=
body
.
get
(
"ticketNo"
);
if
(
userId
==
null
||
ticketNo
==
null
)
return
"缺少 userId 或 ticketNo"
;
WebSocketMessage
response
=
WebSocketMessage
.
info
(
ticketNo
,
"这是一个测试消息,票号:"
+
ticketNo
);
sessionService
.
sendToUser
(
userId
,
response
);
return
"消息已发送到用户 "
+
userId
;
}
}
\ 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