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

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 ( import (
"bytes" "bytes"
"encoding/base64" "encoding/base64"
"encoding/json"
"errors" "errors"
"regexp" "regexp"
"strings" "strings"
@@ -316,6 +317,42 @@ func Login(ctx *Context, authType, authID, authIDType, authSecret string) (authI
return LoginInternal(ctx, authType, authID, authIDType, authSecret) 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绑定新创建的用户 // 通过临时TOKEN绑定新创建的用户
func BindUser(inauthInfo *AuthInfo, user IUser) (outauthInfo *AuthInfo, err error) { func BindUser(inauthInfo *AuthInfo, user IUser) (outauthInfo *AuthInfo, err error) {
if err = AddAuthBind(user, inauthInfo); err == nil { if err = AddAuthBind(user, inauthInfo); err == nil {

View File

@@ -90,6 +90,21 @@ func (c *Auth2Controller) SendVerifyCode() {
}) })
} }
// @Title 抖音解密接口,获取用户电话
// @Description 抖音解密接口,获取用户电话
// @Param iv formData string true "加密字符偏移量"
// @Param sessionKey formData string true "加密key"
// @Param msg formData string true "加密消息"
// @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)
return phone, "", err
})
}
// @Title 登录接口 // @Title 登录接口
// @Description 登录接口(微信与公众号登录不能直接调用此接口) // @Description 登录接口(微信与公众号登录不能直接调用此接口)
// @Param authType formData string true "登录类型,当前支持[localpass本地账号密码mobile手机短信wxqrcode:微信登录weixinsns微信公众号weixinmini小程序wxnative微信APPddstaff钉钉企业ddqrcode钉钉扫码alipaycode支付宝小程序]" // @Param authType formData string true "登录类型,当前支持[localpass本地账号密码mobile手机短信wxqrcode:微信登录weixinsns微信公众号weixinmini小程序wxnative微信APPddstaff钉钉企业ddqrcode钉钉扫码alipaycode支付宝小程序]"

View File

@@ -268,6 +268,15 @@ func init() {
Filters: nil, Filters: nil,
Params: nil}) Params: nil})
web.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:Auth2Controller"] = append(web.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:Auth2Controller"],
web.ControllerComments{
Method: "TiktokDecrypt",
Router: `/TiktokDecrypt`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Filters: nil,
Params: nil})
web.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:Auth2Controller"] = append(web.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:Auth2Controller"], web.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:Auth2Controller"] = append(web.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:Auth2Controller"],
web.ControllerComments{ web.ControllerComments{
Method: "Logout", Method: "Logout",