diff --git a/go.mod b/go.mod index 2c3fef0..f103c20 100644 --- a/go.mod +++ b/go.mod @@ -22,6 +22,7 @@ require ( ) require ( + code.fnuoos.com/go_rely_warehouse/zyos_go_jg_push.git v1.0.2 // indirect github.com/PuerkitoBio/purell v1.1.1 // indirect github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect github.com/davecgh/go-spew v1.1.1 // indirect diff --git a/go.sum b/go.sum index 9cd3db8..003b782 100644 --- a/go.sum +++ b/go.sum @@ -1,4 +1,6 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +code.fnuoos.com/go_rely_warehouse/zyos_go_jg_push.git v1.0.2 h1:LUWlvBgmzZfGqvH4VGEWk+JhXHlI+MFmLNl9uX7eh28= +code.fnuoos.com/go_rely_warehouse/zyos_go_jg_push.git v1.0.2/go.mod h1:IEw6A61Kp2ctoeKIQMFVM/cFq9PUDAzJMb5lVXiEY2Y= github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/PuerkitoBio/goquery v1.5.1/go.mod h1:GsLWisAFVj4WgDibEWF4pvYnkVQBpKBKeU+7zCJoLcc= @@ -165,6 +167,10 @@ github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5 github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/syyongx/php2go v0.9.7/go.mod h1:meN2eIhhUoxOd2nMxbpe8g6cFPXI5O9/UAAuz7oDdzw= +github.com/tidwall/gjson v1.14.1/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= +github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM= +github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU= github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw= github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs= github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY= diff --git a/internal/business/comm/db/db_user_push_for_jg.go b/internal/business/comm/db/db_user_push_for_jg.go new file mode 100644 index 0000000..2f38ab6 --- /dev/null +++ b/internal/business/comm/db/db_user_push_for_jg.go @@ -0,0 +1,81 @@ +package db + +import ( + "fmt" + "gim/internal/business/comm/db/model" + "gim/internal/business/comm/md" + "gim/internal/business/comm/utils" + "gim/internal/business/comm/utils/logx" + "gim/pkg/db" + "gim/pkg/gerrors" +) + +type dbUserPushForJg struct{} + +var DbUserPushForJg = new(dbUserPushForJg) + +// UserPushForJgGetOne 获取一条记录 +func (*dbUserPushForJg) UserPushForJgGetOne(key string, masterId int64) (*model.UserPushForJg, error) { + var cfgList model.UserPushForJg + if err := db.DB.Where("`key` = ? and `master_id` = ?", key, masterId).First(&cfgList).Error; err != nil { + return nil, gerrors.WrapError(err) + } + return &cfgList, nil +} + +// UserPushForJgInsert 插入一条配置信息 +func (*dbUserPushForJg) UserPushForJgInsert(uid, masterId int64, pushAlia string) bool { + cfg := model.UserPushForJg{Uid: uid, PushAlia: pushAlia, MasterId: masterId} + err := db.DB.Create(&cfg).Error + if err != nil { + logx.Error(err) + return false + } + return true +} + +// UserPushForJgUpdate 修改某条配置信息 +func (*dbUserPushForJg) UserPushForJgUpdate(uid, masterId int64, pushAlia string) bool { + cfg := model.UserPushForJg{Uid: uid, PushAlia: pushAlia, MasterId: masterId} + err := db.DB.Where("`uid` = ? and `master_id` = ?", uid, masterId).Update(&cfg).Error + if err != nil { + logx.Error(err) + return false + } + return true +} + +// UserPushForJgGetWithDb 单条记录获取 +func (*dbUserPushForJg) UserPushForJgGetWithDb(masterId string, HKey string) string { + cacheKey := fmt.Sprintf(md.AppCfgCacheKey, masterId, HKey[0:1]) + get, err := db.RedisUtil.HGetString(cacheKey, HKey) + if err != nil || get == "" { + cfg, err := DbUserPushForJg.UserPushForJgGetOne(HKey, utils.StrToInt64(masterId)) + if err != nil || cfg == nil { + _ = logx.Error(err) + return "" + } + + // key是否存在 + cacheKeyExist := false + if db.RedisUtil.Exists(cacheKey) { + cacheKeyExist = true + } + + // 设置缓存 + _, err = db.RedisUtil.HSet(cacheKey, HKey, cfg.PushAlia) + if err != nil { + _ = logx.Error(err) + return "" + } + if !cacheKeyExist { // 如果是首次设置 设置过期时间 + _, err := db.RedisUtil.Expire(cacheKey, md.CfgCacheTime) + if err != nil { + _ = logx.Error(err) + return "" + } + } + return cfg.PushAlia + } + return get +} diff --git a/internal/business/comm/db/model/user_push_for_jg.go b/internal/business/comm/db/model/user_push_for_jg.go new file mode 100644 index 0000000..9a5292b --- /dev/null +++ b/internal/business/comm/db/model/user_push_for_jg.go @@ -0,0 +1,8 @@ +package model + +type UserPushForJg struct { + Id int64 + Uid int64 // 用户id + PushAlia string // 用户头像 + MasterId int64 // 站长id +} diff --git a/internal/business/comm/md/app_redis_key.go b/internal/business/comm/md/app_redis_key.go index 0df0da1..9e4cd58 100644 --- a/internal/business/comm/md/app_redis_key.go +++ b/internal/business/comm/md/app_redis_key.go @@ -2,6 +2,7 @@ package md // 缓存key统一管理, %s格式化为masterId const ( - AppCfgCacheKey = "%s:gim_cfg_cache:%s" // 占位符: masterId, key的第一个字母 - CfgCacheTime = 86400 + AppCfgCacheKey = "%s:gim_cfg_cache:%s" // 占位符: masterId, key的第一个字母 + AppUserPushForJgCacheKey = "%s:gim_user_push_for_jg_cache:%s" // 占位符: masterId, key的第一个字母 + CfgCacheTime = 86400 ) diff --git a/internal/logic/api/logic_ext.go b/internal/logic/api/logic_ext.go index 7905627..84b727a 100644 --- a/internal/logic/api/logic_ext.go +++ b/internal/logic/api/logic_ext.go @@ -84,6 +84,19 @@ func (s *LogicExtServer) AgreeAddFriend(ctx context.Context, in *pb.AgreeAddFrie return &pb.Empty{}, nil } +func (s *LogicExtServer) DeleteFriend(ctx context.Context, in *pb.DeleteFriendReq) (*pb.Empty, error) { + userId, _, err := grpclib.GetCtxData(ctx) + if err != nil { + return nil, err + } + err = app.FriendApp.DeleteFriend(ctx, userId, in.UserId) + if err != nil { + return nil, err + } + + return &pb.Empty{}, nil +} + func (s *LogicExtServer) SetFriend(ctx context.Context, req *pb.SetFriendReq) (*pb.SetFriendResp, error) { userId, _, err := grpclib.GetCtxData(ctx) if err != nil { diff --git a/internal/logic/app/friend_app.go b/internal/logic/app/friend_app.go index a016d13..dacfe52 100644 --- a/internal/logic/app/friend_app.go +++ b/internal/logic/app/friend_app.go @@ -21,6 +21,11 @@ func (*friendApp) AddFriend(ctx context.Context, userId, friendId int64, remarks return frienddomain.FriendService.AddFriend(ctx, userId, friendId, remarks, description) } +// DeleteFriend 添加好友 +func (*friendApp) DeleteFriend(ctx context.Context, userId, friendId int64) error { + return frienddomain.FriendService.DeleteFriend(ctx, userId, friendId) +} + // AgreeAddFriend 同意添加好友 func (*friendApp) AgreeAddFriend(ctx context.Context, userId, friendId int64, remarks string) error { return frienddomain.FriendService.AgreeAddFriend(ctx, userId, friendId, remarks) diff --git a/internal/logic/domain/friend/friend_repo.go b/internal/logic/domain/friend/friend_repo.go index 1f26c08..570801d 100644 --- a/internal/logic/domain/friend/friend_repo.go +++ b/internal/logic/domain/friend/friend_repo.go @@ -29,6 +29,12 @@ func (*friendRepo) Save(friend *Friend) error { return gerrors.WrapError(db.DB.Save(&friend).Error) } +// Delete 删除好友 +func (*friendRepo) Delete(userId, friendId int64) error { + friend := Friend{} + return gerrors.WrapError(db.DB.Where("user_id = ? and friend_id = ?", userId, friendId).Delete(&friend).Error) +} + // List 获取好友列表 func (*friendRepo) List(userId int64, status int) ([]Friend, error) { var friends []Friend diff --git a/internal/logic/domain/friend/friend_service.go b/internal/logic/domain/friend/friend_service.go index a235f32..a841eea 100644 --- a/internal/logic/domain/friend/friend_service.go +++ b/internal/logic/domain/friend/friend_service.go @@ -50,6 +50,15 @@ func (s *friendService) List(ctx context.Context, userId int64) ([]*pb.Friend, e return infos, nil } +// DeleteFriend 删除好友 +func (*friendService) DeleteFriend(ctx context.Context, userId, friendId int64) error { + err := FriendRepo.Delete(userId, friendId) + if err != nil { + return err + } + return nil +} + // AddFriend 添加好友 func (*friendService) AddFriend(ctx context.Context, userId, friendId int64, remarks, description string) error { friend, err := FriendRepo.Get(userId, friendId) diff --git a/internal/logic/domain/message/md/push.go b/internal/logic/domain/message/md/push.go new file mode 100644 index 0000000..26b017b --- /dev/null +++ b/internal/logic/domain/message/md/push.go @@ -0,0 +1,15 @@ +package md + +type PushParams struct { + MasterId string `json:"master_id"` //站长id + Uid string `json:"uid"` //用户id + PushAlia string `json:"push_alia"` //推送别名 + Title string `json:"title"` //标题 + Content string `json:"content"` //内容 + PushType string `json:"push_type"` //推送类型`zhi_ying_gim` + MessageType string `json:"message_type"` //消息类型`UNKNOWN、TEXT、FACE、VOICE、IMAGE、FILE、LOCATION、COMMAND、CUSTOM` + SendUserNickname string `json:"send_user_nickname"` //消费发送者-会员昵称 + SendUserAvatarUrl string `json:"send_user_avatar_url"` //消费发送者-会员头像 + Memo string `json:"reason"` //备注 + Times string `json:"times"` //时间 +} diff --git a/internal/logic/domain/message/service/app_push.go b/internal/logic/domain/message/service/app_push.go new file mode 100644 index 0000000..0ff1475 --- /dev/null +++ b/internal/logic/domain/message/service/app_push.go @@ -0,0 +1,55 @@ +package service + +import ( + jg_push "code.fnuoos.com/go_rely_warehouse/zyos_go_jg_push.git/hdl" + md2 "code.fnuoos.com/go_rely_warehouse/zyos_go_jg_push.git/md" + "gim/internal/business/comm/db" + md3 "gim/internal/logic/domain/message/md" + + "strings" +) + +func getChangeContent(args md3.PushParams, Content string) string { + Content = strings.Replace(Content, "[MasterId]", args.MasterId, -1) + Content = strings.Replace(Content, "[消费发送者-会员昵称]", args.SendUserNickname, -1) + Content = strings.Replace(Content, "[备注]", args.Memo, -1) + Content = strings.Replace(Content, "[时间]", args.Times, -1) + return Content +} + +// CommAddPush 公共处理推送数据 +func CommAddPush(args md3.PushParams) { + pushPlatform := db.DbSysCfg.SysCfgFindWithDb(args.MasterId, "app_push_platform")["app_push_platform"] + if pushPlatform == "jg" { //极光 + args.Content = getChangeContent(args, args.Content) + JgPush(args) + return + } + return +} + +func JgPush(args md3.PushParams) { + thirdJgPush := db.DbSysCfg.SysCfgFindWithDb(args.MasterId, "jg_push_app_key", "jg_push_app_secret") + if thirdJgPush["jg_push_app_key"] == "" || thirdJgPush["jg_push_app_secret"] == "" { + return + } + alia := db.DbUserPushForJg.UserPushForJgGetWithDb(args.MasterId, args.Uid) + var aud = md2.PushAudience{Alias: []string{alia}} + var extras interface{} + var param = md2.PushParam{ + Platform: "all", + Audience: aud, + Title: args.Title, + Content: args.Content, + Extras: extras, + } + send, _, err := jg_push.Send(thirdJgPush["jg_push_app_key"], thirdJgPush["jg_push_app_secret"], param) + if err != nil { + return + } + if send == "" { + return + } + //TODO::发送成功处理 + return +} diff --git a/internal/logic/domain/message/service/message_service.go b/internal/logic/domain/message/service/message_service.go index d4d0165..7864143 100644 --- a/internal/logic/domain/message/service/message_service.go +++ b/internal/logic/domain/message/service/message_service.go @@ -2,6 +2,8 @@ package service import ( "context" + svc "gim/internal/business/comm/service" + "gim/internal/logic/domain/message/md" "gim/internal/logic/domain/message/model" "gim/internal/logic/domain/message/repo" "gim/internal/logic/proxy" @@ -11,6 +13,8 @@ import ( "gim/pkg/pb" "gim/pkg/rpc" "gim/pkg/util" + "strconv" + "time" "go.uber.org/zap" "google.golang.org/protobuf/proto" @@ -89,7 +93,9 @@ func (*messageService) ListByUserIdAndSeq(ctx context.Context, userId, seq int64 // SendToUser 将消息发送给用户 func (*messageService) SendToUser(ctx context.Context, sender *pb.Sender, toUserId int64, req *pb.SendMessageReq) (int64, error) { + masterId, _ := grpclib.GetCtxMasterId(ctx) logger.Logger.Debug("SendToUser", + zap.String("master_id", masterId), zap.Int64("request_id", grpclib.GetCtxRequestId(ctx)), zap.Int64("to_user_id", toUserId)) var ( @@ -154,6 +160,23 @@ func (*messageService) SendToUser(ctx context.Context, sender *pb.Sender, toUser for i := range devices { // 消息不需要投递给发送消息的设备 if sender.DeviceId == devices[i].DeviceId { + isOpenAppPush := svc.SysCfgGet(masterId, "is_open_app_push") + if req.ReceiverType == 1 && isOpenAppPush == "1" { + //TODO::接收者类型为`user`, 进行极光推送 + CommAddPush(md.PushParams{ + MasterId: masterId, + Uid: strconv.FormatInt(req.ReceiverId, 10), + PushAlia: "", + Title: "新消息提醒", + Content: "", + PushType: "zhi_ying_gim", + MessageType: req.MessageType.String(), + SendUserNickname: sender.Nickname, + SendUserAvatarUrl: sender.AvatarUrl, + Memo: sender.SenderType.String(), + Times: time.Now().Format("2006-01-02 15:04:05.000"), + }) + } continue } diff --git a/pkg/pb/connect.ext.pb.go b/pkg/pb/connect.ext.pb.go index 891b272..381a364 100644 --- a/pkg/pb/connect.ext.pb.go +++ b/pkg/pb/connect.ext.pb.go @@ -419,8 +419,8 @@ type Sender struct { SenderType SenderType `protobuf:"varint,1,opt,name=sender_type,json=senderType,proto3,enum=pb.SenderType" json:"sender_type,omitempty"` // 发送者类型,1:系统,2:用户,3:第三方业务系统 SenderId int64 `protobuf:"varint,2,opt,name=sender_id,json=senderId,proto3" json:"sender_id,omitempty"` // 发送者id DeviceId int64 `protobuf:"varint,3,opt,name=device_id,json=deviceId,proto3" json:"device_id,omitempty"` // 发送者设备id - AvatarUrl string `protobuf:"bytes,4,opt,name=avatar_url,json=avatarUrl,proto3" json:"avatar_url,omitempty"` // 昵称 - Nickname string `protobuf:"bytes,5,opt,name=nickname,proto3" json:"nickname,omitempty"` // 头像 + AvatarUrl string `protobuf:"bytes,4,opt,name=avatar_url,json=avatarUrl,proto3" json:"avatar_url,omitempty"` // 头像 + Nickname string `protobuf:"bytes,5,opt,name=nickname,proto3" json:"nickname,omitempty"` // 昵称 Extra string `protobuf:"bytes,6,opt,name=extra,proto3" json:"extra,omitempty"` // 扩展字段 } diff --git a/pkg/proto/logic.ext.proto b/pkg/proto/logic.ext.proto index b35248c..9581974 100644 --- a/pkg/proto/logic.ext.proto +++ b/pkg/proto/logic.ext.proto @@ -18,6 +18,8 @@ service LogicExt { rpc AddFriend (AddFriendReq) returns (Empty); // 同意添加好友 rpc AgreeAddFriend (AgreeAddFriendReq) returns (Empty); + // 删除好友 + rpc DeleteFriend (DeleteFriendReq) returns (Empty); // 设置好友信息 rpc SetFriend (SetFriendReq) returns (SetFriendResp); // 获取好友列表 @@ -82,6 +84,11 @@ message AddFriendReq { string description = 3; // 描述 } +message DeleteFriendReq { + int64 user_id = 1; // 用户id +} + + message AgreeAddFriendReq { int64 user_id = 1; // 用户id string remarks = 2; // 备注 diff --git a/pkg/proto_back/business.ext.proto b/pkg/proto_back/business.ext.proto deleted file mode 100644 index eeb1b32..0000000 --- a/pkg/proto_back/business.ext.proto +++ /dev/null @@ -1,60 +0,0 @@ -syntax = "proto3"; -package pb; -option go_package = "gim/pkg/pb/"; - - -service BusinessExt { - // 登录 - rpc SignIn (SignInReq) returns (SignInResp); - // 获取用户信息 - rpc GetUser (GetUserReq) returns (GetUserResp); - // 更新用户信息 - rpc UpdateUser (UpdateUserReq) returns (Empty); - // 搜索用户(这里简单数据库实现,生产环境建议使用ES) - rpc SearchUser (SearchUserReq) returns (SearchUserResp); -} - -message Empty{} - -message SignInReq { - string phone_number = 1; // 手机号 - string code = 2; // 验证码 - int64 device_id = 3; // 设备id -} -message SignInResp { - bool is_new = 1; // 是否是新用户 - int64 user_id = 2; // 用户id - string token = 3; // token -} - -message User { - int64 user_id = 1; // 用户id - string nickname = 2; // 昵称 - int32 sex = 3; // 性别 - string avatar_url = 4; // 头像地址 - string extra = 5; // 附加字段 - int64 create_time = 6; // 创建时间 - int64 update_time = 7; // 更新时间 -} - -message GetUserReq { - int64 user_id = 1; // 用户id -} -message GetUserResp { - User user = 1; // 用户信息 -} - -message UpdateUserReq { - string nickname = 1; // 昵称 - int32 sex = 2; // 性别 - string avatar_url = 3; // 头像地址 - string extra = 4; // 附加字段 -} - -message SearchUserReq{ - string key = 1; -} -message SearchUserResp{ - repeated User users = 1; -} - diff --git a/pkg/proto_back/business.int.proto b/pkg/proto_back/business.int.proto deleted file mode 100644 index afd49b5..0000000 --- a/pkg/proto_back/business.int.proto +++ /dev/null @@ -1,45 +0,0 @@ -syntax = "proto3"; -package pb; -option go_package = "gim/pkg/pb/"; - - -service BusinessInt { - // 权限校验 - rpc Auth (AuthReq) returns (Empty); - // 批量获取用户信息 - rpc GetUser (GetUserReq) returns (GetUserResp); - // 批量获取用户信息 - rpc GetUsers (GetUsersReq) returns (GetUsersResp); -} - -message Empty{} - -message User { - int64 user_id = 1; // 用户id - string nickname = 2; // 昵称 - int32 sex = 3; // 性别 - string avatar_url = 4; // 头像地址 - string extra = 5; // 附加字段 - int64 create_time = 6; // 创建时间 - int64 update_time = 7; // 更新时间 -} - -message GetUserReq { - int64 user_id = 1; // 用户id -} -message GetUserResp { - User user = 1; // 用户信息 -} - -message AuthReq { - int64 user_id = 1; - int64 device_id = 2; - string token = 3; -} - -message GetUsersReq { - map user_ids = 1; // 用户id -} -message GetUsersResp { - map users = 1; // 用户信息 -} diff --git a/pkg/proto_back/common.ext.proto b/pkg/proto_back/common.ext.proto deleted file mode 100644 index 62448cb..0000000 --- a/pkg/proto_back/common.ext.proto +++ /dev/null @@ -1,5 +0,0 @@ -syntax = "proto3"; -package pb; -option go_package = "gim/pkg/pb/"; - -message Empty{} \ No newline at end of file diff --git a/pkg/proto_back/connect.ext.proto b/pkg/proto_back/connect.ext.proto deleted file mode 100644 index 92f01e6..0000000 --- a/pkg/proto_back/connect.ext.proto +++ /dev/null @@ -1,174 +0,0 @@ -syntax = "proto3"; -package pb; -option go_package = "gim/pkg/pb/"; - -enum PackageType { - PT_UNKNOWN = 0; // 未知 - PT_SIGN_IN = 1; // 设备登录请求 - PT_SYNC = 2; // 消息同步触发 - PT_HEARTBEAT = 3; // 心跳 - PT_MESSAGE = 4; // 消息投递 - PT_SUBSCRIBE_ROOM = 5; // 订阅房间 -} - -/************************************消息体定义开始************************************/ -// 单条消息投递内容(估算大约100个字节),todo 通知栏提醒 -message Message { - Sender sender = 1; // 发送者 - ReceiverType receiver_type = 2; // 接收者类型,1:user;2:group - int64 receiver_id = 3; // 用户id或者群组id - repeated int64 to_user_ids = 4; // 需要@的用户id列表 - MessageType message_type = 5; // 消息类型 - bytes message_content = 6; // 消息内容 - int64 seq = 7; // 用户消息发送序列号 - int64 send_time = 8; // 消息发送时间戳,精确到毫秒 - MessageStatus status = 9; // 消息状态 -} - -message Sender { - SenderType sender_type = 1; // 发送者类型,1:系统,2:用户,3:第三方业务系统 - int64 sender_id = 2; // 发送者id - int64 device_id = 3; // 发送者设备id - string avatar_url = 4; // 昵称 - string nickname = 5; // 头像 - string extra = 6; // 扩展字段 -} - -// 消息类型 -enum MessageType { - MT_UNKNOWN = 0; // 未知 - MT_TEXT = 1; // 文本 - MT_FACE = 2; // 表情 - MT_VOICE = 3; // 语音消息 - MT_IMAGE = 4; // 图片 - MT_FILE = 5; // 文件 - MT_LOCATION = 6; // 地理位置 - MT_COMMAND = 7; // 指令推送 - MT_CUSTOM = 8; // 自定义 -} - -// 文本消息 -message Text { - string text = 1; // 文本消息内容 -} - -// 表情消息 -message Face { - int64 face_id = 1; - string face_url = 2; -} - -// 语音消息 -message Voice { - string id = 1; // 语音包id - int32 size = 2; // 语音包大小 - int32 duration = 3; // 语音时长 - string url = 4; // 语音文件URL -} - -// 图片消息 -message Image { - string id = 1; // 图片id - int32 width = 2; // 图片宽度 - int32 height = 3; // 图片长度 - string url = 4; // 图片URL - string thumbnail_url = 5; // 图片缩略图url -} - -// 文件消息 -message File { - int64 id = 12; // 文件id - string name = 13; // 文件名 - int64 size = 14; // 文件大小 - string url = 15; // 文件url -} - -// 地理位置消息 -message Location { - string desc = 1; // 描述 - double latitude = 2; // 经度 - double longitude = 3; // 纬度 -} - -// Command 指令推送,1000以下,IM内部用,1000以上,留给业务用 -message Command { - int32 code = 1; // 指令码 - bytes data = 2; // 数据内容 -} - -// 自定义消息 -message Custom { - string data = 1; // 自定义数据 -} - -/************************************消息体定义结束************************************/ - -// 上行数据 -message Input { - PackageType type = 1; // 包的类型 - int64 request_id = 2; // 请求id - bytes data = 3; // 数据 -} - -// 下行数据 -message Output { - PackageType type = 1; // 包的类型 - int64 request_id = 2; // 请求id - int32 code = 3; // 错误码 - string message = 4; // 错误信息 - bytes data = 5; // 数据 -} - -// 设备登录,package_type:1 -message SignInInput { - int64 device_id = 1; // 设备id - int64 user_id = 2; // 用户id - string token = 3; // 秘钥 -} - -// 消息同步请求,package_type:2 -message SyncInput { - int64 seq = 1; // 客户端已经同步的序列号 -} -// 消息同步响应,package_type:2 -message SyncOutput { - repeated Message messages = 1; // 消息列表 - bool has_more = 2; // 是否有更多数据 -} - -// 订阅房间请求 -message SubscribeRoomInput { - int64 room_id = 1; // 房间ID,如果为0,取消房间订阅 - int64 seq = 2; // 消息消息序列号, -} - -enum ReceiverType { - RT_UNKNOWN = 0; // 未知 - RT_USER = 1; // 用户 - RT_GROUP = 2; // 群组 - RT_ROOM = 3; // 房间 -} - -// 消息投递,package_type:4 -message MessageSend { - Message message = 1; // 消息 -} - -enum SenderType { - ST_UNKNOWN = 0; // 未知的 - ST_SYSTEM = 1; // IM系统 - ST_USER = 2; // 用户 - ST_BUSINESS = 3; // 业务方 -} - -enum MessageStatus { - MS_UNKNOWN = 0; // 未知的 - MS_NORMAL = 1; // 正常的 - MS_RECALL = 2; // 撤回 -} - -// 投递消息回执,package_type:4 -message MessageACK { - int64 device_ack = 2; // 设备收到消息的确认号 - int64 receive_time = 3; // 消息接收时间戳,精确到毫秒 -} diff --git a/pkg/proto_back/connect.int.proto b/pkg/proto_back/connect.int.proto deleted file mode 100644 index a2e0719..0000000 --- a/pkg/proto_back/connect.int.proto +++ /dev/null @@ -1,83 +0,0 @@ -syntax = "proto3"; -package pb; -option go_package = "gim/pkg/pb/"; - -service ConnectInt { - // 消息投递 - rpc DeliverMessage (DeliverMessageReq) returns (Empty); -} -message Empty{} -enum SenderType { - ST_UNKNOWN = 0; // 未知的 - ST_SYSTEM = 1; // IM系统 - ST_USER = 2; // 用户 - ST_BUSINESS = 3; // 业务方 -} -message Sender { - SenderType sender_type = 1; // 发送者类型,1:系统,2:用户,3:第三方业务系统 - int64 sender_id = 2; // 发送者id - int64 device_id = 3; // 发送者设备id - string avatar_url = 4; // 昵称 - string nickname = 5; // 头像 - string extra = 6; // 扩展字段 -} -enum ReceiverType { - RT_UNKNOWN = 0; // 未知 - RT_USER = 1; // 用户 - RT_GROUP = 2; // 群组 - RT_ROOM = 3; // 房间 -} - -// 单条消息投递内容(估算大约100个字节),todo 通知栏提醒 -message Message { - Sender sender = 1; // 发送者 - ReceiverType receiver_type = 2; // 接收者类型,1:user;2:group - int64 receiver_id = 3; // 用户id或者群组id - repeated int64 to_user_ids = 4; // 需要@的用户id列表 - MessageType message_type = 5; // 消息类型 - bytes message_content = 6; // 消息内容 - int64 seq = 7; // 用户消息发送序列号 - int64 send_time = 8; // 消息发送时间戳,精确到毫秒 - MessageStatus status = 9; // 消息状态 -} -enum MessageStatus { - MS_UNKNOWN = 0; // 未知的 - MS_NORMAL = 1; // 正常的 - MS_RECALL = 2; // 撤回 -} - - -// 消息类型 -enum MessageType { - MT_UNKNOWN = 0; // 未知 - MT_TEXT = 1; // 文本 - MT_FACE = 2; // 表情 - MT_VOICE = 3; // 语音消息 - MT_IMAGE = 4; // 图片 - MT_FILE = 5; // 文件 - MT_LOCATION = 6; // 地理位置 - MT_COMMAND = 7; // 指令推送 - MT_CUSTOM = 8; // 自定义 -} - - -// 消息投递,package_type:4 -message MessageSend { - Message message = 1; // 消息 -} -message DeliverMessageReq { - int64 device_id = 1; // 设备id - MessageSend message_send = 2; // 数据 -} - -// 房间推送 -message PushRoomMsg{ - int64 room_id = 1; // 设备id - MessageSend message_send = 2; // 数据 -} - -// 房间推送 -message PushAllMsg{ - MessageSend message_send = 2; // 数据 -} - diff --git a/pkg/proto_back/logic.ext.proto b/pkg/proto_back/logic.ext.proto deleted file mode 100644 index e6fa480..0000000 --- a/pkg/proto_back/logic.ext.proto +++ /dev/null @@ -1,212 +0,0 @@ -syntax = "proto3"; -package pb; -option go_package = "gim/pkg/pb/"; - -message Empty{} - -service LogicExt { - // 注册设备 - rpc RegisterDevice (RegisterDeviceReq) returns (RegisterDeviceResp); - - // 发送消息 - rpc SendMessage (SendMessageReq) returns (SendMessageResp); - // 推送消息到房间 - rpc PushRoom(PushRoomReq)returns(Empty); - - // 添加好友 - rpc AddFriend (AddFriendReq) returns (Empty); - // 同意添加好友 - rpc AgreeAddFriend (AgreeAddFriendReq) returns (Empty); - // 设置好友信息 - rpc SetFriend (SetFriendReq) returns (SetFriendResp); - // 获取好友列表 - rpc GetFriends (Empty) returns (GetFriendsResp); - - // 创建群组 - rpc CreateGroup (CreateGroupReq) returns (CreateGroupResp); - // 更新群组 - rpc UpdateGroup (UpdateGroupReq) returns (Empty); - // 获取群组信息 - rpc GetGroup (GetGroupReq) returns (GetGroupResp); - // 获取用户加入的所有群组 - rpc GetGroups (Empty) returns (GetGroupsResp); - - // 添加群组成员 - rpc AddGroupMembers (AddGroupMembersReq) returns (AddGroupMembersResp); - // 更新群组成员信息 - rpc UpdateGroupMember (UpdateGroupMemberReq) returns (Empty); - // 添加群组成员 - rpc DeleteGroupMember (DeleteGroupMemberReq) returns (Empty); - // 获取群组成员 - rpc GetGroupMembers (GetGroupMembersReq) returns (GetGroupMembersResp); -} - -message RegisterDeviceReq { - int32 type = 2; // 设备类型 - string brand = 3; // 厂商 - string model = 4; // 机型 - string system_version = 5; // 系统版本 - string sdk_version = 6; // sdk版本号 -} -message RegisterDeviceResp { - int64 device_id = 1; // 设备id -} -enum ReceiverType { - RT_UNKNOWN = 0; // 未知 - RT_USER = 1; // 用户 - RT_GROUP = 2; // 群组 - RT_ROOM = 3; // 房间 -} -message SendMessageReq { - ReceiverType receiver_type = 1; // 接收者类型,1:user;2:group - int64 receiver_id = 2; // 用户id或者群组id - repeated int64 to_user_ids = 3; // 需要@的用户id列表 - MessageType message_type = 4; // 消息类型 - bytes message_content = 5; // 消息内容 - int64 send_time = 6; // 消息发送时间戳,精确到毫秒 - bool is_persist = 7; // 是否将消息持久化到数据库 -} -message SendMessageResp { - int64 seq = 1; // 消息序列号 -} -// 消息类型 -enum MessageType { - MT_UNKNOWN = 0; // 未知 - MT_TEXT = 1; // 文本 - MT_FACE = 2; // 表情 - MT_VOICE = 3; // 语音消息 - MT_IMAGE = 4; // 图片 - MT_FILE = 5; // 文件 - MT_LOCATION = 6; // 地理位置 - MT_COMMAND = 7; // 指令推送 - MT_CUSTOM = 8; // 自定义 -} -message PushRoomReq{ - int64 room_id = 1; // 房间id - MessageType message_type = 2; // 消息类型 - bytes message_content = 3; // 消息内容 - int64 send_time = 4; // 消息发送时间戳,精确到毫秒 - bool is_persist = 5; // 是否将消息持久化 - bool is_priority = 6; // 是否优先推送 -} - -message AddFriendReq { - int64 friend_id = 1; // 用户id - string remarks = 2; // 备注 - string description = 3; // 描述 -} - -message AgreeAddFriendReq { - int64 user_id = 1; // 用户id - string remarks = 2; // 备注 -} - -message SetFriendReq { - int64 friend_id = 1; // 好友id - string remarks = 2; // 备注 - string extra = 8; // 附加字段 -} -message SetFriendResp { - int64 friend_id = 1; // 好友id - string remarks = 2; // 备注 - string extra = 8; // 附加字段 -} - -message Friend { - int64 user_id = 1; // 用户id - string phone_number = 2; // 电话号码 - string nickname = 3; // 昵称 - int32 sex = 4; // 性别 - string avatar_url = 5; // 头像地址 - string user_extra = 6; // 用户附加字段 - string remarks = 7; // 备注 - string extra = 8; // 附加字段 -} -message GetFriendsResp { - repeated Friend friends = 1; -} - -message CreateGroupReq { - string name = 1; // 名称 - string avatar_url = 2; // 头像 - string introduction = 3; // 简介 - string extra = 4; // 附加字段 - repeated int64 member_ids = 5; // 群组成员ID列表 -} -message CreateGroupResp { - int64 group_id = 1; // 群组id -} - -message UpdateGroupReq { - int64 group_id = 1; // 群组id - string avatar_url = 2; // 头像 - string name = 3; // 名称 - string introduction = 4; // 简介 - string extra = 5; // 附加字段 -} - -message GetGroupReq { - int64 group_id = 1; -} -message GetGroupResp { - Group group = 1; -} - -message Group { - int64 group_id = 1; // 群组id - string name = 2; // 名称 - string avatar_url = 3; // 头像 - string introduction = 4; // 简介 - int32 user_mum = 5; // 用户数 - string extra = 6; // 附加字段 - int64 create_time = 7; // 创建时间 - int64 update_time = 8; // 更新时间 -} - -message GetGroupsResp { - repeated Group groups = 1; -} - -message AddGroupMembersReq { - int64 group_id = 1; // 群组id - repeated int64 user_ids = 2; // 用户id列表 -} -message AddGroupMembersResp { - repeated int64 user_ids = 1; // 已经在群组的用户id列表 -} - -enum MemberType { - GMT_UNKNOWN = 0; // 未知 - GMT_ADMIN = 1; // 管理员 - GMT_MEMBER = 2; // 成员 -} - -message UpdateGroupMemberReq { - int64 group_id = 1; // 群组id - int64 user_id = 2; // 用户id - MemberType member_type = 3; // 成员类型 - string remarks = 4; // 备注 - string extra = 5; // 附加字段 -} - -message DeleteGroupMemberReq { - int64 group_id = 1; // 群组id - int64 user_id = 2; // 用户id -} - -message GetGroupMembersReq { - int64 group_id = 1; -} -message GetGroupMembersResp { - repeated GroupMember members = 1; -} -message GroupMember { - int64 user_id = 1; - string nickname = 2; // 昵称 - int32 sex = 3; // 性别 - string avatar_url = 4; // 头像地址 - string user_extra = 5; // 用户附加字段 - MemberType member_type = 6; // 成员类型 - string remarks = 7; // 备注 - string extra = 8; // 群组成员附加字段 -} \ No newline at end of file diff --git a/pkg/proto_back/logic.int.proto b/pkg/proto_back/logic.int.proto deleted file mode 100644 index c9f8a31..0000000 --- a/pkg/proto_back/logic.int.proto +++ /dev/null @@ -1,177 +0,0 @@ -syntax = "proto3"; -package pb; -option go_package = "gim/pkg/pb/"; - -message Empty{} - -service LogicInt { - // 登录 - rpc ConnSignIn (ConnSignInReq) returns (Empty); - // 消息同步 - rpc Sync (SyncReq) returns (SyncResp); - // 设备收到消息回执 - rpc MessageACK (MessageACKReq) returns (Empty); - // 设备离线 - rpc Offline (OfflineReq) returns (Empty); - // 订阅房间 - rpc SubscribeRoom(SubscribeRoomReq)returns(Empty); - // 发送消息 - rpc SendMessage (SendMessageReq) returns (SendMessageResp); - // 推送消息到房间 - rpc PushRoom(PushRoomReq)returns(Empty); - // 全服推送 - rpc PushAll(PushAllReq)returns(Empty); - - // 获取设备信息 - rpc GetDevice (GetDeviceReq) returns (GetDeviceResp); - // 服务停止 - rpc ServerStop (ServerStopReq) returns (Empty); -} - -message PushRoomReq{ - int64 room_id = 1; // 房间id - MessageType message_type = 2; // 消息类型 - bytes message_content = 3; // 消息内容 - int64 send_time = 4; // 消息发送时间戳,精确到毫秒 - bool is_persist = 5; // 是否将消息持久化 - bool is_priority = 6; // 是否优先推送 -} - -message SendMessageResp { - int64 seq = 1; // 消息序列号 -} - -message SendMessageReq { - ReceiverType receiver_type = 1; // 接收者类型,1:user;2:group - int64 receiver_id = 2; // 用户id或者群组id - repeated int64 to_user_ids = 3; // 需要@的用户id列表 - MessageType message_type = 4; // 消息类型 - bytes message_content = 5; // 消息内容 - int64 send_time = 6; // 消息发送时间戳,精确到毫秒 - bool is_persist = 7; // 是否将消息持久化到数据库 -} - -enum ReceiverType { - RT_UNKNOWN = 0; // 未知 - RT_USER = 1; // 用户 - RT_GROUP = 2; // 群组 - RT_ROOM = 3; // 房间 -} - -// 消息类型 -enum MessageType { - MT_UNKNOWN = 0; // 未知 - MT_TEXT = 1; // 文本 - MT_FACE = 2; // 表情 - MT_VOICE = 3; // 语音消息 - MT_IMAGE = 4; // 图片 - MT_FILE = 5; // 文件 - MT_LOCATION = 6; // 地理位置 - MT_COMMAND = 7; // 指令推送 - MT_CUSTOM = 8; // 自定义 -} - -enum SenderType { - ST_UNKNOWN = 0; // 未知的 - ST_SYSTEM = 1; // IM系统 - ST_USER = 2; // 用户 - ST_BUSINESS = 3; // 业务方 -} - -message Sender { - SenderType sender_type = 1; // 发送者类型,1:系统,2:用户,3:第三方业务系统 - int64 sender_id = 2; // 发送者id - int64 device_id = 3; // 发送者设备id - string avatar_url = 4; // 昵称 - string nickname = 5; // 头像 - string extra = 6; // 扩展字段 -} - -// 单条消息投递内容(估算大约100个字节),todo 通知栏提醒 -message Message { - Sender sender = 1; // 发送者 - ReceiverType receiver_type = 2; // 接收者类型,1:user;2:group - int64 receiver_id = 3; // 用户id或者群组id - repeated int64 to_user_ids = 4; // 需要@的用户id列表 - MessageType message_type = 5; // 消息类型 - bytes message_content = 6; // 消息内容 - int64 seq = 7; // 用户消息发送序列号 - int64 send_time = 8; // 消息发送时间戳,精确到毫秒 - MessageStatus status = 9; // 消息状态 -} -enum MessageStatus { - MS_UNKNOWN = 0; // 未知的 - MS_NORMAL = 1; // 正常的 - MS_RECALL = 2; // 撤回 -} - -message ConnSignInReq { - int64 device_id = 1; // 设备id - int64 user_id = 2; // 用户id - string token = 3; // 秘钥 - string conn_addr = 4; // 服务器地址 - string client_addr = 5; // 客户端地址 -} - -message SyncReq { - int64 user_id = 1; // 用户id - int64 device_id = 2; // 设备id - int64 seq = 3; // 客户端已经同步的序列号 -} -message SyncResp { - repeated Message messages = 1; // 消息列表 - bool has_more = 2; // 是否有更多数据 -} - -message MessageACKReq { - int64 user_id = 1; // 用户id - int64 device_id = 2; // 设备id - int64 device_ack = 3; // 设备收到消息的确认号 - int64 receive_time = 4; // 消息接收时间戳,精确到毫秒 -} - -message OfflineReq { - int64 user_id = 1; // 用户id - int64 device_id = 2; // 设备id - string client_addr = 3; // 客户端地址 -} - -message SubscribeRoomReq{ - int64 user_id = 1; // 用户id - int64 device_id = 2; // 设备id - int64 room_id = 3; // 房间id - int64 seq = 4; // 消息序列号 - string conn_addr = 5; // 服务器地址 -} - -message PushAllReq{ - MessageType message_type = 1; // 消息类型 - bytes message_content = 2; // 消息内容 - int64 send_time = 3; // 消息发送时间戳,精确到毫秒 -} - -message GetDeviceReq { - int64 device_id = 1; -} -message GetDeviceResp { - Device device = 1; -} - -message Device { - int64 device_id = 1; // 设备id - int64 user_id = 2; // 用户id - int32 type = 3; // 设备类型,1:Android;2:IOS;3:Windows; 4:MacOS;5:Web - string brand = 4; // 手机厂商 - string model = 5; // 机型 - string system_version = 6; // 系统版本 - string sdk_version = 7; // SDK版本 - int32 status = 8; // 在线状态,0:不在线;1:在线 - string conn_addr = 9; // 服务端连接地址 - string client_addr = 10; // 客户端地址 - int64 create_time = 11; // 创建时间 - int64 update_time = 12; // 更新时间 -} - -message ServerStopReq { - string conn_addr = 1; -} diff --git a/pkg/proto_back/push.ext.proto b/pkg/proto_back/push.ext.proto deleted file mode 100644 index 72d3c2a..0000000 --- a/pkg/proto_back/push.ext.proto +++ /dev/null @@ -1,71 +0,0 @@ -syntax = "proto3"; -package pb; -option go_package = "gim/pkg/pb/"; - -enum PushCode { - PC_ADD_DEFAULT = 0; - - PC_ADD_FRIEND = 100; // 添加好友请求 - PC_AGREE_ADD_FRIEND = 101; // 同意添加好友 - - PC_UPDATE_GROUP = 110; // 更新群组 - - PC_ADD_GROUP_MEMBERS = 120; // 添加群组成员 - PC_REMOVE_GROUP_MEMBER = 121; // 移除群组成员 - -} - -// 推送码 PC_ADD_FRIEND = 100 -message AddFriendPush { - int64 friend_id = 1; // 好友id - string nickname = 2; // 昵称 - string avatar_url = 3; // 头像 - string description = 4; // 描述 -} - -// 推送码 PC_AGREE_ADD_FRIEND = 101 -message AgreeAddFriendPush { - int64 friend_id = 1; // 好友id - string nickname = 2; // 昵称 - string avatar_url = 3; // 头像 -} - -// 更新群组 PC_UPDATE_GROUP = 110 -message UpdateGroupPush { - int64 opt_id = 1; // 操作人用户id - string opt_name = 2; // 操作人昵称 - string name = 3; // 群组名称 - string avatar_url = 4; // 群组头像 - string introduction = 5; // 群组简介 - string extra = 6; // 附加字段 -} - -// 添加群组成员 PC_AGREE_ADD_GROUPS = 120 -message AddGroupMembersPush { - int64 opt_id = 1; // 操作人用户id - string opt_name = 2; // 操作人昵称 - repeated GroupMember members = 3; // 群组成员 -} - -// 删除群组成员 PC_REMOVE_GROUP_MEMBER = 121 -message RemoveGroupMemberPush { - int64 opt_id = 1; // 操作人用户id - string opt_name = 2; // 操作人昵称 - int64 deleted_user_id = 3; // 被删除的成员id -} - -enum MemberType { - GMT_UNKNOWN = 0; // 未知 - GMT_ADMIN = 1; // 管理员 - GMT_MEMBER = 2; // 成员 -} -message GroupMember { - int64 user_id = 1; - string nickname = 2; // 昵称 - int32 sex = 3; // 性别 - string avatar_url = 4; // 头像地址 - string user_extra = 5; // 用户附加字段 - MemberType member_type = 6; // 成员类型 - string remarks = 7; // 备注 - string extra = 8; // 群组成员附加字段 -} \ No newline at end of file diff --git a/test/tcp_conn/main.go b/test/tcp_conn/main.go index df3558b..da2c5d5 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: "LGTMCTLHAUBHNPBHSYWRIUDPGMXHUEFNAKLYZMTD", + Token: "RRTTGFUKCAQGAIDXMITFIBPMZOVSYDQQUQRZNMYG", } c.Output(pb.PackageType_PT_SIGN_IN, time.Now().UnixNano(), &signIn) }