wxapp login

This commit is contained in:
richboo111
2022-12-01 11:22:46 +08:00
parent 874d2ffc76
commit 3e3c623ebc
3 changed files with 38 additions and 3 deletions

View File

@@ -5,6 +5,7 @@ import (
"encoding/base64" "encoding/base64"
"encoding/json" "encoding/json"
"errors" "errors"
"git.rosy.net.cn/jx-callback/globals"
"regexp" "regexp"
"strings" "strings"
"time" "time"
@@ -36,6 +37,8 @@ const (
AuthTypePassword = "localpass" AuthTypePassword = "localpass"
AuthTypeEmail = "email" AuthTypeEmail = "email"
AuthTypeMobile = "mobile" AuthTypeMobile = "mobile"
AuthTypeWXApp = "weixinapp" //微信小程序
AuthTypeWXMini = "weixinmini" //微信小程序
) )
const ( const (
@@ -280,8 +283,9 @@ func LoginInternal(ctx *Context, authType, authID, authIDType, authSecret string
userProvider.UpdateLastLogin(user.GetID(), authType, ctx.GetRealRemoteIP()) userProvider.UpdateLastLogin(user.GetID(), authType, ctx.GetRealRemoteIP())
} }
//如果是小程序 //如果是小程序
if authType == "weixinmini" || authType == "weixinapp" { if authType == AuthTypeWXMini { // || authType == AuthTypeWXApp 此处AuthTypeWXApp没用上
appID := strings.Split(authSecret, ",")[0] 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 appID == model.JXC4BusinessAppId || appID == "wx2d6949f724b2541d" || appID == "wx18111a41fd17f24f" || appID == model.JXC4AppId { //菜市或者果园
if authInfo.AuthBindInfo.UserID != "" { 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 { } else {

View File

@@ -70,6 +70,18 @@ func (a *Auther) VerifySecret(id, secret string) (authBindEx *auth2.AuthBindEx,
} else { } else {
err = ErrStateIsWrong 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 { } else {
openID = id openID = id
accessToken = secret accessToken = secret

View File

@@ -533,7 +533,10 @@ func IsWaybillFinalStatus(status int) bool {
} }
const ( const (
JXC4AppId = "wx4b5930c13f8b1170" // 京西菜市appId JXC4AppId = "wx4b5930c13f8b1170" // 京西菜市appId type=weixinmini
JXC4BusinessAppId = "wx08a5c2a8581414ff" // 京西商家appId JXC4BusinessAppId = "wx08a5c2a8581414ff" // 京西商家appId type=weixinmini
JXC4TiktokAppId = "tta6a1d01c399f264201" // 抖音appID JXC4TiktokAppId = "tta6a1d01c399f264201" // 抖音appID
JXC4ClientAppID = "wxf3657c94aa01a3f0" //京西菜市客户端APP ID type="weixinapp"
) )