diff --git a/business/auth2/auth2.go b/business/auth2/auth2.go index 05e8603e2..17acd991e 100644 --- a/business/auth2/auth2.go +++ b/business/auth2/auth2.go @@ -335,7 +335,7 @@ func Login(ctx *Context, authType, authID, authIDType, authSecret string) (authI return LoginInternal(ctx, authType, authID, authIDType, authSecret) } -// 抖音用户信息解密 +// TikTokDecryptInfo 抖音用户信息解密 type TikTokDecryptInfo struct { CountryCode string `json:"countryCode"` PhoneNumber string `json:"phoneNumber"` @@ -346,7 +346,13 @@ type TikTokDecryptInfo struct { } `json:"watermark"` } -func DecryptUserMsg(sessionKey, iv, msg string) (string, error) { +// KuaiShouInfo 抖音用户信息解密 +type KuaiShouInfo struct { + CountryCode string `json:"countryCode"` + PhoneNumber string `json:"phoneNumber"` +} + +func DecryptUserMsg(sessionKey, iv, msg, loginType string) (string, error) { decodeMsg, err := base64.StdEncoding.DecodeString(msg) if err != nil { return "", err @@ -364,11 +370,22 @@ func DecryptUserMsg(sessionKey, iv, msg string) (string, error) { if err != nil { return "", err } - result := &TikTokDecryptInfo{} - if err := json.Unmarshal(userInfo, result); err != nil { - return "", err + + switch loginType { + case "tiktokmini": + result := &TikTokDecryptInfo{} + if err := json.Unmarshal(userInfo, result); err != nil { + return "", err + } + return result.PhoneNumber, nil + case "kuaishoumini": + result := &KuaiShouInfo{} + if err := json.Unmarshal(userInfo, result); err != nil { + return "", err + } + return result.PhoneNumber, nil } - return result.PhoneNumber, nil + return "", ErrIllegalAuthType } // 通过临时TOKEN绑定新创建的用户 diff --git a/controllers/auth2.go b/controllers/auth2.go index 47df0f47b..fe5e489be 100644 --- a/controllers/auth2.go +++ b/controllers/auth2.go @@ -92,12 +92,13 @@ func (c *Auth2Controller) SendVerifyCode() { // @Param iv formData string true "加密字符偏移量" // @Param sessionKey formData string true "加密key" // @Param msg formData string true "加密消息" +// @Param loginType formData string true "登录类型兼容抖音登录/快手[tiktokmini/kuaishoumini]" // @Success 200 {object} controllers.CallResult // @Failure 200 {object} controllers.CallResult // @router /TiktokDecrypt [post] func (c *Auth2Controller) TiktokDecrypt() { c.callTiktokDecrypt(func(params *tAuth2TiktokDecryptParams) (interface{}, string, error) { - phone, err := auth2.DecryptUserMsg(params.SessionKey, params.Iv, params.Msg) + phone, err := auth2.DecryptUserMsg(params.SessionKey, params.Iv, params.Msg, params.LoginType) return phone, "", err }) }