Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions api/send2group/send2group.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,22 @@ package send2group

import (
"encoding/json"
"net/http"

"github.com/woodylan/go-websocket/api"
"github.com/woodylan/go-websocket/define/retcode"
"github.com/woodylan/go-websocket/servers"
"net/http"
)

type Controller struct {
}

type inputData struct {
SendUserId string `json:"sendUserId"`
GroupName string `json:"groupName" validate:"required"`
Code int `json:"code"`
Msg string `json:"msg"`
Data string `json:"data"`
SendUserId string `json:"sendUserId"`
GroupName string `json:"groupName" validate:"required"`
Code int `json:"code"`
Msg string `json:"msg"`
Data json.RawMessage `json:"data"`
}

func (c *Controller) Run(w http.ResponseWriter, r *http.Request) {
Expand All @@ -31,9 +32,9 @@ func (c *Controller) Run(w http.ResponseWriter, r *http.Request) {
api.Render(w, retcode.FAIL, err.Error(), []string{})
return
}

dataStr := string(inputData.Data)
systemId := r.Header.Get("SystemId")
messageId := servers.SendMessage2Group(systemId, inputData.SendUserId, inputData.GroupName, inputData.Code, inputData.Msg, &inputData.Data)
messageId := servers.SendMessage2Group(systemId, inputData.SendUserId, inputData.GroupName, inputData.Code, inputData.Msg, &dataStr)

api.Render(w, retcode.SUCCESS, "success", map[string]string{
"messageId": messageId,
Expand Down
9 changes: 6 additions & 3 deletions servers/server.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package servers

import (
"encoding/json"
"net/http"
"time"

"github.com/gorilla/websocket"
log "github.com/sirupsen/logrus"
"github.com/woodylan/go-websocket/pkg/setting"
"github.com/woodylan/go-websocket/tools/util"
"net/http"
"time"
)

//channel通道
Expand Down Expand Up @@ -209,8 +211,9 @@ func WriteMessage() {
"msg": clientInfo.Msg,
"data": clientInfo.Data,
}).Info("发送到本机")
jsonRawData := json.RawMessage([]byte(*clientInfo.Data))
if conn, err := Manager.GetByClientId(clientInfo.ClientId); err == nil && conn != nil {
if err := Render(conn.Socket, clientInfo.MessageId, clientInfo.SendUserId, clientInfo.Code, clientInfo.Msg, clientInfo.Data); err != nil {
if err := Render(conn.Socket, clientInfo.MessageId, clientInfo.SendUserId, clientInfo.Code, clientInfo.Msg, jsonRawData); err != nil {
Manager.DisConnect <- conn
log.WithFields(log.Fields{
"host": setting.GlobalSetting.LocalHost,
Expand Down