xuzhiheng 4 ani în urmă
părinte
comite
af8eac653c

+ 2 - 1
README.md

@@ -1 +1,2 @@
-消息中台
+消息中台
+goctl rpc proto -src message.proto -dir .

+ 15 - 7
entity/message.go

@@ -1,19 +1,27 @@
 package entity
 
 import (
-	"github.com/go-xorm/xorm"
 	"time"
+
+	"github.com/go-xorm/xorm"
 )
 
 //定义orm引擎
 var Engine *xorm.Engine
 
 type Message struct {
-	Id            int       `xorm:"id" form:"id" json:"id"`                                     // 发送方用户id
+	Id            int       `xorm:"id" form:"id" json:"id"`
+	AppId         string    `xorm:"appid" form:"appid" json:"appid"`
 	ReceiveUserid string    `xorm:"receive_userid" form:"receive_userid" json:"receive_userid"` // 接收方用户id
-	SendUserid    string    `xorm:"send_userid" form:"send_userid" json:"send_userid"`          // 消息id
-	CreateTime    time.Time `xorm:"createtime" form:"createtime" json:"createtime"`             // 创建时间
-	Content       string    `xorm:"content" form:"content" json:"content"`                      // '内容
-	IsRead        int       `xorm:"isRead" form:"isRead" json:"isRead"`                         //  '0:未读  1:已读'
-	Isdel         int       `xorm:"isdel" form:"isdel" json:"isdel"`                            // 1:未删除  -1:已删除
+	ReceiveName   string    `xorm:"receive_name" form:"receive_name" json:"receive_name"`
+	SendUserid    string    `xorm:"send_userid" form:"send_userid" json:"send_userid"` // 消息id
+	SendName      string    `xorm:"send_name" form:"send_name" json:"send_name"`
+	CreateTime    time.Time `xorm:"createtime" form:"createtime" json:"createtime"` // 创建时间
+	Title         string    `xorm:"title" form:"title" json:"title"`
+	MsgType       int       `xorm:"msg_type" form:"msg_type" json:"msg_type"`
+	Link          string    `xorm:"link" form:"link" json:"link"`
+	CiteId        string    `xorm:"cite_id" form:"cite_id" json:"cite_id"`
+	Content       string    `xorm:"content" form:"content" json:"content"` // '内容
+	IsRead        int       `xorm:"isRead" form:"isRead" json:"isRead"`    //  '0:未读  1:已读'
+	Isdel         int       `xorm:"isdel" form:"isdel" json:"isdel"`       // 1:未删除  -1:已删除
 }

+ 0 - 30
rpc/internal/logic/pinglogic.go

@@ -1,30 +0,0 @@
-package logic
-
-import (
-	"context"
-
-	"app.yhyue.com/moapp/MessageCenter/rpc/internal/svc"
-	"app.yhyue.com/moapp/MessageCenter/rpc/message"
-
-	"github.com/tal-tech/go-zero/core/logx"
-)
-
-type PingLogic struct {
-	ctx    context.Context
-	svcCtx *svc.ServiceContext
-	logx.Logger
-}
-
-func NewPingLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PingLogic {
-	return &PingLogic{
-		ctx:    ctx,
-		svcCtx: svcCtx,
-		Logger: logx.WithContext(ctx),
-	}
-}
-
-func (l *PingLogic) Ping(in *message.Request) (*message.Response, error) {
-	// todo: add your logic here and delete this line
-
-	return &message.Response{}, nil
-}

+ 34 - 0
rpc/internal/logic/sendusermsglogic.go

