This commit is contained in:
邹宗楠
2023-01-31 10:27:15 +08:00
parent c3c7c7ddbd
commit 0f45dee310
8 changed files with 44 additions and 32 deletions

View File

@@ -33,12 +33,13 @@ const (
)
const (
AuthTypeNone = ""
AuthTypePassword = "localpass"
AuthTypeEmail = "email"
AuthTypeMobile = "mobile"
AuthTypeWXApp = "weixinapp" //微信小程序
AuthTypeWXMini = "weixinmini" //微信小程序
AuthTypeNone = ""
AuthTypePassword = "localpass"
AuthTypeEmail = "email"
AuthTypeMobile = "mobile"
AuthTypeWXApp = "weixinapp" //微信小程序(商家版)
AuthTypeWXAppCaishi = "weixinappcs" //微信小程序(用户)
AuthTypeWXMini = "weixinmini" //微信小程序
)
const (
@@ -305,7 +306,7 @@ func LoginInternal(ctx *Context, authType, authID, authIDType, authSecret string
}
}
//微信APP端登录
if authType == AuthTypeWXApp {
if authType == AuthTypeWXApp || authType == AuthTypeWXAppCaishi {
appID := strings.Split(authSecret, ",")[0]
if appID == model.JXC4ClientAppID && authInfo.AuthBindInfo.UserID != "" {
binds, err := dao.GetUserBindAuthInfo(dao.GetDB(), authInfo.AuthBindInfo.UserID, 0, nil, "", "", []string{model.JXC4ClientAppID})

View File

@@ -2,9 +2,6 @@ package weixin
import (
"errors"
"git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-callback/globals"
"git.rosy.net.cn/baseapi/platformapi/weixinapi"
"git.rosy.net.cn/jx-callback/business/auth2"
"git.rosy.net.cn/jx-callback/business/auth2/authprovider"
@@ -13,10 +10,11 @@ import (
)
const (
AuthTypeWeixin = "wxqrcode" // 微信扫码
AuthTypeMP = "weixinsns" // 公众号
AuthTypeWXNative = "wxnative" // 微信APP
AuthTypeWxApp = "weixinapp" //app微信登录()
AuthTypeWeixin = "wxqrcode" // 微信扫码
AuthTypeMP = "weixinsns" // 公众号
AuthTypeWXNative = "wxnative" // 微信APP
AuthTypeWxApp = "weixinapp" //app微信登录(商家版)
AuthTypeWxAppCaishi = "weixinappcs" //app微信登录(用户版)
)
type Auther struct {
@@ -25,10 +23,11 @@ type Auther struct {
}
var (
AutherObjWX *Auther
AutherObjMP *Auther
AutherObjNative *Auther
AutherObjApp *Auther
AutherObjWX *Auther
AutherObjMP *Auther
AutherObjNative *Auther
AutherObjApp *Auther
AutherObjCaiShiApp *Auther
)
var (
@@ -55,14 +54,16 @@ func init() {
authType: AuthTypeWxApp,
}
auth2.RegisterAuther(AuthTypeWxApp, AutherObjApp)
AutherObjCaiShiApp = &Auther{
authType: AuthTypeWxAppCaishi,
}
auth2.RegisterAuther(AuthTypeWxAppCaishi, AutherObjCaiShiApp)
}
func (a *Auther) VerifySecret(id, secret string) (authBindEx *auth2.AuthBindEx, err error) {
var openID, accessToken string
appId, jsCode := SplitJsCode(secret)
globals.SugarLogger.Debugf("=======appId := %s ,jscode := %s", appId, jsCode)
globals.SugarLogger.Debugf("auther := %s", utils.Format4Output(a.authType, false))
globals.SugarLogger.Debugf("auther := %s", utils.Format4Output(a.DefAuther, false))
_, jsCode := SplitJsCode(secret)
if a.authType != AuthTypeWXNative {
state := id
code := jsCode
@@ -94,7 +95,7 @@ func (a *Auther) VerifySecret(id, secret string) (authBindEx *auth2.AuthBindEx,
if err == nil {
wxUserinfo, err2 := a.getAPI().SNSGetUserInfo(accessToken, openID)
if err = err2; err == nil {
if authBindEx, err = a.UnionFindAuthBind(a.authType, a.getAPI().GetAppID(), []string{AuthTypeWeixin, AuthTypeMP, AuthTypeMini, AuthTypeWXNative, AuthTypeWxApp}, wxUserinfo.OpenID, wxUserinfo.UnionID, wxUserinfo); err == nil {
if authBindEx, err = a.UnionFindAuthBind(a.authType, a.getAPI().GetAppID(), []string{AuthTypeWeixin, AuthTypeMP, AuthTypeMini, AuthTypeWXNative, AuthTypeWxApp, AuthTypeWxAppCaishi}, wxUserinfo.OpenID, wxUserinfo.UnionID, wxUserinfo); err == nil {
authBindEx.UserHint = &auth2.UserBasic{
Name: wxUserinfo.NickName,
Avatar: wxUserinfo.HeadImgURL,
@@ -112,6 +113,9 @@ func (a *Auther) getAPI() *weixinapi.API {
if a.authType == AuthTypeWxApp {
return api.WeixinApp
}
if a.authType == AuthTypeWxAppCaishi {
return api.WeixinApp2
}
return api.WeixinAPI
}

View File

@@ -3526,7 +3526,7 @@ func GetStoreCategoryMap(ctx *jxcontext.Context, parentID, level int, storeID in
if err != nil {
return nil, err
}
if ctx.GetLoginType() != weixin.AuthTypeMP && ctx.GetLoginType() != weixin.AuthTypeMini && ctx.GetLoginType() != weixin.AuthTypeWxApp && ctx.GetLoginType() != auth2.AuthTypeMobile {
if ctx.GetLoginType() != weixin.AuthTypeMP && ctx.GetLoginType() != weixin.AuthTypeMini && ctx.GetLoginType() != weixin.AuthTypeWxApp && ctx.GetLoginType() != weixin.AuthTypeWxAppCaishi && ctx.GetLoginType() != auth2.AuthTypeMobile {
return storeCatMaps, err
}
//表示没有门店分类
@@ -3542,7 +3542,7 @@ func GetStoreCategoryMapNoDefault(ctx *jxcontext.Context, parentID, level int, s
if err != nil {
return nil, err
}
if ctx.GetLoginType() != weixin.AuthTypeMP && ctx.GetLoginType() != weixin.AuthTypeMini && ctx.GetLoginType() != weixin.AuthTypeWxApp && ctx.GetLoginType() != auth2.AuthTypeMobile {
if ctx.GetLoginType() != weixin.AuthTypeMP && ctx.GetLoginType() != weixin.AuthTypeMini && ctx.GetLoginType() != weixin.AuthTypeWxApp && ctx.GetLoginType() != weixin.AuthTypeWxAppCaishi && ctx.GetLoginType() != auth2.AuthTypeMobile {
return storeCatMaps, err
}
return storeCatMaps, err
@@ -5512,7 +5512,7 @@ func GetBrandCategoryMap(ctx *jxcontext.Context, parentID, level int, brandID in
if err != nil {
return nil, err
}
if ctx.GetLoginType() != weixin.AuthTypeMP && ctx.GetLoginType() != weixin.AuthTypeMini && ctx.GetLoginType() != weixin.AuthTypeWxApp && ctx.GetLoginType() != auth2.AuthTypeMobile {
if ctx.GetLoginType() != weixin.AuthTypeMP && ctx.GetLoginType() != weixin.AuthTypeMini && ctx.GetLoginType() != weixin.AuthTypeWxApp && ctx.GetLoginType() != weixin.AuthTypeWxAppCaishi && ctx.GetLoginType() != auth2.AuthTypeMobile {
return brandCatMaps, err
}
return brandCatMaps, err

View File

@@ -5896,7 +5896,7 @@ func doStoreSkuAudit(ctx *jxcontext.Context, storeIDs []int, skuBindInfos []*Sto
return false, err
}
if ctx.GetLoginType() != weixin.AuthTypeMP && ctx.GetLoginType() != weixin.AuthTypeMini && ctx.GetLoginType() != weixin.AuthTypeWxApp && ctx.GetLoginType() != auth2.AuthTypeMobile {
if ctx.GetLoginType() != weixin.AuthTypeMP && ctx.GetLoginType() != weixin.AuthTypeMini && ctx.GetLoginType() != weixin.AuthTypeWxApp && ctx.GetLoginType() != weixin.AuthTypeWxAppCaishi && ctx.GetLoginType() != auth2.AuthTypeMobile {
authInfo, err := ctx.GetV2AuthInfo()
if err == nil && authInfo != nil && (ctx.GetFullUser().Type&model.UserTypeOperator) != 0 {
if len(storeAudits) > 0 {
@@ -5974,7 +5974,7 @@ func doStoreSkuAuditForGy(ctx *jxcontext.Context, storeIDs []int, skuBindInfos [
return false, err
}
if ctx.GetLoginType() != weixin.AuthTypeMP && ctx.GetLoginType() != weixin.AuthTypeMini && ctx.GetLoginType() != weixin.AuthTypeWxApp && ctx.GetLoginType() != auth2.AuthTypeMobile {
if ctx.GetLoginType() != weixin.AuthTypeMP && ctx.GetLoginType() != weixin.AuthTypeMini && ctx.GetLoginType() != weixin.AuthTypeWxApp && ctx.GetLoginType() != weixin.AuthTypeWxAppCaishi && ctx.GetLoginType() != auth2.AuthTypeMobile {
authInfo, err := ctx.GetV2AuthInfo()
if err == nil && authInfo != nil && (ctx.GetFullUser().Type&model.UserTypeOperator) != 0 {
if len(storeAudits) > 0 {

View File

@@ -504,7 +504,7 @@ func GetMyStoreListNew(ctx *jxcontext.Context, version string) (storesInfo inter
if !auth2.IsV2Token(ctx.GetToken()) {
return nil, model.ErrCodeTokenIsInvalid, model.ErrTokenIsInvalid
}
if ctx.GetLoginType() == weixin.AuthTypeWxApp {
if ctx.GetLoginType() == weixin.AuthTypeWxApp || ctx.GetLoginType() == weixin.AuthTypeWxAppCaishi {
if configs, _ := dao.QueryConfigs(dao.GetDB(), "checkversion", model.ConfigTypeSys, ""); len(configs) > 0 {
if version == "" || configs[0].Value != version {
return nil, "", fmt.Errorf("当前APP版本过旧数据显示有错误请到'京西菜市'公众号下载最新版本APP")