wxapp login
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -36,6 +37,8 @@ const (
|
||||
AuthTypePassword = "localpass"
|
||||
AuthTypeEmail = "email"
|
||||
AuthTypeMobile = "mobile"
|
||||
AuthTypeWXApp = "weixinapp" //微信小程序
|
||||
AuthTypeWXMini = "weixinmini" //微信小程序
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -280,8 +283,9 @@ func LoginInternal(ctx *Context, authType, authID, authIDType, authSecret string
|
||||
userProvider.UpdateLastLogin(user.GetID(), authType, ctx.GetRealRemoteIP())
|
||||
}
|
||||
//如果是小程序
|
||||
if authType == "weixinmini" || authType == "weixinapp" {
|
||||
if authType == AuthTypeWXMini { // || authType == AuthTypeWXApp 此处AuthTypeWXApp没用上
|
||||
appID := strings.Split(authSecret, ",")[0]
|
||||
globals.SugarLogger.Debugf("authSecret=%s,appID=%s", authSecret, appID)
|
||||
// 菜市商家 // // // 京西商城
|
||||
if appID == model.JXC4BusinessAppId || appID == "wx2d6949f724b2541d" || appID == "wx18111a41fd17f24f" || appID == model.JXC4AppId { //菜市或者果园
|
||||
if authInfo.AuthBindInfo.UserID != "" {
|
||||
@@ -300,6 +304,22 @@ func LoginInternal(ctx *Context, authType, authID, authIDType, authSecret string
|
||||
}
|
||||
}
|
||||
}
|
||||
//微信APP端登录
|
||||
if authType == AuthTypeWXApp {
|
||||
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})
|
||||
if err != nil {
|
||||
return authInfo, err
|
||||
}
|
||||
if len(binds) == 0 {
|
||||
authInfo.IsExistOpenID = false
|
||||
} else {
|
||||
authInfo.IsExistOpenID = true
|
||||
}
|
||||
authInfo.AppID = model.JXC4ClientAppID
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -70,6 +70,18 @@ func (a *Auther) VerifySecret(id, secret string) (authBindEx *auth2.AuthBindEx,
|
||||
} else {
|
||||
err = ErrStateIsWrong
|
||||
}
|
||||
} else if a.authType == AuthTypeWxApp {
|
||||
state := id
|
||||
code := jsCode
|
||||
if state == "" {
|
||||
token, err2 := a.getAPI().SNSRetrieveToken(code)
|
||||
if err = err2; err == nil {
|
||||
openID = token.OpenID
|
||||
accessToken = token.AccessToken
|
||||
}
|
||||
} else {
|
||||
err = ErrStateIsWrong
|
||||
}
|
||||
} else {
|
||||
openID = id
|
||||
accessToken = secret
|
||||
|
||||
@@ -533,7 +533,10 @@ func IsWaybillFinalStatus(status int) bool {
|
||||
}
|
||||
|
||||
const (
|
||||
JXC4AppId = "wx4b5930c13f8b1170" // 京西菜市appId
|
||||
JXC4BusinessAppId = "wx08a5c2a8581414ff" // 京西商家appId
|
||||
JXC4AppId = "wx4b5930c13f8b1170" // 京西菜市appId type=weixinmini
|
||||
JXC4BusinessAppId = "wx08a5c2a8581414ff" // 京西商家appId type=weixinmini
|
||||
JXC4TiktokAppId = "tta6a1d01c399f264201" // 抖音appID
|
||||
|
||||
JXC4ClientAppID = "wxf3657c94aa01a3f0" //京西菜市客户端APP ID type="weixinapp"
|
||||
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user