From b9fb32157ebca5f2f8a13b00b894e2fa98f5ef56 Mon Sep 17 00:00:00 2001 From: DengBiao <2319963317@qq.com> Date: Mon, 28 Nov 2022 21:00:21 +0800 Subject: [PATCH] update --- chart/templates/configmap/configmap-prd.yaml | 11 ++++++ chart/templates/server/business.yaml | 2 +- chart/templates/server/connect.yaml | 2 +- chart/templates/server/logic.yaml | 2 +- cmd/business/main.go | 2 +- internal/business/api/business_ext.go | 2 +- internal/business/app/auth_app.go | 4 +- .../business/comm/db/db_user_push_for_jg.go | 4 +- internal/business/domain/user/service/auth.go | 22 ++++++++++- .../logic/domain/message/service/app_push.go | 4 +- .../domain/message/service/message_service.go | 39 +++++++++++-------- pkg/pb/business.ext.pb.go | 1 + pkg/proto/business.ext.proto | 1 + 13 files changed, 68 insertions(+), 28 deletions(-) create mode 100644 chart/templates/configmap/configmap-prd.yaml diff --git a/chart/templates/configmap/configmap-prd.yaml b/chart/templates/configmap/configmap-prd.yaml new file mode 100644 index 0000000..e6500c6 --- /dev/null +++ b/chart/templates/configmap/configmap-prd.yaml @@ -0,0 +1,11 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: config +data: + # 类属性键;每一个键都映射到一个简单的值,仅仅支持键值对,不支持嵌套 + mysql: "root:ZHIoscnfnuo123@@tcp(zhios123.rwlb.rds.aliyuncs.com:3306)/gim?charset=utf8&parseTime=true" + redisIP: "116.62.62.35:6379" + redisPassword: "dengsanhu" + pushRoomSubscribeNum: "100" + pushAllSubscribeNum: "100" diff --git a/chart/templates/server/business.yaml b/chart/templates/server/business.yaml index e697f27..df48c88 100644 --- a/chart/templates/server/business.yaml +++ b/chart/templates/server/business.yaml @@ -18,7 +18,7 @@ spec: spec: containers: - name: business - image: 'registry.cn-shenzhen.aliyuncs.com/fnuoos-prd/zyos-gim-business:202209020-03' + image: 'registry.cn-shenzhen.aliyuncs.com/fnuoos-prd/zyos-gim-business:20221128-01' imagePullPolicy: Always ports: - containerPort: 8000 diff --git a/chart/templates/server/connect.yaml b/chart/templates/server/connect.yaml index 88df932..f48fd72 100644 --- a/chart/templates/server/connect.yaml +++ b/chart/templates/server/connect.yaml @@ -18,7 +18,7 @@ spec: spec: containers: - name: connect - image: 'registry.cn-shenzhen.aliyuncs.com/fnuoos-prd/zyos-gim-connect:202209018-03' + image: 'registry.cn-shenzhen.aliyuncs.com/fnuoos-prd/zyos-gim-connect:20221128-01' imagePullPolicy: Always ports: - containerPort: 8000 diff --git a/chart/templates/server/logic.yaml b/chart/templates/server/logic.yaml index d61eae1..b73608e 100644 --- a/chart/templates/server/logic.yaml +++ b/chart/templates/server/logic.yaml @@ -18,7 +18,7 @@ spec: spec: containers: - name: logic - image: 'registry.cn-shenzhen.aliyuncs.com/fnuoos-prd/zyos-gim-logic:202209018-04' + image: 'registry.cn-shenzhen.aliyuncs.com/fnuoos-prd/zyos-gim-logic:20221128-01' imagePullPolicy: Always # 在kind中需要指定,不然会强制到远程拉取镜像,导致部署失败 ports: - containerPort: 8001 diff --git a/cmd/business/main.go b/cmd/business/main.go index 35ad187..8852cae 100644 --- a/cmd/business/main.go +++ b/cmd/business/main.go @@ -18,7 +18,7 @@ import ( ) func main() { - //config.Init() + config.Init() db.Init() server := grpc.NewServer(grpc.UnaryInterceptor(interceptor.NewInterceptor("business_interceptor", urlwhitelist.Business))) diff --git a/internal/business/api/business_ext.go b/internal/business/api/business_ext.go index e69ff61..1cc896c 100644 --- a/internal/business/api/business_ext.go +++ b/internal/business/api/business_ext.go @@ -13,7 +13,7 @@ import ( type BusinessExtServer struct{} func (s *BusinessExtServer) SignIn(ctx context.Context, req *pb.SignInReq) (*pb.SignInResp, error) { - isNew, userId, token, masterId, err := app.AuthApp.SignIn(ctx, req.PhoneNumber, req.Code, req.MasterId, req.DeviceId) + isNew, userId, token, masterId, err := app.AuthApp.SignIn(ctx, req.PhoneNumber, req.Code, req.MasterId, req.DeviceId, req.PushAlia) if err != nil { return nil, err } diff --git a/internal/business/app/auth_app.go b/internal/business/app/auth_app.go index fbda97e..94baf4a 100644 --- a/internal/business/app/auth_app.go +++ b/internal/business/app/auth_app.go @@ -10,8 +10,8 @@ type authApp struct{} var AuthApp = new(authApp) // SignIn 长连接登录 -func (*authApp) SignIn(ctx context.Context, phoneNumber, code string, masterId, deviceId int64) (bool, int64, string, int64, error) { - return service.AuthService.SignIn(ctx, phoneNumber, code, masterId, deviceId) +func (*authApp) SignIn(ctx context.Context, phoneNumber, code string, masterId, deviceId int64, pushAlia string) (bool, int64, string, int64, error) { + return service.AuthService.SignIn(ctx, phoneNumber, code, masterId, deviceId, pushAlia) } // Auth 验证用户是否登录 diff --git a/internal/business/comm/db/db_user_push_for_jg.go b/internal/business/comm/db/db_user_push_for_jg.go index 2f38ab6..87f4618 100644 --- a/internal/business/comm/db/db_user_push_for_jg.go +++ b/internal/business/comm/db/db_user_push_for_jg.go @@ -15,9 +15,9 @@ type dbUserPushForJg struct{} var DbUserPushForJg = new(dbUserPushForJg) // UserPushForJgGetOne 获取一条记录 -func (*dbUserPushForJg) UserPushForJgGetOne(key string, masterId int64) (*model.UserPushForJg, error) { +func (*dbUserPushForJg) UserPushForJgGetOne(uid 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 { + if err := db.DB.Where("`uid` = ? and `master_id` = ?", uid, masterId).First(&cfgList).Error; err != nil { return nil, gerrors.WrapError(err) } return &cfgList, nil diff --git a/internal/business/domain/user/service/auth.go b/internal/business/domain/user/service/auth.go index 1b75b1d..072255e 100644 --- a/internal/business/domain/user/service/auth.go +++ b/internal/business/domain/user/service/auth.go @@ -2,12 +2,15 @@ package service import ( "context" + "errors" + "gim/internal/business/comm/db" "gim/internal/business/domain/user/model" "gim/internal/business/domain/user/repo" "gim/pkg/gerrors" "gim/pkg/pb" "gim/pkg/rpc" "gim/pkg/util" + "strconv" "time" ) @@ -16,7 +19,7 @@ type authService struct{} var AuthService = new(authService) // SignIn 登录 -func (*authService) SignIn(ctx context.Context, phoneNumber, code string, masterId, deviceId int64) (bool, int64, string, int64, error) { +func (*authService) SignIn(ctx context.Context, phoneNumber, code string, masterId, deviceId int64, pushAlia string) (bool, int64, string, int64, error) { if !Verify(phoneNumber, code) { return false, 0, "", 0, gerrors.ErrBadCode } @@ -58,6 +61,23 @@ func (*authService) SignIn(ctx context.Context, phoneNumber, code string, master return false, 0, "", 0, err } + if pushAlia != "" { + userPushForJg, err := db.DbUserPushForJg.UserPushForJgGetOne(strconv.FormatInt(user.Id, 10), masterId) + if err != nil { + return false, 0, "", 0, err + } + if userPushForJg == nil { + save := db.DbUserPushForJg.UserPushForJgInsert(user.Id, masterId, pushAlia) + if !save { + return false, 0, "", 0, errors.New("插入user_push_for_jg记录失败") + } + } else { + update := db.DbUserPushForJg.UserPushForJgUpdate(user.Id, masterId, pushAlia) + if !update { + return false, 0, "", 0, errors.New("修改user_push_for_jg记录失败") + } + } + } return isNew, user.Id, token, masterId, nil } diff --git a/internal/logic/domain/message/service/app_push.go b/internal/logic/domain/message/service/app_push.go index 0ff1475..3bc3925 100644 --- a/internal/logic/domain/message/service/app_push.go +++ b/internal/logic/domain/message/service/app_push.go @@ -33,8 +33,8 @@ func JgPush(args md3.PushParams) { 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}} + //alia := db.DbUserPushForJg.UserPushForJgGetWithDb(args.MasterId, args.Uid) + var aud = md2.PushAudience{Alias: []string{args.PushAlia}} var extras interface{} var param = md2.PushParam{ Platform: "all", diff --git a/internal/logic/domain/message/service/message_service.go b/internal/logic/domain/message/service/message_service.go index 7864143..252c3f4 100644 --- a/internal/logic/domain/message/service/message_service.go +++ b/internal/logic/domain/message/service/message_service.go @@ -2,6 +2,7 @@ package service import ( "context" + "gim/internal/business/comm/db" svc "gim/internal/business/comm/service" "gim/internal/logic/domain/message/md" "gim/internal/logic/domain/message/model" @@ -157,26 +158,32 @@ func (*messageService) SendToUser(ctx context.Context, sender *pb.Sender, toUser return 0, err } + var isPush = false for i := range devices { - // 消息不需要投递给发送消息的设备 - if sender.DeviceId == devices[i].DeviceId { + if sender.DeviceId == devices[i].DeviceId && !isPush { 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"), - }) + uid := strconv.FormatInt(req.ReceiverId, 10) + alia := db.DbUserPushForJg.UserPushForJgGetWithDb(masterId, uid) + if alia != "" { + //TODO::接收者类型为`user`, 进行极光推送 + CommAddPush(md.PushParams{ + MasterId: masterId, + Uid: uid, + 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"), + }) + isPush = true + } } + // 消息不需要投递给发送消息的设备 continue } diff --git a/pkg/pb/business.ext.pb.go b/pkg/pb/business.ext.pb.go index 548d8e3..083b0d1 100644 --- a/pkg/pb/business.ext.pb.go +++ b/pkg/pb/business.ext.pb.go @@ -33,6 +33,7 @@ type SignInReq struct { Code string `protobuf:"bytes,2,opt,name=code,proto3" json:"code,omitempty"` // 验证码 DeviceId int64 `protobuf:"varint,3,opt,name=device_id,json=deviceId,proto3" json:"device_id,omitempty"` // 设备id MasterId int64 `protobuf:"varint,4,opt,name=master_id,json=masterId,proto3" json:"master_id,omitempty"` // 站长id + PushAlia string `protobuf:"varint,5,opt,name=push_alia,json=pushAlia,proto3" json:"push_alia,omitempty"` // 极光推送-别名 } func (x *SignInReq) Reset() { diff --git a/pkg/proto/business.ext.proto b/pkg/proto/business.ext.proto index b2c672c..bc01a31 100644 --- a/pkg/proto/business.ext.proto +++ b/pkg/proto/business.ext.proto @@ -22,6 +22,7 @@ message SignInReq { string code = 2; // 验证码 int64 device_id = 3; // 设备id int64 master_id = 4; // 站长id + string push_alia = 5; // 极光推送-别名 } message SignInResp { bool is_new = 1; // 是否是新用户