diff --git a/api/errcode/errcode.go b/api/errcode/errcode.go index 6d6f2586..f8f9b397 100644 --- a/api/errcode/errcode.go +++ b/api/errcode/errcode.go @@ -36,8 +36,10 @@ var ErrCodeMsgMap = map[ErrCode]string{ ErrCodeLoginRegisterUserFail: "账号注册失败,请稍后重试", ErrCodeLoginWrongOldPswd: "旧密码错误", - ErrCodeAccountSrvFail: "账户服务错误", - ErrCodeAccountNotExist: "账户信息不存在", + ErrCodeAccountSrvFail: "账户服务错误", + ErrCodeAccountNotExist: "账户信息不存在", + ErrCodeAccountInviterNotExist: "邀请人不存在", + ErrCodeAccountInviterIsNotAStreamer: "邀请人非主播", ErrCodeVasSrvFail: "增值服务错误", ErrCodeVasProductNotExist: "商品不存在", @@ -188,9 +190,11 @@ const ( ErrCodeLoginWrongOldPswd ErrCode = -5011 //旧密码错误 // Account: 6xxx - ErrCodeAccountSrvOk ErrCode = ErrCodeOk - ErrCodeAccountSrvFail ErrCode = -6001 //账户服务错误 - ErrCodeAccountNotExist ErrCode = -6002 //账户信息不存在 + ErrCodeAccountSrvOk ErrCode = ErrCodeOk + ErrCodeAccountSrvFail ErrCode = -6001 //账户服务错误 + ErrCodeAccountNotExist ErrCode = -6002 //账户信息不存在 + ErrCodeAccountInviterNotExist ErrCode = -6003 //邀请人不存在, + ErrCodeAccountInviterIsNotAStreamer ErrCode = -6004 //邀请人非主播, // Vas: 7xxx ErrCodeVasSrvOk ErrCode = ErrCodeOk diff --git a/api/proto/login/proto/login_api.go b/api/proto/login/proto/login_api.go index 089ba84c..5da120d4 100644 --- a/api/proto/login/proto/login_api.go +++ b/api/proto/login/proto/login_api.go @@ -75,6 +75,7 @@ type ApiLoginByVeriCodeReq struct { base.BaseRequest MobilePhoneInfoComponent `jcrypto:"true"` VeriCodeComponent + Inviter *int64 `json:"inviter"` } type ApiLoginData struct { diff --git a/api/proto/login/proto/login_op.go b/api/proto/login/proto/login_op.go index 5f6d5238..3eb7cbd7 100644 --- a/api/proto/login/proto/login_op.go +++ b/api/proto/login/proto/login_op.go @@ -75,6 +75,7 @@ type OpLoginByVeriCodeReq struct { base.BaseRequest MobilePhoneInfoComponent `jcrypto:"true"` VeriCodeComponent + Inviter *int64 `json:"inviter"` } type OpLoginData struct { diff --git a/app/mix/service/apiservice.go b/app/mix/service/apiservice.go index 5f30ef92..6b95b20f 100644 --- a/app/mix/service/apiservice.go +++ b/app/mix/service/apiservice.go @@ -123,7 +123,7 @@ func (s *Service) ApiLoginByVeriCode(ctx *gin.Context, req *loginproto.ApiLoginB // 2.如果错误码是登录信息不存在,则判断为首次登录,将创建用户信息 if ec == errcode.ErrCodeLoginNotExist { - login, account, ec = s.utilRegisterUser(ctx, &req.MobilePhoneInfoComponent) + login, account, ec = s.utilRegisterUser(ctx, &req.MobilePhoneInfoComponent, req.Inviter) if ec != errcode.ErrCodeLoginSrvOk { logger.Error("utilRegisterUser failed") ec = errcode.ErrCodeLoginRegisterUserFail diff --git a/app/mix/service/apiservice_business_validation.go b/app/mix/service/apiservice_business_validation.go index 940495d2..4af569af 100644 --- a/app/mix/service/apiservice_business_validation.go +++ b/app/mix/service/apiservice_business_validation.go @@ -106,13 +106,26 @@ func (s *Service) ApiLoginByVeriCodeBusinessValidate(ctx *gin.Context, req *logi // 2.如果错误码是登录信息不存在,则判断为首次登录,业务逻辑将创建用户信息 if ec == errcode.ErrCodeLoginNotExist { vericode, _ = resultList[3].(*dbstruct.VeriCode) + if req.Inviter != nil { + inviter, err := _DefaultAccount.OpListByUserId(ctx, &accountproto.OpListByUserIdReq{ + UserId: req.Inviter, + }) + if err != nil || inviter == nil { + ec = errcode.ErrCodeAccountInviterNotExist + return + } + if util.DerefInt64(inviter.Role) != consts.Streamer { + ec = errcode.ErrCodeAccountInviterIsNotAStreamer + return + } + } return } else if ec == errcode.ErrCodeLoginSrvOk { login, _ = resultList[1].(*dbstruct.Login) account, _ = resultList[2].(*dbstruct.Account) vericode, _ = resultList[3].(*dbstruct.VeriCode) } else { - logger.Error("ApiLoginByPswd business validation failed!") + logger.Error("ApiLoginByVeriCode business validation failed!") return } return diff --git a/app/mix/service/opservice_business_validation.go b/app/mix/service/opservice_business_validation.go index cf7133da..cd8b9627 100644 --- a/app/mix/service/opservice_business_validation.go +++ b/app/mix/service/opservice_business_validation.go @@ -1,6 +1,7 @@ package service import ( + "service/api/consts" "service/api/errcode" accountproto "service/api/proto/account/proto" accountrelationproto "service/api/proto/accountrelation/proto" @@ -18,6 +19,7 @@ import ( userwxaddcheckproto "service/api/proto/userwxaddcheck/proto" vericodeproto "service/api/proto/vericode/proto" businessvalidator "service/app/mix/service/business_validator" + "service/bizcommon/util" "service/dbstruct" "service/library/logger" "service/library/mycrypto" @@ -112,6 +114,19 @@ func (s *Service) OpLoginByVeriCodeBusinessValidate(ctx *gin.Context, req *login // 2.如果错误码是登录信息不存在,则判断为首次登录,将创建用户信息 if ec == errcode.ErrCodeLoginNotExist { + if req.Inviter != nil { + inviter, err := _DefaultAccount.OpListByUserId(ctx, &accountproto.OpListByUserIdReq{ + UserId: req.Inviter, + }) + if err != nil || inviter == nil { + ec = errcode.ErrCodeAccountInviterNotExist + return + } + if util.DerefInt64(inviter.Role) != consts.Streamer { + ec = errcode.ErrCodeAccountInviterIsNotAStreamer + return + } + } return } else if ec == errcode.ErrCodeLoginSrvOk { login, _ = resultList[1].(*dbstruct.Login) diff --git a/app/mix/service/service.go b/app/mix/service/service.go index 76adef72..c382458b 100644 --- a/app/mix/service/service.go +++ b/app/mix/service/service.go @@ -524,7 +524,7 @@ func (s *Service) OpLoginByVeriCode(ctx *gin.Context, req *loginproto.OpLoginByV // 2.如果错误码是登录信息不存在,则判断为首次登录,将创建用户信息 if ec == errcode.ErrCodeLoginNotExist { - login, account, ec = s.utilRegisterUser(ctx, &req.MobilePhoneInfoComponent) + login, account, ec = s.utilRegisterUser(ctx, &req.MobilePhoneInfoComponent, req.Inviter) if ec != errcode.ErrCodeLoginSrvOk { logger.Error("utilRegisterUser failed") ec = errcode.ErrCodeLoginRegisterUserFail diff --git a/app/mix/service/utilservice.go b/app/mix/service/utilservice.go index 4c426a83..9f64d7a3 100644 --- a/app/mix/service/utilservice.go +++ b/app/mix/service/utilservice.go @@ -19,7 +19,7 @@ import ( // 不向外暴露的辅助公共函数 // 注册账户 -func (s *Service) utilRegisterUser(ctx *gin.Context, req *loginproto.MobilePhoneInfoComponent) (login *dbstruct.Login, account *dbstruct.Account, ec errcode.ErrCode) { +func (s *Service) utilRegisterUser(ctx *gin.Context, req *loginproto.MobilePhoneInfoComponent, inviter *int64) (login *dbstruct.Login, account *dbstruct.Account, ec errcode.ErrCode) { var err error ec = errcode.ErrCodeLoginSrvOk @@ -44,6 +44,7 @@ func (s *Service) utilRegisterUser(ctx *gin.Context, req *loginproto.MobilePhone account.MobilePhone = goproto.String(req.MobilePhone) account.RegionCode = goproto.String(req.RegionCode) account.PhoneHash = goproto.String(req.PhoneHash) + account.Inviter = inviter // 创建账户,生成mid err = _DefaultAccount.OpCreate(ctx, &accountproto.OpCreateReq{ diff --git a/dbstruct/account.go b/dbstruct/account.go index a989dc8f..672226ec 100644 --- a/dbstruct/account.go +++ b/dbstruct/account.go @@ -20,6 +20,7 @@ type Account struct { IsDndModeEnabled *int64 `json:"is_dnd_mode_enabled" bson:"is_dnd_mode_enabled"` // 是否开启勿扰模式 GoldNum *int64 `json:"gold_num" bson:"gold_num"` // 金币数量 DiamondNum *int64 `json:"diamond_num" bson:"diamond_num"` // 钻石数量 + Inviter *int64 `json:"inviter" bson:"inviter"` // 邀请人user_id Latitude *float64 `bson:"latitude"` // 纬度 Longitude *float64 `bson:"longitude"` // 经度 Ct *int64 `json:"ct" bson:"ct"` // 创建时间 diff --git a/library/mycrypto/aesCrypto.go b/library/mycrypto/aesCrypto.go index 18bb2852..5e6c52ba 100644 --- a/library/mycrypto/aesCrypto.go +++ b/library/mycrypto/aesCrypto.go @@ -39,6 +39,9 @@ func (aesCrypto *AesCrypto) Encrypt(msg []byte) (encryptedBytes []byte, err erro } func (aesCrypto *AesCrypto) Decrypt(encryptedBytes []byte) (decryptedBytes []byte, err error) { + if len(encryptedBytes) == 0 { + return + } //CBC解密 block, _ := aes.NewCipher(aesCrypto.aesPriKey) // 分组秘钥 blockSize := block.BlockSize() // 获取秘钥块的长度 diff --git a/library/mycrypto/rsaCrypto.go b/library/mycrypto/rsaCrypto.go index 32ac06d0..a023f385 100644 --- a/library/mycrypto/rsaCrypto.go +++ b/library/mycrypto/rsaCrypto.go @@ -39,6 +39,9 @@ func (rsaCrypto *RsaCrypto) Encrypt(msg []byte) (encryptedBytes []byte, err erro } func (rsaCrypto *RsaCrypto) Decrypt(encryptedBytes []byte) (decryptedBytes []byte, err error) { + if len(encryptedBytes) == 0 { + return + } //私钥解密 decryptedBytes, err = rsa.DecryptPKCS1v15(rand.Reader, rsaCrypto.rsaPriKey, encryptedBytes) if err != nil {