This commit is contained in:
richboo111
2023-04-27 14:00:52 +08:00
parent a2e183b5b9
commit 01f4f9cb19
3 changed files with 35 additions and 24 deletions

View File

@@ -7,7 +7,7 @@ import (
"io"
"log"
"net"
"net/http"
"net/http/httptest"
"sync"
"time"
@@ -56,8 +56,9 @@ type clientInfo struct {
// RetData 统一返回值结构体
type RetData struct {
Code int `json:"code"` //响应code
Msg string `json:"msg"` //响应msg success/fail
Code int `json:"code"` //响应code
Msg string `json:"msg"` //响应msg success/fail
//MsgType string `json:"msgType"` //发送消息方类型mt;elm;jx
Data interface{} `json:"data"` //信息
//MessageType string `json:"messageType"` //消息类型 heart-心跳检测send-发送消息receive-接收消息
@@ -90,8 +91,8 @@ type SendData struct {
// JXMsg 京西消息结构体
type JXMsg struct {
SendType string `json:"sendType"` //消息发送方 jx-商家mt-美团elm-饿了么
Data interface{} `json:"data"` //美团/饿了么 单聊消息
SendType string `json:"sendType"` //消息发送方 jx-商家mt-美团elm-饿了么
MsgContent interface{} `json:"msgContent"` //美团/饿了么 单聊消息
}
// GetUserListReq 获取门店用户聊天列表
@@ -170,11 +171,21 @@ const (
// Render 统一返回值
func Render(conn *websocket.Conn, messageId string, code int, message string, data interface{}) error {
return conn.WriteJSON(RetData{
Code: code,
Msg: message,
Data: data,
})
if data != nil {
str, _ := json.Marshal(data)
temp := string(str)
return conn.WriteJSON(RetData{
Code: code,
Msg: message,
//MsgType: temp.SendType,
Data: temp,
})
} else {
return conn.WriteJSON(RetData{
Code: code,
Msg: message,
})
}
}
func ClientRender(code int, msg string, data interface{}) (str string) {
@@ -187,7 +198,7 @@ func ClientRender(code int, msg string, data interface{}) (str string) {
retJson, _ := json.Marshal(retData)
str = string(retJson)
var w http.ResponseWriter
w := httptest.NewRecorder()
w.Header().Set("Content-Type", "application/json; charset=utf-8")
_, _ = io.WriteString(w, str)
return