From 982be3fe9cfe98e24b67629d447f51913c7a86b4 Mon Sep 17 00:00:00 2001 From: zyj <18107291228@163.com> Date: Tue, 23 Sep 2025 16:57:31 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=B6=88=E6=81=AF=E6=8E=A8?= =?UTF-8?q?=E9=80=81=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/websocks.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/api/websocks.go b/api/websocks.go index 9ec0cb6..e5b8381 100644 --- a/api/websocks.go +++ b/api/websocks.go @@ -20,7 +20,7 @@ import ( type Websocks struct { } -var DeviceList map[int64]models.Device +var DeviceList = make(map[int64]models.Device) type Message struct { Type string `form:"type" json:"type" uri:"type" xml:"type"` @@ -76,6 +76,7 @@ func (w *Websocks) Init(ctx *gin.Context) { deviceService := services.InitDeviceService() deviceLoginInfo := deviceService.Login(tokenStr) DeviceList[deviceLoginInfo.ID] = deviceLoginInfo + // 将保存连接状态 ClientsMu.Lock() Clients[TokenStatus.UserId] = map[int64]*websocket.Conn{deviceLoginInfo.ID: conn} @@ -106,6 +107,9 @@ func (*Websocks) MessageHandle(conn *websocket.Conn, deviceLoginInfo models.Devi if data.Recipient != 0 { RecipientDevice = DeviceList[data.Recipient] } + log.Println("推送用户", RecipientDevice.UserId) + log.Println("推送设备", RecipientDevice.ID) + switch data.Type { case "message": if data.Recipient != 0 {