新增抖音授权登录,添加定时任务,更新[配送中的订单骑手位置!
This commit is contained in:
@@ -417,8 +417,6 @@ func ClearUserToken(userID string) {
|
||||
}
|
||||
}
|
||||
|
||||
/////////////
|
||||
|
||||
func createToken(user IUser, authBindInfo *AuthBindEx) (token string, tokenType int) {
|
||||
userID := TokenUserEmpty
|
||||
userName := authBindInfo.AuthID
|
||||
|
||||
@@ -80,9 +80,9 @@ func (a *DefAuther) UnionFindAuthBind(curAuthType, curAuthTypeID string, unionAu
|
||||
dao.UpdateEntity(db, authBind, "TypeID")
|
||||
}
|
||||
} else if dao.IsNoRowsError(err) { // 直接找不到,尝试unionID
|
||||
if unionID != "" { // 且有unionID
|
||||
if unionID != "" || openID != "" { // 且有unionID
|
||||
var authBindList []*model.AuthBind
|
||||
if authBindList, err = dao.GetUserBindAuthInfo(db, "", model.AuthBindTypeAuth, unionAuthTypeList, "", unionID, nil); err == nil && len(authBindList) > 0 { // 通过unionID找到至少一个认证方式
|
||||
if authBindList, err = dao.GetUserBindAuthInfo(db, "", model.AuthBindTypeAuth, unionAuthTypeList, openID, unionID, nil); err == nil && len(authBindList) > 0 { // 通过unionID找到至少一个认证方式
|
||||
authBind = authBindList[0]
|
||||
authBind.Type = curAuthType
|
||||
authBind.TypeID = curAuthTypeID
|
||||
|
||||
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
|
||||
}
|
||||
@@ -94,6 +94,9 @@ func getWxApp(appID string) (miniApi *weixinapi.API) {
|
||||
if len(appID) > 0 && appID == api.WeixinMiniAppIDsc {
|
||||
miniApi = api.WeixinMiniAPIsc
|
||||
}
|
||||
if len(appID) > 0 && appID == api.WeixinMiniPrintAppId {
|
||||
miniApi = api.WeixinMiniAPIPrint
|
||||
}
|
||||
return miniApi
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user