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")

View File

@@ -38,12 +38,16 @@ func GetComposedCode2(c *web.Controller, code string) (composedCode string) {
composedCode = code
referer := c.Ctx.Request.UserAgent()
index := strings.Index(referer, "//")
globals.SugarLogger.Debugf("====GetComposedCode2==== %s", referer)
if index > 0 {
list := strings.Split(referer[index+2:], "/")
globals.SugarLogger.Debugf("====GetComposedCode2===list= %s", utils.Format4Output(list, false))
if len(list) >= 2 {
composedCode = weixin.ComposeJsCode(list[1], code)
}
}
globals.SugarLogger.Debugf("====composedCode===list= %s", utils.Format4Output(composedCode, false))
return composedCode
}
@@ -123,7 +127,7 @@ func (c *Auth2Controller) Login() {
if params.AuthType == weixin.AuthTypeMini {
params.AuthSecret = GetComposedCode(&c.Controller, params.AuthSecret)
}
if params.AuthType == weixin.AuthTypeWxApp {
if params.AuthType == weixin.AuthTypeWxApp || params.AuthType == weixin.AuthTypeWxAppCaishi {
//if configs, _ := dao.QueryConfigs(dao.GetDB(), "checkversion", model.ConfigTypeSys, ""); len(configs) > 0 {
// if params.Version == "" || configs[0].Value != params.Version {
// return nil, "", fmt.Errorf("当前APP版本过旧数据显示有错误请到'京西菜市'公众号下载最新版本APP")

View File

@@ -39,7 +39,7 @@ func (c *User2Controller) RegisterUser() {
)
if params.AuthToken != "" {
inAuthInfo, err = auth2.GetTokenInfo(params.AuthToken)
if inAuthInfo.AuthBindInfo.Type == weixin.AuthTypeWxApp {
if inAuthInfo.AuthBindInfo.Type == weixin.AuthTypeWxApp || inAuthInfo.AuthBindInfo.Type == weixin.AuthTypeWxAppCaishi {
if configs, _ := dao.QueryConfigs(dao.GetDB(), "checkversion", model.ConfigTypeSys, ""); len(configs) > 0 {
if params.Version == "" || configs[0].Value != params.Version {
return nil, "", fmt.Errorf("当前APP版本过旧数据显示有错误请到'京西菜市'公众号下载最新版本APP")

View File

@@ -80,7 +80,8 @@ var (
WeixinMiniAPI2 *weixinapi.API // 小程序2
WeixinMiniAPIsc *weixinapi.API //小程序商超
WeixinMiniAPIPrint *weixinapi.API //小程序打印机
WeixinApp *weixinapi.API // app微信登录
WeixinApp *weixinapi.API // app微信登录(商家端App微信授权)
WeixinApp2 *weixinapi.API // app微信登录(菜市端App微信授权)
WeixinMiniAppID2 string
WeixinMiniAppID3 string
WeixinMiniAppIDsc string
@@ -267,6 +268,8 @@ func Init() {
if WeixinMiniAppID3 = beego.AppConfig.DefaultString("weixinMiniAppID3", ""); WeixinMiniAppID3 != "" {
WeixinApp = weixinapi.New(WeixinMiniAppID3, beego.AppConfig.DefaultString("weixinMiniSecret3", ""))
}
WeixinApp2 = weixinapi.New("wxf3657c94aa01a3f0", "358b794343bfb48a32ccbf1d9052a30") // 暂时写死的
if WeixinMiniAppIDsc = beego.AppConfig.DefaultString("weixinMiniAppIDsc", ""); WeixinMiniAppIDsc != "" {
WeixinMiniAPIsc = weixinapi.New(WeixinMiniAppIDsc, beego.AppConfig.DefaultString("weixinMiniSecretsc", ""))
}