去掉ProxySNSxx函数,添加getWxApp
This commit is contained in:
@@ -37,7 +37,8 @@ func init() {
|
|||||||
func (a *MiniAuther) VerifySecret(dummy, jsCode string) (authBindEx *auth2.AuthBindEx, err error) {
|
func (a *MiniAuther) VerifySecret(dummy, jsCode string) (authBindEx *auth2.AuthBindEx, err error) {
|
||||||
globals.SugarLogger.Debugf("weixin mini VerifySecret jsCode:%s", jsCode)
|
globals.SugarLogger.Debugf("weixin mini VerifySecret jsCode:%s", jsCode)
|
||||||
|
|
||||||
sessionInfo, err := ProxySNSCode2Session(jsCode)
|
appID, jsCode := SplitJsCode(jsCode)
|
||||||
|
sessionInfo, err := getWxApp(appID).SNSCode2Session(jsCode)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
sessionKey := sessionInfo.SessionKey
|
sessionKey := sessionInfo.SessionKey
|
||||||
sessionInfo.SessionKey = ""
|
sessionInfo.SessionKey = ""
|
||||||
@@ -52,8 +53,9 @@ func (a *MiniAuther) VerifySecret(dummy, jsCode string) (authBindEx *auth2.AuthB
|
|||||||
func (a *MiniAuther) DecryptData(authInfo *auth2.AuthInfo, jsCode, encryptedData, iv string) (decryptedDataBase64 string, err error) {
|
func (a *MiniAuther) 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)
|
globals.SugarLogger.Debugf("weixin mini DecryptData jsCode:%s, encryptedData:%s, iv:%s", jsCode, encryptedData, iv)
|
||||||
var sessionKey string
|
var sessionKey string
|
||||||
|
appID, jsCode := SplitJsCode(jsCode)
|
||||||
if jsCode != "" {
|
if jsCode != "" {
|
||||||
sessionInfo, err := ProxySNSCode2Session(jsCode)
|
sessionInfo, err := getWxApp(appID).SNSCode2Session(jsCode)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
if authBindEx, err := a.UnionFindAuthBind(AuthTypeMini, []string{AuthTypeMini}, sessionInfo.OpenID, "", nil); err == nil {
|
if authBindEx, err := a.UnionFindAuthBind(AuthTypeMini, []string{AuthTypeMini}, sessionInfo.OpenID, "", nil); err == nil {
|
||||||
if authBindEx.UserID != authInfo.GetID() {
|
if authBindEx.UserID != authInfo.GetID() {
|
||||||
@@ -72,7 +74,8 @@ func (a *MiniAuther) DecryptData(authInfo *auth2.AuthInfo, jsCode, encryptedData
|
|||||||
}
|
}
|
||||||
sessionKey = authInfo.AuthBindInfo.UserData.(string)
|
sessionKey = authInfo.AuthBindInfo.UserData.(string)
|
||||||
}
|
}
|
||||||
decryptedData, err := ProxySNSDecodeMiniProgramData(encryptedData, sessionKey, iv)
|
// decryptedData, err := ProxySNSDecodeMiniProgramData(encryptedData, sessionKey, iv)
|
||||||
|
decryptedData, err := weixinapi.SNSDecodeMiniProgramData(encryptedData, sessionKey, iv)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
@@ -84,21 +87,51 @@ func (a *MiniAuther) GetUserType() (userType int8) {
|
|||||||
return model.UserTypeStoreBoss
|
return model.UserTypeStoreBoss
|
||||||
}
|
}
|
||||||
|
|
||||||
func ProxySNSCode2Session(jsCode string) (sessionInfo *weixinapi.SessionInfo, err error) {
|
func getWxApp(appID string) (miniApi *weixinapi.API) {
|
||||||
miniApi := api.WeixinMiniAPI
|
miniApi = api.WeixinMiniAPI
|
||||||
list := strings.Split(jsCode, ",")
|
if len(appID) > 0 && appID == api.WeixinMiniAppID2 {
|
||||||
if len(list) >= 2 && len(list[0]) == len("wx4b5930c13f8b1170") {
|
miniApi = api.WeixinMiniAPI2
|
||||||
if list[0] == api.WeixinMiniAppID2 {
|
|
||||||
miniApi = api.WeixinMiniAPI2
|
|
||||||
}
|
|
||||||
jsCode = strings.Join(list[1:], ",")
|
|
||||||
}
|
}
|
||||||
sessionInfo, err = miniApi.SNSCode2Session(jsCode)
|
return miniApi
|
||||||
return sessionInfo, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func ProxySNSDecodeMiniProgramData(encryptedData, sessionKey, iv string) (decryptedData []byte, err error) {
|
func SplitJsCode(jsCode string) (appID, realJsCode string) {
|
||||||
globals.SugarLogger.Debugf("ProxySNSDecodeMiniProgramData, encryptedData:%s, sessionKey:%s, iv:%s", encryptedData, sessionKey, iv)
|
list := strings.Split(jsCode, ",")
|
||||||
decryptedData, err = api.WeixinMiniAPI.SNSDecodeMiniProgramData(encryptedData, sessionKey, iv)
|
if len(list) == 2 {
|
||||||
return decryptedData, err
|
appID = list[0]
|
||||||
|
realJsCode = list[1]
|
||||||
|
} else if len(list) == 1 {
|
||||||
|
realJsCode = jsCode
|
||||||
|
} else {
|
||||||
|
globals.SugarLogger.Warnf("SplitJsCode abnormal jsCode:%s", jsCode)
|
||||||
|
}
|
||||||
|
return appID, realJsCode
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ComposeJsCode(appID, jsCode string) (composedCode string) {
|
||||||
|
composedCode = strings.Join([]string{
|
||||||
|
appID,
|
||||||
|
jsCode,
|
||||||
|
}, ",")
|
||||||
|
return composedCode
|
||||||
|
}
|
||||||
|
|
||||||
|
// func ProxySNSCode2Session(jsCode string) (sessionInfo *weixinapi.SessionInfo, err error) {
|
||||||
|
// miniApi := api.WeixinMiniAPI
|
||||||
|
// list := strings.Split(jsCode, ",")
|
||||||
|
// if len(list) >= 2 && len(list[0]) == len("wx4b5930c13f8b1170") {
|
||||||
|
// if list[0] == api.WeixinMiniAppID2 {
|
||||||
|
// miniApi = api.WeixinMiniAPI2
|
||||||
|
// }
|
||||||
|
// miniApi = getWxApp(list[0])
|
||||||
|
// jsCode = strings.Join(list[1:], ",")
|
||||||
|
// }
|
||||||
|
// sessionInfo, err = miniApi.SNSCode2Session(jsCode)
|
||||||
|
// return sessionInfo, err
|
||||||
|
// }
|
||||||
|
|
||||||
|
// func ProxySNSDecodeMiniProgramData(encryptedData, sessionKey, iv string) (decryptedData []byte, err error) {
|
||||||
|
// globals.SugarLogger.Debugf("ProxySNSDecodeMiniProgramData, encryptedData:%s, sessionKey:%s, iv:%s", encryptedData, sessionKey, iv)
|
||||||
|
// decryptedData, err = api.WeixinMiniAPI.SNSDecodeMiniProgramData(encryptedData, sessionKey, iv)
|
||||||
|
// return decryptedData, err
|
||||||
|
// }
|
||||||
|
|||||||
@@ -18,19 +18,14 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func GetComposedCode(c *beego.Controller, code string) (composedCode string) {
|
func GetComposedCode(c *beego.Controller, code string) (composedCode string) {
|
||||||
if code != "" {
|
composedCode = code
|
||||||
composedCode = code
|
referer := c.Ctx.Request.Referer()
|
||||||
referer := c.Ctx.Request.Referer()
|
globals.SugarLogger.Debugf("GetComposedCode referer:%s", referer)
|
||||||
globals.SugarLogger.Debugf("GetComposedCode referer:%s", referer)
|
index := strings.Index(referer, "//")
|
||||||
index := strings.Index(referer, "//")
|
if index > 0 {
|
||||||
if index > 0 {
|
list := strings.Split(referer[index+2:], "/")
|
||||||
list := strings.Split(referer[index+2:], "/")
|
if len(list) >= 2 {
|
||||||
if len(list) >= 2 {
|
composedCode = weixin.ComposeJsCode(list[1], code)
|
||||||
composedCode = strings.Join([]string{
|
|
||||||
list[1],
|
|
||||||
code,
|
|
||||||
}, ",")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return composedCode
|
return composedCode
|
||||||
|
|||||||
Reference in New Issue
Block a user