From 1040113a4da0cf4b46457a394d2a74baca17a228 Mon Sep 17 00:00:00 2001 From: DengBiao <2319963317@qq.com> Date: Wed, 2 Nov 2022 22:02:20 +0800 Subject: [PATCH] update --- internal/logic/api/logic_ext.go | 11 ++++++++++- internal/logic/api/logic_ext_test.go | 8 +++++--- pkg/pb/logic.ext.pb.go | 15 ++++++++------- test/tcp_conn/main.go | 2 +- 4 files changed, 24 insertions(+), 12 deletions(-) diff --git a/internal/logic/api/logic_ext.go b/internal/logic/api/logic_ext.go index b32ee4b..d8cb897 100644 --- a/internal/logic/api/logic_ext.go +++ b/internal/logic/api/logic_ext.go @@ -5,6 +5,7 @@ import ( "gim/internal/logic/app" "gim/pkg/grpclib" "gim/pkg/pb" + "google.golang.org/protobuf/proto" ) type LogicExtServer struct{} @@ -21,7 +22,15 @@ func (*LogicExtServer) SendMessage(ctx context.Context, in *pb.SendMessageReq) ( if err != nil { return nil, err } - + if in.MessageContentBack != "" { + buf, err := proto.Marshal(&pb.Text{ + Text: "hello world!", + }) + if err != nil { + return nil, err + } + in.MessageContent = buf + } sender := pb.Sender{ SenderType: pb.SenderType_ST_USER, SenderId: userId, diff --git a/internal/logic/api/logic_ext_test.go b/internal/logic/api/logic_ext_test.go index 07b3434..48e7105 100644 --- a/internal/logic/api/logic_ext_test.go +++ b/internal/logic/api/logic_ext_test.go @@ -26,10 +26,10 @@ func getLogicExtClient() pb.LogicExtClient { // deprecated: func getCtx() context.Context { - token := "0" + token := "VRZWQVPFXHPUCCKFOANEYOLCDSFMKEAVYVMAZQWQ" return metadata.NewOutgoingContext(context.TODO(), metadata.Pairs( "user_id", "2", - "device_id", "1", + "device_id", "2", "token", token, "request_id", strconv.FormatInt(time.Now().UnixNano(), 10))) } @@ -52,12 +52,14 @@ func TestLogicExtServer_RegisterDevice(t *testing.T) { func TestLogicExtServer_SendMessage(t *testing.T) { buf, err := proto.Marshal(&pb.Text{ - Text: "hello alber ", + Text: "hello world!", }) if err != nil { fmt.Println(err) return } + var one = string(buf) + fmt.Printf(one) resp, err := getLogicExtClient().SendMessage(getCtx(), &pb.SendMessageReq{ ReceiverType: pb.ReceiverType_RT_USER, diff --git a/pkg/pb/logic.ext.pb.go b/pkg/pb/logic.ext.pb.go index cc62313..19bf780 100644 --- a/pkg/pb/logic.ext.pb.go +++ b/pkg/pb/logic.ext.pb.go @@ -204,13 +204,14 @@ type SendMessageReq struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - ReceiverType ReceiverType `protobuf:"varint,1,opt,name=receiver_type,json=receiverType,proto3,enum=pb.ReceiverType" json:"receiver_type,omitempty"` // 接收者类型,1:user;2:group - ReceiverId int64 `protobuf:"varint,2,opt,name=receiver_id,json=receiverId,proto3" json:"receiver_id,omitempty"` // 用户id或者群组id - ToUserIds []int64 `protobuf:"varint,3,rep,packed,name=to_user_ids,json=toUserIds,proto3" json:"to_user_ids,omitempty"` // 需要@的用户id列表 - MessageType MessageType `protobuf:"varint,4,opt,name=message_type,json=messageType,proto3,enum=pb.MessageType" json:"message_type,omitempty"` // 消息类型 - MessageContent []byte `protobuf:"bytes,5,opt,name=message_content,json=messageContent,proto3" json:"message_content,omitempty"` // 消息内容 - SendTime int64 `protobuf:"varint,6,opt,name=send_time,json=sendTime,proto3" json:"send_time,omitempty"` // 消息发送时间戳,精确到毫秒 - IsPersist bool `protobuf:"varint,7,opt,name=is_persist,json=isPersist,proto3" json:"is_persist,omitempty"` // 是否将消息持久化到数据库 + ReceiverType ReceiverType `protobuf:"varint,1,opt,name=receiver_type,json=receiverType,proto3,enum=pb.ReceiverType" json:"receiver_type,omitempty"` // 接收者类型,1:user;2:group + ReceiverId int64 `protobuf:"varint,2,opt,name=receiver_id,json=receiverId,proto3" json:"receiver_id,omitempty"` // 用户id或者群组id + ToUserIds []int64 `protobuf:"varint,3,rep,packed,name=to_user_ids,json=toUserIds,proto3" json:"to_user_ids,omitempty"` // 需要@的用户id列表 + MessageType MessageType `protobuf:"varint,4,opt,name=message_type,json=messageType,proto3,enum=pb.MessageType" json:"message_type,omitempty"` // 消息类型 + MessageContent []byte `protobuf:"bytes,5,opt,name=message_content,json=messageContent,proto3" json:"message_content,omitempty"` // 消息内容 + SendTime int64 `protobuf:"varint,6,opt,name=send_time,json=sendTime,proto3" json:"send_time,omitempty"` // 消息发送时间戳,精确到毫秒 + IsPersist bool `protobuf:"varint,7,opt,name=is_persist,json=isPersist,proto3" json:"is_persist,omitempty"` // 是否将消息持久化到数据库 + MessageContentBack string `protobuf:"bytes,8,opt,name=message_content_back,json=messageContentBack,proto3" json:"message_content_back,omitempty"` } func (x *SendMessageReq) Reset() { diff --git a/test/tcp_conn/main.go b/test/tcp_conn/main.go index b862e6f..8ef12bc 100644 --- a/test/tcp_conn/main.go +++ b/test/tcp_conn/main.go @@ -87,7 +87,7 @@ func (c *TcpClient) SignIn() { signIn := pb.SignInInput{ UserId: c.UserId, DeviceId: c.DeviceId, - Token: "0", + Token: "ABPIKUKGTCZZGLUSZQAGFXKCSQFEVXEMAYHNNOUZ", } c.Output(pb.PackageType_PT_SIGN_IN, time.Now().UnixNano(), &signIn) }