新增抖音授权登录,添加定时任务,更新[配送中的订单骑手位置!
This commit is contained in:
93
business/auth2/authprovider/douyin/tiktop_mini.go
Normal file
93
business/auth2/authprovider/douyin/tiktop_mini.go
Normal file
@@ -0,0 +1,93 @@
|
||||
package douyin
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"git.rosy.net.cn/jx-callback/business/auth2/authprovider/weixin"
|
||||
|
||||
"git.rosy.net.cn/baseapi/platformapi/weixinapi"
|
||||
"git.rosy.net.cn/jx-callback/business/auth2"
|
||||
"git.rosy.net.cn/jx-callback/business/auth2/authprovider"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
)
|
||||
|
||||
const (
|
||||
AuthTypeTiktokMini = "tiktokmini" // 抖音小程序
|
||||
)
|
||||
|
||||
type TiktopMiniAuther struct {
|
||||
authprovider.DefAuther
|
||||
}
|
||||
|
||||
var (
|
||||
ErrAuthTypeShouldBeMini = errors.New("当前操作要求是抖音小程序登录方式")
|
||||
)
|
||||
|
||||
var (
|
||||
AutherObjMini *TiktopMiniAuther
|
||||
)
|
||||
|
||||
func init() {
|
||||
AutherObjMini = new(TiktopMiniAuther)
|
||||
auth2.RegisterAuther(AuthTypeTiktokMini, AutherObjMini)
|
||||
}
|
||||
|
||||
func (a *TiktopMiniAuther) VerifySecret(dummy, code string) (authBindEx *auth2.AuthBindEx, err error) {
|
||||
globals.SugarLogger.Debugf("toktok mini VerifySecret jsCode:%s", code)
|
||||
|
||||
sessionInfo, err := api.TiktokApi.GetTiktokToken(code)
|
||||
if err == nil {
|
||||
if authBindEx, err = a.UnionFindAuthBind(AuthTypeTiktokMini, api.TiktokApi.GetAppID(), []string{AuthTypeTiktokMini}, sessionInfo.Data.OpenId, sessionInfo.Data.UnionId, sessionInfo); err == nil {
|
||||
authBindEx.UserData = sessionInfo.Data
|
||||
}
|
||||
}
|
||||
return authBindEx, err
|
||||
}
|
||||
|
||||
// 特殊接口
|
||||
func (a *TiktopMiniAuther) DecryptData(authInfo *auth2.AuthInfo, jsCode, encryptedData, iv string) (decryptedDataBase64 string, err error) {
|
||||
globals.SugarLogger.Debugf("weixin mini DecryptData jsCode:%s, encryptedData:%s, iv:%s", jsCode, encryptedData, iv)
|
||||
var sessionKey string
|
||||
appID, jsCode := weixin.SplitJsCode(jsCode)
|
||||
if jsCode != "" {
|
||||
sessionInfo, err := getWxApp(appID).SNSCode2Session(jsCode)
|
||||
if err == nil {
|
||||
// if authBindEx, err := a.UnionFindAuthBind(AuthTypeMini, getWxApp(appID).GetAppID(), []string{AuthTypeMini}, sessionInfo.OpenID, "", nil); err == nil {
|
||||
// if authBindEx.UserID != authInfo.GetID() {
|
||||
// return "", fmt.Errorf("jsCode与token不匹配")
|
||||
// }
|
||||
// } else {
|
||||
// return "", err
|
||||
// }
|
||||
sessionKey = sessionInfo.SessionKey
|
||||
} else {
|
||||
return "", err
|
||||
}
|
||||
} else {
|
||||
if authInfo.AuthBindInfo.Type != AuthTypeTiktokMini {
|
||||
// return "", ErrAuthTypeShouldBeMini
|
||||
}
|
||||
sessionKey = authInfo.AuthBindInfo.UserData.(string)
|
||||
}
|
||||
decryptedData, err := weixinapi.SNSDecodeMiniProgramData(encryptedData, sessionKey, iv)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return string(decryptedData), nil
|
||||
}
|
||||
|
||||
func (a *TiktopMiniAuther) GetUserType() (userType int8) {
|
||||
return model.UserTypeStoreBoss
|
||||
}
|
||||
|
||||
func getWxApp(appID string) (miniApi *weixinapi.API) {
|
||||
miniApi = api.WeixinMiniAPI
|
||||
if len(appID) > 0 && appID == api.WeixinMiniAppID2 {
|
||||
miniApi = api.WeixinMiniAPI2
|
||||
}
|
||||
if len(appID) > 0 && appID == api.WeixinMiniAppIDsc {
|
||||
miniApi = api.WeixinMiniAPIsc
|
||||
}
|
||||
return miniApi
|
||||
}
|
||||
Reference in New Issue
Block a user