1
This commit is contained in:
@@ -58,7 +58,6 @@ func SendToVendor(msg []byte) {
|
|||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func Send(data []byte) {
|
func Send(data []byte) {
|
||||||
@@ -114,8 +113,8 @@ func ReadMsgFromClient(vendorID int, elmAppID string, msg interface{}) {
|
|||||||
var MtSingleChat = mtwmapi.SingleChat{}
|
var MtSingleChat = mtwmapi.SingleChat{}
|
||||||
err = json.Unmarshal(data, &MtSingleChat)
|
err = json.Unmarshal(data, &MtSingleChat)
|
||||||
jxMsg = &JXMsg{
|
jxMsg = &JXMsg{
|
||||||
SendType: SendTypeJx,
|
SendType: SendTypeJx,
|
||||||
Data: MtSingleChat,
|
MsgContent: MtSingleChat,
|
||||||
}
|
}
|
||||||
userList = &UserMessageList{
|
userList = &UserMessageList{
|
||||||
VendorID: VendorIDMT,
|
VendorID: VendorIDMT,
|
||||||
@@ -128,8 +127,8 @@ func ReadMsgFromClient(vendorID int, elmAppID string, msg interface{}) {
|
|||||||
var ElmData = ebaiapi.ImMessageSend{}
|
var ElmData = ebaiapi.ImMessageSend{}
|
||||||
err = json.Unmarshal(data, &ElmData)
|
err = json.Unmarshal(data, &ElmData)
|
||||||
jxMsg = &JXMsg{
|
jxMsg = &JXMsg{
|
||||||
SendType: SendTypeJx,
|
SendType: SendTypeJx,
|
||||||
Data: ElmData,
|
MsgContent: ElmData,
|
||||||
}
|
}
|
||||||
userList = &UserMessageList{
|
userList = &UserMessageList{
|
||||||
VendorID: VendorIDMT,
|
VendorID: VendorIDMT,
|
||||||
@@ -166,8 +165,8 @@ func ReadMsgFromVendor(vendorID int, elmAppID string, msg []byte) {
|
|||||||
var MtSingleChat = mtwmapi.SingleChat{}
|
var MtSingleChat = mtwmapi.SingleChat{}
|
||||||
err = json.Unmarshal(msg, &MtSingleChat)
|
err = json.Unmarshal(msg, &MtSingleChat)
|
||||||
jxMsg = &JXMsg{
|
jxMsg = &JXMsg{
|
||||||
SendType: SendTypeMt,
|
SendType: SendTypeMt,
|
||||||
Data: MtSingleChat,
|
MsgContent: MtSingleChat,
|
||||||
}
|
}
|
||||||
userList = &UserMessageList{
|
userList = &UserMessageList{
|
||||||
VendorID: VendorIDMT,
|
VendorID: VendorIDMT,
|
||||||
@@ -181,8 +180,8 @@ func ReadMsgFromVendor(vendorID int, elmAppID string, msg []byte) {
|
|||||||
var ElmData = ebaiapi.ImMessageSend{}
|
var ElmData = ebaiapi.ImMessageSend{}
|
||||||
err = json.Unmarshal(msg, &ElmData)
|
err = json.Unmarshal(msg, &ElmData)
|
||||||
jxMsg = &JXMsg{
|
jxMsg = &JXMsg{
|
||||||
SendType: SendTypeElm,
|
SendType: SendTypeElm,
|
||||||
Data: ElmData,
|
MsgContent: ElmData,
|
||||||
}
|
}
|
||||||
userList = &UserMessageList{
|
userList = &UserMessageList{
|
||||||
VendorID: VendorIDMT,
|
VendorID: VendorIDMT,
|
||||||
@@ -285,11 +284,11 @@ func GetNewAndTrim(key string, flag string) (cnt int, err error) {
|
|||||||
// GenMsgDetailID 生成查询详细聊天记录ID
|
// GenMsgDetailID 生成查询详细聊天记录ID
|
||||||
func GenMsgDetailID(jxMsg *JXMsg, vendorID int, elmAppID string) (msgID string) {
|
func GenMsgDetailID(jxMsg *JXMsg, vendorID int, elmAppID string) (msgID string) {
|
||||||
if vendorID == VendorIDMT {
|
if vendorID == VendorIDMT {
|
||||||
var d1 = jxMsg.Data.(mtwmapi.SingleChat)
|
var d1 = jxMsg.MsgContent.(mtwmapi.SingleChat)
|
||||||
msgID = utils.Int2Str(d1.AppID) + ":" + d1.AppPoiCode + ":10:" + utils.Int2Str(d1.OpenUserID)
|
msgID = utils.Int2Str(d1.AppID) + ":" + d1.AppPoiCode + ":10:" + utils.Int2Str(d1.OpenUserID)
|
||||||
}
|
}
|
||||||
if vendorID == VendorIDELM {
|
if vendorID == VendorIDELM {
|
||||||
var d2 = jxMsg.Data.(ebaiapi.ImMessageSend)
|
var d2 = jxMsg.MsgContent.(ebaiapi.ImMessageSend)
|
||||||
msgID = elmAppID + ":" + d2.PlatformShopID + ":11:" + d2.PayLoad.GroupID
|
msgID = elmAppID + ":" + d2.PlatformShopID + ":11:" + d2.PayLoad.GroupID
|
||||||
}
|
}
|
||||||
return msgID
|
return msgID
|
||||||
@@ -298,11 +297,11 @@ func GenMsgDetailID(jxMsg *JXMsg, vendorID int, elmAppID string) (msgID string)
|
|||||||
// GenMsgListID 生成展示列表时单条数据ID(部分)
|
// GenMsgListID 生成展示列表时单条数据ID(部分)
|
||||||
func GenMsgListID(jxMsg *JXMsg, vendorID int, elmAppID string) (msgID string) {
|
func GenMsgListID(jxMsg *JXMsg, vendorID int, elmAppID string) (msgID string) {
|
||||||
if vendorID == VendorIDMT {
|
if vendorID == VendorIDMT {
|
||||||
var d1 = jxMsg.Data.(mtwmapi.SingleChat)
|
var d1 = jxMsg.MsgContent.(mtwmapi.SingleChat)
|
||||||
msgID = utils.Int2Str(d1.AppID) + ":" + d1.AppPoiCode + ":10"
|
msgID = utils.Int2Str(d1.AppID) + ":" + d1.AppPoiCode + ":10"
|
||||||
}
|
}
|
||||||
if vendorID == VendorIDELM {
|
if vendorID == VendorIDELM {
|
||||||
var d2 = jxMsg.Data.(ebaiapi.ImMessageSend)
|
var d2 = jxMsg.MsgContent.(ebaiapi.ImMessageSend)
|
||||||
msgID = elmAppID + ":" + d2.PlatformShopID + ":11"
|
msgID = elmAppID + ":" + d2.PlatformShopID + ":11"
|
||||||
}
|
}
|
||||||
return msgID
|
return msgID
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http/httptest"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -56,8 +56,9 @@ type clientInfo struct {
|
|||||||
|
|
||||||
// RetData 统一返回值结构体
|
// RetData 统一返回值结构体
|
||||||
type RetData struct {
|
type RetData struct {
|
||||||
Code int `json:"code"` //响应code
|
Code int `json:"code"` //响应code
|
||||||
Msg string `json:"msg"` //响应msg success/fail
|
Msg string `json:"msg"` //响应msg success/fail
|
||||||
|
//MsgType string `json:"msgType"` //发送消息方类型:mt;elm;jx
|
||||||
Data interface{} `json:"data"` //信息
|
Data interface{} `json:"data"` //信息
|
||||||
|
|
||||||
//MessageType string `json:"messageType"` //消息类型 heart-心跳检测;send-发送消息;receive-接收消息
|
//MessageType string `json:"messageType"` //消息类型 heart-心跳检测;send-发送消息;receive-接收消息
|
||||||
@@ -90,8 +91,8 @@ type SendData struct {
|
|||||||
|
|
||||||
// JXMsg 京西消息结构体
|
// JXMsg 京西消息结构体
|
||||||
type JXMsg struct {
|
type JXMsg struct {
|
||||||
SendType string `json:"sendType"` //消息发送方 jx-商家;mt-美团;elm-饿了么
|
SendType string `json:"sendType"` //消息发送方 jx-商家;mt-美团;elm-饿了么
|
||||||
Data interface{} `json:"data"` //美团/饿了么 单聊消息
|
MsgContent interface{} `json:"msgContent"` //美团/饿了么 单聊消息
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetUserListReq 获取门店用户聊天列表
|
// GetUserListReq 获取门店用户聊天列表
|
||||||
@@ -170,11 +171,21 @@ const (
|
|||||||
|
|
||||||
// Render 统一返回值
|
// Render 统一返回值
|
||||||
func Render(conn *websocket.Conn, messageId string, code int, message string, data interface{}) error {
|
func Render(conn *websocket.Conn, messageId string, code int, message string, data interface{}) error {
|
||||||
return conn.WriteJSON(RetData{
|
if data != nil {
|
||||||
Code: code,
|
str, _ := json.Marshal(data)
|
||||||
Msg: message,
|
temp := string(str)
|
||||||
Data: data,
|
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) {
|
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)
|
retJson, _ := json.Marshal(retData)
|
||||||
str = string(retJson)
|
str = string(retJson)
|
||||||
|
|
||||||
var w http.ResponseWriter
|
w := httptest.NewRecorder()
|
||||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||||
_, _ = io.WriteString(w, str)
|
_, _ = io.WriteString(w, str)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -118,6 +118,7 @@ func WriteMessage() {
|
|||||||
fmt.Printf("WriteMessage clientInfo=%s i=%d", utils.Format4Output(clientInfo, false), i)
|
fmt.Printf("WriteMessage clientInfo=%s i=%d", utils.Format4Output(clientInfo, false), i)
|
||||||
if Manager.AllClient() != nil {
|
if Manager.AllClient() != nil {
|
||||||
for _, conn := range Manager.AllClient() {
|
for _, conn := range Manager.AllClient() {
|
||||||
|
globals.SugarLogger.Debugf("WriteMessage conn.ClientId=%s", conn.ClientId)
|
||||||
if err := Render(conn.Socket, clientInfo.MessageId, clientInfo.Code, clientInfo.Msg, clientInfo.Data); err != nil {
|
if err := Render(conn.Socket, clientInfo.MessageId, clientInfo.Code, clientInfo.Msg, clientInfo.Data); err != nil {
|
||||||
Manager.DisConnect <- conn
|
Manager.DisConnect <- conn
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user