更新消息发送
This commit is contained in:
parent
e9f71bc927
commit
09ceb33130
22
lib/robot.go
22
lib/robot.go
@ -67,8 +67,6 @@ func (r *Robot) SendMsg(mainType, subType string, req proto.Message, rsp proto.M
|
||||
start := time.Now()
|
||||
defer time.Since(start)
|
||||
|
||||
logrus.WithFields(logrus.Fields{"MainType": mainType, "SubType": subType, "req": req, "rsp": rsp}).Debug("发送消息")
|
||||
|
||||
head := &pb.UserMessage{MainType: mainType, SubType: subType}
|
||||
if mainType == "user" && subType == "login" {
|
||||
loginReq := req.(*pb.UserLoginReq)
|
||||
@ -84,6 +82,7 @@ func (r *Robot) SendMsg(mainType, subType string, req proto.Message, rsp proto.M
|
||||
return pb.ErrorCode_SystemError
|
||||
}
|
||||
|
||||
logrus.WithFields(logrus.Fields{"MainType": mainType, "SubType": subType, "req": req}).Debug("发送消息")
|
||||
for {
|
||||
_, data, err := r.conn.ReadMessage()
|
||||
if err != nil {
|
||||
@ -91,9 +90,23 @@ func (r *Robot) SendMsg(mainType, subType string, req proto.Message, rsp proto.M
|
||||
break
|
||||
}
|
||||
|
||||
if r.checkResp(data, rsp) {
|
||||
msg := &pb.UserMessage{}
|
||||
if err := proto.Unmarshal(data, msg); err != nil {
|
||||
logrus.Error("pb解析失败")
|
||||
break
|
||||
}
|
||||
|
||||
if msg.MainType == mainType && msg.SubType == subType {
|
||||
if !ProtoUnmarshal(msg, rsp) {
|
||||
break
|
||||
}
|
||||
logrus.WithFields(logrus.Fields{"MainType": mainType, "SubType": subType, "rsp": rsp}).Debug("接收消息")
|
||||
return pb.ErrorCode_Success
|
||||
}
|
||||
|
||||
// if r.checkResp(data, rsp) {
|
||||
// return pb.ErrorCode_Success
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
@ -199,8 +212,9 @@ func (m *Robot) checkResp(data []byte, rsp proto.Message) bool {
|
||||
logrus.Error("pb解析失败")
|
||||
return false
|
||||
}
|
||||
logrus.WithField("methodName", methodName).WithField("code", push.Code).Debug("收到推送")
|
||||
logrus.WithField("methodName", methodName).WithField("code", push.Code).Debug("收到错误推送")
|
||||
}
|
||||
return false
|
||||
} else {
|
||||
if !ProtoUnmarshal(msg, rsp) {
|
||||
return false
|
||||
|
Loading…
Reference in New Issue
Block a user