@@ -0,0 +1,34 @@
+package logic
+
+import (
+	"context"
+
+	"app.yhyue.com/moapp/MessageCenter/rpc/internal/svc"
+	"app.yhyue.com/moapp/MessageCenter/rpc/message"
+	"app.yhyue.com/moapp/MessageCenter/service"
+	"github.com/tal-tech/go-zero/core/logx"
+)
+
+type SendUserMsgLogic struct {
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+	logx.Logger
+}
+
+func NewSendUserMsgLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SendUserMsgLogic {
+	return &SendUserMsgLogic{
+		ctx:    ctx,
+		svcCtx: svcCtx,
+		Logger: logx.WithContext(ctx),
+	}
+}
+
+// 指定用户发消息
+func (l *SendUserMsgLogic) SendUserMsg(in *message.SendMsgRequest) (*message.Response, error) {
+	// todo: add your logic here and delete this line
+	code, msg := service.SendMsg(*in)
+	return &message.Response{
+		Code:    code,
+		Message: msg,
+	}, nil
+}

+ 7 - 5
rpc/internal/server/messageserver.go

@@ -21,12 +21,14 @@ func NewMessageServer(svcCtx *svc.ServiceContext) *MessageServer {
 	}
 }
 
-func (s *MessageServer) Ping(ctx context.Context, in *message.Request) (*message.Response, error) {
-	l := logic.NewPingLogic(ctx, s.svcCtx)
-	return l.Ping(in)
-}
-
+// 修改消息阅读状态
 func (s *MessageServer) ChangeReadStatus(ctx context.Context, in *message.ChangeReadStatusRequest) (*message.Response, error) {
 	l := logic.NewChangeReadStatusLogic(ctx, s.svcCtx)
 	return l.ChangeReadStatus(in)
 }
+
+// 指定用户发消息
+func (s *MessageServer) SendUserMsg(ctx context.Context, in *message.SendMsgRequest) (*message.Response, error) {
+	l := logic.NewSendUserMsgLogic(ctx, s.svcCtx)
+	return l.SendUserMsg(in)
+}

+ 21 - 9
rpc/message.proto

@@ -2,20 +2,32 @@ syntax = "proto3";
 
 package message;
 
