This commit is contained in:
Gordon 2021-10-25 22:15:35 +08:00
parent 55cfec827a
commit fb5bed9cce
3 changed files with 32 additions and 28 deletions

View File

@ -6,11 +6,13 @@ import (
"Open_IM/src/common/log" "Open_IM/src/common/log"
"Open_IM/src/grpc-etcdv3/getcdv3" "Open_IM/src/grpc-etcdv3/getcdv3"
pbRelay "Open_IM/src/proto/relay" pbRelay "Open_IM/src/proto/relay"
pbWs "Open_IM/src/proto/sdk_ws"
"Open_IM/src/utils" "Open_IM/src/utils"
"bytes" "bytes"
"context" "context"
"encoding/gob" "encoding/gob"
"fmt" "fmt"
"github.com/golang/protobuf/proto"
"github.com/gorilla/websocket" "github.com/gorilla/websocket"
"google.golang.org/grpc" "google.golang.org/grpc"
"net" "net"
@ -56,27 +58,29 @@ func (r *RPCServer) MsgToUser(_ context.Context, in *pbRelay.MsgToUserReq) (*pbR
log.InfoByKv("PushMsgToUser is arriving", in.OperationID, "args", in.String()) log.InfoByKv("PushMsgToUser is arriving", in.OperationID, "args", in.String())
var resp []*pbRelay.SingleMsgToUser var resp []*pbRelay.SingleMsgToUser
var RecvID string var RecvID string
msg := make(map[string]interface{}) msg := pbWs.MsgData{
mReply := make(map[string]interface{}) SendID: in.SendID,
mReply["reqIdentifier"] = constant.WSPushMsg RecvID: in.RecvID,
mReply["errCode"] = 0 MsgFrom: in.MsgFrom,
mReply["errMsg"] = "" ContentType: in.ContentType,
msg["sendID"] = in.SendID SessionType: in.SessionType,
msg["recvID"] = in.RecvID SenderNickName: in.SenderNickName,
msg["msgFrom"] = in.MsgFrom SenderFaceURL: in.SenderFaceURL,
msg["contentType"] = in.ContentType ClientMsgID: in.ClientMsgID,
msg["sessionType"] = in.SessionType ServerMsgID: in.ServerMsgID,
msg["senderNickName"] = in.SenderNickName Content: in.Content,
msg["senderFaceUrl"] = in.SenderFaceURL Seq: in.RecvSeq,
msg["clientMsgID"] = in.ClientMsgID SendTime: in.SendTime,
msg["serverMsgID"] = in.ServerMsgID SenderPlatformID: in.PlatformID,
msg["content"] = in.Content }
msg["seq"] = in.RecvSeq msgBytes, _ := proto.Marshal(&msg)
msg["sendTime"] = in.SendTime mReply := Resp{
msg["senderPlatformID"] = in.PlatformID ReqIdentifier: constant.WSPushMsg,
mReply["data"] = msg OperationID: in.OperationID,
var b bytes.Buffer Data: msgBytes,
enc := gob.NewEncoder(&b) }
var replyBytes bytes.Buffer
enc := gob.NewEncoder(&replyBytes)
err := enc.Encode(mReply) err := enc.Encode(mReply)
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
@ -88,12 +92,12 @@ func (r *RPCServer) MsgToUser(_ context.Context, in *pbRelay.MsgToUserReq) (*pbR
RecvID = strings.Split(in.GetRecvID(), " ")[0] RecvID = strings.Split(in.GetRecvID(), " ")[0]
} }
var tag bool var tag bool
a := genUidPlatformArray(RecvID) userIDList := genUidPlatformArray(RecvID)
for _, v := range a { for _, v := range userIDList {
if conn := ws.getUserConn(v); conn != nil { if conn := ws.getUserConn(v); conn != nil {
UIDAndPID := strings.Split(v, " ") UIDAndPID := strings.Split(v, " ")
tag = true tag = true
resultCode := sendMsgToUser(conn, b.Bytes(), in, UIDAndPID[1], UIDAndPID[0]) resultCode := sendMsgToUser(conn, replyBytes.Bytes(), in, UIDAndPID[1], UIDAndPID[0])
temp := &pbRelay.SingleMsgToUser{ temp := &pbRelay.SingleMsgToUser{
ResultCode: resultCode, ResultCode: resultCode,
RecvID: UIDAndPID[0], RecvID: UIDAndPID[0],

View File

@ -15,7 +15,7 @@ import (
type Req struct { type Req struct {
ReqIdentifier int32 `json:"reqIdentifier" validate:"required"` ReqIdentifier int32 `json:"reqIdentifier" validate:"required"`
Token string `json:"token" validate:"required"` Token string `json:"token" `
SendID string `json:"sendID" validate:"required"` SendID string `json:"sendID" validate:"required"`
OperationID string `json:"operationID" validate:"required"` OperationID string `json:"operationID" validate:"required"`
MsgIncr string `json:"msgIncr" validate:"required"` MsgIncr string `json:"msgIncr" validate:"required"`

View File

@ -44,9 +44,9 @@ func (rpc *rpcChat) UserSendMsg(_ context.Context, pb *pbChat.UserSendMsgReq) (*
replay := pbChat.UserSendMsgResp{} replay := pbChat.UserSendMsgResp{}
log.InfoByKv("sendMsg", pb.OperationID, "args", pb.String()) log.InfoByKv("sendMsg", pb.OperationID, "args", pb.String())
time := utils.GetCurrentTimestampByMill() time := utils.GetCurrentTimestampByMill()
if !utils.VerifyToken(pb.Token, pb.SendID) { //if !utils.VerifyToken(pb.Token, pb.SendID) {
return returnMsg(&replay, pb, http.StatusUnauthorized, "token validate err,not authorized", "", 0) // return returnMsg(&replay, pb, http.StatusUnauthorized, "token validate err,not authorized", "", 0)
} //}
log.NewInfo(pb.OperationID, "VerifyToken cost time ", utils.GetCurrentTimestampByMill()-time) log.NewInfo(pb.OperationID, "VerifyToken cost time ", utils.GetCurrentTimestampByMill()-time)
serverMsgID := GetMsgID(pb.SendID) serverMsgID := GetMsgID(pb.SendID)
pbData := pbChat.WSToMsgSvrChatMsg{} pbData := pbChat.WSToMsgSvrChatMsg{}