1
This commit is contained in:
@@ -4,7 +4,6 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
|
||||
@@ -20,7 +19,7 @@ import (
|
||||
// SendToVendor 向平台发消息
|
||||
func SendToVendor(msg []byte) {
|
||||
var (
|
||||
w http.ResponseWriter
|
||||
//w http.ResponseWriter
|
||||
sendData SendData
|
||||
err error
|
||||
elmAppID = api.EbaiAPI.GetSource()
|
||||
@@ -48,14 +47,16 @@ func SendToVendor(msg []byte) {
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
ClientRender(w, Fail, FailMsg, map[string]string{
|
||||
ClientRender(Fail, FailMsg, map[string]string{
|
||||
"errMsg": fmt.Sprintf("%v", err),
|
||||
})
|
||||
return
|
||||
} else {
|
||||
ClientRender(w, SuccessCode, SuccessMsg, map[string]interface{}{
|
||||
ClientRender(SuccessCode, SuccessMsg, map[string]interface{}{
|
||||
"vendorID": sendData.VendorID,
|
||||
"msg": "ok",
|
||||
})
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -93,6 +94,7 @@ func Send(data []byte) {
|
||||
}
|
||||
fmt.Printf("%s receive: %s\n", conn.RemoteAddr(), string(msg))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// ReadMsgFromClient 存储客户端发送的消息
|
||||
@@ -139,11 +141,13 @@ func ReadMsgFromClient(vendorID int, elmAppID string, msg interface{}) {
|
||||
|
||||
//1 存储详细聊天记录list
|
||||
if err = SetMessageDetail(jxMsg, vendorID, elmAppID); err != nil {
|
||||
return
|
||||
globals.SugarLogger.Debugf("ReadMsgFromClient SetMessageDetail err:=%v\n", err)
|
||||
//return
|
||||
}
|
||||
//2 存储展示列表时单条数据
|
||||
if err = SetUserList(jxMsg, userList, vendorID, elmAppID); err != nil {
|
||||
return
|
||||
globals.SugarLogger.Debugf("ReadMsgFromClient SetUserList err:=%v\n", err)
|
||||
//return
|
||||
}
|
||||
}
|
||||
|
||||
@@ -190,16 +194,19 @@ func ReadMsgFromVendor(vendorID int, elmAppID string, msg []byte) {
|
||||
|
||||
//1 存储详细聊天记录list
|
||||
if err = SetMessageDetail(jxMsg, vendorID, elmAppID); err != nil {
|
||||
return
|
||||
globals.SugarLogger.Debugf("ReadMsgFromVendor SetMessageDetail err:=%v\n", err)
|
||||
//return
|
||||
}
|
||||
//2 存储展示列表时单条数据
|
||||
if err = SetUserList(jxMsg, userList, vendorID, elmAppID); err != nil {
|
||||
return
|
||||
globals.SugarLogger.Debugf("ReadMsgFromVendor SetUserList err:=%v\n", err)
|
||||
//return
|
||||
}
|
||||
//3 cid推送新消息
|
||||
err = PushMsgByCid(vendorStoreID, vendorID)
|
||||
//4 长链接通知给客户端
|
||||
ToClientChan <- clientInfo{Code: SuccessCode, Msg: fmt.Sprintf("%v", err), Data: jxMsg}
|
||||
return
|
||||
}
|
||||
|
||||
// PushMsgByCid 通过cid push用户
|
||||
|
||||
@@ -177,7 +177,7 @@ func Render(conn *websocket.Conn, messageId string, code int, message string, da
|
||||
})
|
||||
}
|
||||
|
||||
func ClientRender(w http.ResponseWriter, code int, msg string, data interface{}) (str string) {
|
||||
func ClientRender(code int, msg string, data interface{}) (str string) {
|
||||
var retData RetData
|
||||
|
||||
retData.Code = code
|
||||
@@ -187,6 +187,7 @@ func ClientRender(w http.ResponseWriter, code int, msg string, data interface{})
|
||||
retJson, _ := json.Marshal(retData)
|
||||
str = string(retJson)
|
||||
|
||||
var w http.ResponseWriter
|
||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
_, _ = io.WriteString(w, str)
|
||||
return
|
||||
|
||||
@@ -16,11 +16,8 @@ func Init() {
|
||||
//初始化
|
||||
ToClientChan = make(chan clientInfo, 1000)
|
||||
//写入全局变量
|
||||
//Default()
|
||||
|
||||
Setup()
|
||||
//建立长链接
|
||||
//StartWebSocket(res, req)
|
||||
go Send([]byte(HeartCheckMsg))
|
||||
|
||||
//启动定时器
|
||||
@@ -51,7 +48,8 @@ func Run(w http.ResponseWriter, r *http.Request) {
|
||||
//设置读取消息大小上线
|
||||
conn.SetReadLimit(maxMessageSize)
|
||||
|
||||
clientID := r.FormValue("clientId")
|
||||
//clientID := r.FormValue("clientId")
|
||||
clientID := r.Header.Get("Clientid")
|
||||
clientSocket := NewClient(clientID, conn)
|
||||
|
||||
//读取客户端消息
|
||||
@@ -164,6 +162,7 @@ func (c *Client) Read() {
|
||||
}
|
||||
} else {
|
||||
SendToVendor(msg)
|
||||
return
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
Reference in New Issue
Block a user