-message Request {
-  string ping = 1;
+message SendMsgRequest {
+  	string receiveUserId = 1; //接收方用户ID
+	string receiveName = 2; //接收方用户名
+	string sendUserId = 3; //发送方用户ID
+	string sendName = 4; //发送方用户名
+	string title = 5; //主题
+	string content = 6; //内容
+	int64 msgType = 7; //消息类型 1:客服   2:系统通知  3:营销   4:用户会话
+	string link = 8; //跳转链接
+	string citeId = 9; //引用id
+	string appid = 10; //应用标识
 }
-// 修改消息阅读状态
+
 message  ChangeReadStatusRequest {
-  int64 id = 1; // 消息id
-  int64 readStatus = 2;// 阅读状态 0-未读 1-已读
+  	int64 id = 1; // 消息id
+  	int64 readStatus = 2;// 阅读状态 0-未读 1-已读
+	string appid = 3; //应用标识
 }
 
 message Response {
-  int64 code = 1;//状态码
-  string message=2;//响应消息
+  	int64 code = 1;//状态码
+  	string message=2;//响应消息
 }
 service Message {
-  rpc Ping(Request) returns(Response);
-  rpc ChangeReadStatus(ChangeReadStatusRequest) returns(Response);
+	//修改消息阅读状态
+  	rpc ChangeReadStatus(ChangeReadStatusRequest) returns(Response);
+	//指定用户发消息
+	rpc SendUserMsg(SendMsgRequest) returns(Response);
 }

+ 166 - 65
rpc/message/message.pb.go

@@ -1,7 +1,7 @@
 // Code generated by protoc-gen-go. DO NOT EDIT.
 // versions:
-// 	protoc-gen-go v1.25.0
-// 	protoc        v3.15.1
+// 	protoc-gen-go v1.23.0
+// 	protoc        v3.11.4
 // source: message.proto
 
 package message
@@ -29,16 +29,25 @@ const (
 // of the legacy proto package is being used.
 const _ = proto.ProtoPackageIsVersion4
 
-type Request struct {
+type SendMsgRequest struct {
 	state         protoimpl.MessageState
 	sizeCache     protoimpl.SizeCache
 	unknownFields protoimpl.UnknownFields
 
-	Ping string `protobuf:"bytes,1,opt,name=ping,proto3" json:"ping,omitempty"`
+	ReceiveUserId string `protobuf:"bytes,1,opt,name=receiveUserId,proto3" json:"receiveUserId,omitempty"` //接收方用户ID
+	ReceiveName   string `protobuf:"bytes,2,opt,name=receiveName,proto3" json:"receiveName,omitempty"`     //接收方用户名
+	SendUserId    string `protobuf:"bytes,3,opt,name=sendUserId,proto3" json:"sendUserId,omitempty"`       //发送方用户ID
+	SendName      string `protobuf:"bytes,4,opt,name=sendName,proto3" json:"sendName,omitempty"`           //发送方用户名
+	Title         string `protobuf:"bytes,5,opt,name=title,proto3" json:"title,omitempty"`                 //主题
+	Content       string `protobuf:"bytes,6,opt,name=content,proto3" json:"content,omitempty"`             //内容
+	MsgType       int64  `protobuf:"varint,7,opt,name=msgType,proto3" json:"msgType,omitempty"`            //消息类型 1:客服   2:系统通知  3:营销   4:用户会话
+	Link          string `protobuf:"bytes,8,opt,name=link,proto3" json:"link,omitempty"`                   //跳转链接
+	CiteId        string `protobuf:"bytes,9,opt,name=citeId,proto3" json:"citeId,omitempty"`               //引用id
+	Appid         string `protobuf:"bytes,10,opt,name=appid,proto3" json:"appid,omitempty"`                //应用标识
 }
 
-func (x *Request) Reset() {
-	*x = Request{}
+func (x *SendMsgRequest) Reset() {
+	*x = SendMsgRequest{}
 	if protoimpl.UnsafeEnabled {
 		mi := &file_message_proto_msgTypes[0]
 		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
@@ -46,13 +55,13 @@ func (x *Request) Reset() {
 	}
 }
 
-func (x *Request) String() string {
+func (x *SendMsgRequest) String() string {
 	return protoimpl.X.MessageStringOf(x)
 }
 
-func (*Request) ProtoMessage() {}
+func (*SendMsgRequest) ProtoMessage() {}
 
-func (x *Request) ProtoReflect() protoreflect.Message {
+func (x *SendMsgRequest) ProtoReflect() protoreflect.Message {
 	mi := &file_message_proto_msgTypes[0]
 	if protoimpl.UnsafeEnabled && x != nil {
 		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
@@ -64,26 +73,89 @@ func (x *Request) ProtoReflect() protoreflect.Message {
 	return mi.MessageOf(x)
 }
 
-// Deprecated: Use Request.ProtoReflect.Descriptor instead.
-func (*Request) Descriptor() ([]byte, []int) {
+// Deprecated: Use SendMsgRequest.ProtoReflect.Descriptor instead.
+func (*SendMsgRequest) Descriptor() ([]byte, []int) {
 	return file_message_proto_rawDescGZIP(), []int{0}
 }
 
-func (x *Request) GetPing() string {
+func (x *SendMsgRequest) GetReceiveUserId() string {
 	if x != nil {
-		return x.Ping
+		return x.ReceiveUserId
+	}
+	return ""
+}
+
+func (x *SendMsgRequest) GetReceiveName() string {
+	if x != nil {
+		return x.ReceiveName
+	}
+	return ""
+}
+
+func (x *SendMsgRequest) GetSendUserId() string {
+	if x != nil {
+		return x.SendUserId
+	}
+	return ""
+}
+
+func (x *SendMsgRequest) GetSendName() string {
+	if x != nil {
+		return x.SendName
+	}
+	return ""
+}
+
+func (x *SendMsgRequest) GetTitle() string {
+	if x != nil {
+		return x.Title
+	}
+	return ""
+}
+
+func (x *SendMsgRequest) GetContent() string {
+	if x != nil {
+		return x.Content
+	}
+	return ""
+}
+
+func (x *SendMsgRequest) GetMsgType() int64 {
+	if x != nil {
+		return x.MsgType
+	}
+	return 0
+}
+
+func (x *SendMsgRequest) GetLink() string {
+	if x != nil {
+		return x.Link
+	}
+	return ""
+}
+
+func (x *SendMsgRequest) GetCiteId() string {
+	if x != nil {
+		return x.CiteId
+	}
+	return ""
+}
+
+func (x *SendMsgRequest) GetAppid() string {
+	if x != nil {
+		return x.Appid
 	}
 	return ""
 }
 
-// 修改消息阅读状态
 type ChangeReadStatusRequest struct {
 	state         protoimpl.MessageState
 	sizeCache     protoimpl.SizeCache
 	unknownFields protoimpl.UnknownFields
 
-	Id         int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"`                 // 消息id
-	ReadStatus int64 `protobuf:"varint,2,opt,name=readStatus,proto3" json:"readStatus,omitempty"` // 阅读状态 0-未读 1-已读
+	Id         int64  `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"`                 // 消息id
+	ReadStatus int64  `protobuf:"varint,2,opt,name=readStatus,proto3" json:"readStatus,omitempty"` // 阅读状态 0-未读 1-已读
+	Appid      string `protobuf:"bytes,3,opt,name=appid,proto3" json:"appid,omitempty"`            //应用标识
 }
 
 func (x *ChangeReadStatusRequest) Reset() {
@@ -132,6 +204,13 @@ func (x *ChangeReadStatusRequest) GetReadStatus() int64 {
 	return 0
 }
 
+func (x *ChangeReadStatusRequest) GetAppid() string {
+	if x != nil {
+		return x.Appid
+	}
+	return ""
+}
+
 type Response struct {
 	state         protoimpl.MessageState
 	sizeCache     protoimpl.SizeCache
@@ -191,26 +270,44 @@ var File_message_proto protoreflect.FileDescriptor
 
 var file_message_proto_rawDesc = []byte{
 	0x0a, 0x0d, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12,
-	0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0x1d, 0x0a, 0x07, 0x52, 0x65, 0x71, 0x75,
-	0x65, 0x73, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x70, 0x69, 0x6e, 0x67, 0x18, 0x01, 0x20, 0x01, 0x28,
-	0x09, 0x52, 0x04, 0x70, 0x69, 0x6e, 0x67, 0x22, 0x49, 0x0a, 0x17, 0x43, 0x68, 0x61, 0x6e, 0x67,
-	0x65, 0x52, 0x65, 0x61, 0x64, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65,
-	0x73, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x02,
-	0x69, 0x64, 0x12, 0x1e, 0x0a, 0x0a, 0x72, 0x65, 0x61, 0x64, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73,
-	0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0a, 0x72, 0x65, 0x61, 0x64, 0x53, 0x74, 0x61, 0x74,
-	0x75, 0x73, 0x22, 0x38, 0x0a, 0x08, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x12,
-	0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, 0x63, 0x6f,
-	0x64, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x02, 0x20,
-	0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x32, 0x7f, 0x0a, 0x07,
-	0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x2b, 0x0a, 0x04, 0x50, 0x69, 0x6e, 0x67, 0x12,
-	0x10, 0x2e, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x2e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73,
-	0x74, 0x1a, 0x11, 0x2e, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x2e, 0x52, 0x65, 0x73, 0x70,
-	0x6f, 0x6e, 0x73, 0x65, 0x12, 0x47, 0x0a, 0x10, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x52, 0x65,
-	0x61, 0x64, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x20, 0x2e, 0x6d, 0x65, 0x73, 0x73, 0x61,
-	0x67, 0x65, 0x2e, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x52, 0x65, 0x61, 0x64, 0x53, 0x74, 0x61,
-	0x74, 0x75, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x11, 0x2e, 0x6d, 0x65, 0x73,
-	0x73, 0x61, 0x67, 0x65, 0x2e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x62, 0x06, 0x70,
-	0x72, 0x6f, 0x74, 0x6f, 0x33,
+	0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0xa0, 0x02, 0x0a, 0x0e, 0x53, 0x65, 0x6e,
+	0x64, 0x4d, 0x73, 0x67, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x24, 0x0a, 0x0d, 0x72,
+	0x65, 0x63, 0x65, 0x69, 0x76, 0x65, 0x55, 0x73, 0x65, 0x72, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01,
+	0x28, 0x09, 0x52, 0x0d, 0x72, 0x65, 0x63, 0x65, 0x69, 0x76, 0x65, 0x55, 0x73, 0x65, 0x72, 0x49,
+	0x64, 0x12, 0x20, 0x0a, 0x0b, 0x72, 0x65, 0x63, 0x65, 0x69, 0x76, 0x65, 0x4e, 0x61, 0x6d, 0x65,
+	0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x72, 0x65, 0x63, 0x65, 0x69, 0x76, 0x65, 0x4e,
+	0x61, 0x6d, 0x65, 0x12, 0x1e, 0x0a, 0x0a, 0x73, 0x65, 0x6e, 0x64, 0x55, 0x73, 0x65, 0x72, 0x49,
+	0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x73, 0x65, 0x6e, 0x64, 0x55, 0x73, 0x65,
+	0x72, 0x49, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x73, 0x65, 0x6e, 0x64, 0x4e, 0x61, 0x6d, 0x65, 0x18,
+	0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x73, 0x65, 0x6e, 0x64, 0x4e, 0x61, 0x6d, 0x65, 0x12,
+	0x14, 0x0a, 0x05, 0x74, 0x69, 0x74, 0x6c, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05,
+	0x74, 0x69, 0x74, 0x6c, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74,
+	0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x12,
+	0x18, 0x0a, 0x07, 0x6d, 0x73, 0x67, 0x54, 0x79, 0x70, 0x65, 0x18, 0x07, 0x20, 0x01, 0x28, 0x03,
+	0x52, 0x07, 0x6d, 0x73, 0x67, 0x54, 0x79, 0x70, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x6c, 0x69, 0x6e,
+	0x6b, 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6c, 0x69, 0x6e, 0x6b, 0x12, 0x16, 0x0a,
+	0x06, 0x63, 0x69, 0x74, 0x65, 0x49, 0x64, 0x18, 0x09, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x63,
+	0x69, 0x74, 0x65, 0x49, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x61, 0x70, 0x70, 0x69, 0x64, 0x18, 0x0a,
+	0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x61, 0x70, 0x70, 0x69, 0x64, 0x22, 0x5f, 0x0a, 0x17, 0x43,
+	0x68, 0x61, 0x6e, 0x67, 0x65, 0x52, 0x65, 0x61, 0x64, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52,
+	0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01,
+	0x28, 0x03, 0x52, 0x02, 0x69, 0x64, 0x12, 0x1e, 0x0a, 0x0a, 0x72, 0x65, 0x61, 0x64, 0x53, 0x74,
+	0x61, 0x74, 0x75, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0a, 0x72, 0x65, 0x61, 0x64,
+	0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x14, 0x0a, 0x05, 0x61, 0x70, 0x70, 0x69, 0x64, 0x18,
+	0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x61, 0x70, 0x70, 0x69, 0x64, 0x22, 0x38, 0x0a, 0x08,
+	0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65,
+	0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x12, 0x18, 0x0a, 0x07,
+	0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d,
+	0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x32, 0x8d, 0x01, 0x0a, 0x07, 0x4d, 0x65, 0x73, 0x73, 0x61,
+	0x67, 0x65, 0x12, 0x47, 0x0a, 0x10, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x52, 0x65, 0x61, 0x64,
+	0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x20, 0x2e, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65,
+	0x2e, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x52, 0x65, 0x61, 0x64, 0x53, 0x74, 0x61, 0x74, 0x75,
+	0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x11, 0x2e, 0x6d, 0x65, 0x73, 0x73, 0x61,
+	0x67, 0x65, 0x2e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x39, 0x0a, 0x0b, 0x53,
+	0x65, 0x6e, 0x64, 0x55, 0x73, 0x65, 0x72, 0x4d, 0x73, 0x67, 0x12, 0x17, 0x2e, 0x6d, 0x65, 0x73,
+	0x73, 0x61, 0x67, 0x65, 0x2e, 0x53, 0x65, 0x6e, 0x64, 0x4d, 0x73, 0x67, 0x52, 0x65, 0x71, 0x75,
+	0x65, 0x73, 0x74, 0x1a, 0x11, 0x2e, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x2e, 0x52, 0x65,
+	0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
 }
 
 var (
@@ -227,15 +324,15 @@ func file_message_proto_rawDescGZIP() []byte {
 
 var file_message_proto_msgTypes = make([]protoimpl.MessageInfo, 3)
 var file_message_proto_goTypes = []interface{}{
-	(*Request)(nil),                 // 0: message.Request
+	(*SendMsgRequest)(nil),          // 0: message.SendMsgRequest
 	(*ChangeReadStatusRequest)(nil), // 1: message.ChangeReadStatusRequest
 	(*Response)(nil),                // 2: message.Response
 }
 var file_message_proto_depIdxs = []int32{
-	0, // 0: message.Message.Ping:input_type -> message.Request
-	1, // 1: message.Message.ChangeReadStatus:input_type -> message.ChangeReadStatusRequest
-	2, // 2: message.Message.Ping:output_type -> message.Response
-	2, // 3: message.Message.ChangeReadStatus:output_type -> message.Response
+	1, // 0: message.Message.ChangeReadStatus:input_type -> message.ChangeReadStatusRequest
+	0, // 1: message.Message.SendUserMsg:input_type -> message.SendMsgRequest
+	2, // 2: message.Message.ChangeReadStatus:output_type -> message.Response
+	2, // 3: message.Message.SendUserMsg:output_type -> message.Response
 	2, // [2:4] is the sub-list for method output_type
 	0, // [0:2] is the sub-list for method input_type
 	0, // [0:0] is the sub-list for extension type_name
@@ -250,7 +347,7 @@ func file_message_proto_init() {
 	}
 	if !protoimpl.UnsafeEnabled {
 		file_message_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
-			switch v := v.(*Request); i {
+			switch v := v.(*SendMsgRequest); i {
 			case 0:
 				return &v.state
 			case 1:
@@ -318,8 +415,10 @@ const _ = grpc.SupportPackageIsVersion6
 //
 // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream.
 type MessageClient interface {
-	Ping(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Response, error)
+	//修改消息阅读状态
 	ChangeReadStatus(ctx context.Context, in *ChangeReadStatusRequest, opts ...grpc.CallOption) (*Response, error)
+	//指定用户发消息
+	SendUserMsg(ctx context.Context, in *SendMsgRequest, opts ...grpc.CallOption) (*Response, error)
 }
 
 type messageClient struct {
@@ -330,18 +429,18 @@ func NewMessageClient(cc grpc.ClientConnInterface) MessageClient {
 	return &messageClient{cc}
 }
 
-func (c *messageClient) Ping(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Response, error) {
+func (c *messageClient) ChangeReadStatus(ctx context.Context, in *ChangeReadStatusRequest, opts ...grpc.CallOption) (*Response, error) {
 	out := new(Response)
-	err := c.cc.Invoke(ctx, "/message.Message/Ping", in, out, opts...)
+	err := c.cc.Invoke(ctx, "/message.Message/ChangeReadStatus", in, out, opts...)
 	if err != nil {
 		return nil, err
 	}
 	return out, nil
 }
 
-func (c *messageClient) ChangeReadStatus(ctx context.Context, in *ChangeReadStatusRequest, opts ...grpc.CallOption) (*Response, error) {
+func (c *messageClient) SendUserMsg(ctx context.Context, in *SendMsgRequest, opts ...grpc.CallOption) (*Response, error) {
 	out := new(Response)
-	err := c.cc.Invoke(ctx, "/message.Message/ChangeReadStatus", in, out, opts...)
+	err := c.cc.Invoke(ctx, "/message.Message/SendUserMsg", in, out, opts...)
 	if err != nil {
 		return nil, err
 	}
@@ -350,57 +449,59 @@ func (c *messageClient) ChangeReadStatus(ctx context.Context, in *ChangeReadStat
 
 // MessageServer is the server API for Message service.
 type MessageServer interface {
-	Ping(context.Context, *Request) (*Response, error)
+	//修改消息阅读状态
 	ChangeReadStatus(context.Context, *ChangeReadStatusRequest) (*Response, error)
+	//指定用户发消息
+	SendUserMsg(context.Context, *SendMsgRequest) (*Response, error)
 }
 
 // UnimplementedMessageServer can be embedded to have forward compatible implementations.
 type UnimplementedMessageServer struct {
 }
 
-func (*UnimplementedMessageServer) Ping(context.Context, *Request) (*Response, error) {
-	return nil, status.Errorf(codes.Unimplemented, "method Ping not implemented")
-}
 func (*UnimplementedMessageServer) ChangeReadStatus(context.Context, *ChangeReadStatusRequest) (*Response, error) {
 	return nil, status.Errorf(codes.Unimplemented, "method ChangeReadStatus not implemented")
 }
+func (*UnimplementedMessageServer) SendUserMsg(context.Context, *SendMsgRequest) (*Response, error) {
+	return nil, status.Errorf(codes.Unimplemented, "method SendUserMsg not implemented")
+}
 
 func RegisterMessageServer(s *grpc.Server, srv MessageServer) {
 	s.RegisterService(&_Message_serviceDesc, srv)
 }
 
-func _Message_Ping_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
-	in := new(Request)
+func _Message_ChangeReadStatus_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
+	in := new(ChangeReadStatusRequest)
 	if err := dec(in); err != nil {
 		return nil, err
 	}
 	if interceptor == nil {
-		return srv.(MessageServer).Ping(ctx, in)
+		return srv.(MessageServer).ChangeReadStatus(ctx, in)
 	}
 	info := &grpc.UnaryServerInfo{
 		Server:     srv,
-		FullMethod: "/message.Message/Ping",
+		FullMethod: "/message.Message/ChangeReadStatus",
 	}
 	handler := func(ctx context.Context, req interface{}) (interface{}, error) {
-		return srv.(MessageServer).Ping(ctx, req.(*Request))
+		return srv.(MessageServer).ChangeReadStatus(ctx, req.(*ChangeReadStatusRequest))
 	}
 	return interceptor(ctx, in, info, handler)
 }
 
-func _Message_ChangeReadStatus_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
-	in := new(ChangeReadStatusRequest)
+func _Message_SendUserMsg_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
+	in := new(SendMsgRequest)
 	if err := dec(in); err != nil {
 		return nil, err
 	}
 	if interceptor == nil {
-		return srv.(MessageServer).ChangeReadStatus(ctx, in)
+		return srv.(MessageServer).SendUserMsg(ctx, in)
 	}
 	info := &grpc.UnaryServerInfo{
 		Server:     srv,
-		FullMethod: "/message.Message/ChangeReadStatus",
+		FullMethod: "/message.Message/SendUserMsg",
 	}
 	handler := func(ctx context.Context, req interface{}) (interface{}, error) {
-		return srv.(MessageServer).ChangeReadStatus(ctx, req.(*ChangeReadStatusRequest))
+		return srv.(MessageServer).SendUserMsg(ctx, req.(*SendMsgRequest))
 	}
 	return interceptor(ctx, in, info, handler)
 }
@@ -409,14 +510,14 @@ var _Message_serviceDesc = grpc.ServiceDesc{
 	ServiceName: "message.Message",
 	HandlerType: (*MessageServer)(nil),
 	Methods: []grpc.MethodDesc{
-		{
-			MethodName: "Ping",
-			Handler:    _Message_Ping_Handler,
-		},
 		{
 			MethodName: "ChangeReadStatus",
 			Handler:    _Message_ChangeReadStatus_Handler,
 		},
+		{
+			MethodName: "SendUserMsg",
+			Handler:    _Message_SendUserMsg_Handler,
+		},
 	},
 	Streams:  []grpc.StreamDesc{},
 	Metadata: "message.proto",

+ 11 - 7
rpc/messageclient/message.go

@@ -14,13 +14,15 @@ import (
 )
 
 type (
-	Response                = message.Response
-	Request                 = message.Request
+	SendMsgRequest          = message.SendMsgRequest
 	ChangeReadStatusRequest = message.ChangeReadStatusRequest
+	Response                = message.Response
 
 	Message interface {
-		Ping(ctx context.Context, in *Request) (*Response, error)
+		// 修改消息阅读状态
 		ChangeReadStatus(ctx context.Context, in *ChangeReadStatusRequest) (*Response, error)
+		// 指定用户发消息
+		SendUserMsg(ctx context.Context, in *SendMsgRequest) (*Response, error)
 	}
 
 	defaultMessage struct {
@@ -34,12 +36,14 @@ func NewMessage(cli zrpc.Client) Message {
 	}
 }
 
-func (m *defaultMessage) Ping(ctx context.Context, in *Request) (*Response, error) {
+// 修改消息阅读状态
+func (m *defaultMessage) ChangeReadStatus(ctx context.Context, in *ChangeReadStatusRequest) (*Response, error) {
 	client := message.NewMessageClient(m.cli.Conn())
-	return client.Ping(ctx, in)
+	return client.ChangeReadStatus(ctx, in)
 }
 
-func (m *defaultMessage) ChangeReadStatus(ctx context.Context, in *ChangeReadStatusRequest) (*Response, error) {
+// 指定用户发消息
+func (m *defaultMessage) SendUserMsg(ctx context.Context, in *SendMsgRequest) (*Response, error) {
 	client := message.NewMessageClient(m.cli.Conn())
-	return client.ChangeReadStatus(ctx, in)
+	return client.SendUserMsg(ctx, in)
 }

+ 40 - 0
service/sendMsg.go

@@ -0,0 +1,40 @@
+package service
+
+import (
+	"fmt"
+	"log"
+	"time"
+
+	"app.yhyue.com/moapp/MessageCenter/entity"
+	"app.yhyue.com/moapp/MessageCenter/rpc/message"
+)
+
+func SendMsg(this message.SendMsgRequest) (int64, string) {
+	orm := entity.Engine.NewSession()
+	defer orm.Close()
+	err := orm.Begin()
+	fmt.Println(err)
+	message := entity.Message{
+		AppId:         this.Appid,
+		ReceiveUserid: this.ReceiveUserId,
+		ReceiveName:   this.ReceiveName,
+		SendUserid:    this.SendUserId,
+		SendName:      this.SendName,
+		CreateTime:    time.Now(),
+		Title:         this.Title,
+		MsgType:       int(this.MsgType),
+		Link:          this.Link,
+		CiteId:        this.CiteId,
+		Content:       this.Content,
+		IsRead:        0,
+		Isdel:         1,
+	}
+	_, err = orm.Table("message").Insert(&message)
+	if err != nil {
+		log.Panicln("消息发送失败:", err)
+		orm.Rollback()
+		return -1, "消息发送失败"
+	}
+	orm.Commit()
+	return 1, "消息发送成功"
+}