新增抖音用户基本信息解密

This commit is contained in:
邹宗楠
2022-06-10 18:03:13 +08:00
parent 5fd9ffcb26
commit a6fb0ed185
3 changed files with 61 additions and 0 deletions

View File

@@ -3,6 +3,7 @@ package auth2
import (
"bytes"
"encoding/base64"
"encoding/json"
"errors"
"regexp"
"strings"
@@ -316,6 +317,42 @@ func Login(ctx *Context, authType, authID, authIDType, authSecret string) (authI
return LoginInternal(ctx, authType, authID, authIDType, authSecret)
}
// 抖音用户信息解密
type TikTokDecryptInfo struct {
CountryCode string `json:"countryCode"`
PhoneNumber string `json:"phoneNumber"`
PurePhoneNumber string `json:"purePhoneNumber"`
Watermark *struct {
AppID string `json:"appid"`
Timestamp int64 `json:"timestamp"`
} `json:"watermark"`
}
func DecryptUserMsg(sessionKey, iv, msg string) (string, error) {
decodeMsg, err := base64.StdEncoding.DecodeString(msg)
if err != nil {
return "", err
}
decodeIv, err := base64.StdEncoding.DecodeString(iv)
if err != nil {
return "", err
}
decodeSessionKey, err := base64.StdEncoding.DecodeString(sessionKey)
if err != nil {
return "", err
}
userInfo, err := utils.AESCBC16Decrypt(decodeSessionKey, decodeIv, decodeMsg)
if err != nil {
return "", err
}
result := &TikTokDecryptInfo{}
if err := json.Unmarshal(userInfo, result); err != nil {
return "", err
}
return result.PhoneNumber, nil
}
// 通过临时TOKEN绑定新创建的用户
func BindUser(inauthInfo *AuthInfo, user IUser) (outauthInfo *AuthInfo, err error) {
if err = AddAuthBind(user, inauthInfo); err == nil {