From 128d719a9c521e6ce1deac69b5c83620efcb0834 Mon Sep 17 00:00:00 2001 From: gazebo Date: Fri, 8 Nov 2019 18:25:46 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9MiniDecryptData=E4=B8=AD?= =?UTF-8?q?=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/auth2/authprovider/weixin/weixin_mini.go | 3 +-- controllers/auth2.go | 15 ++++++++++----- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/business/auth2/authprovider/weixin/weixin_mini.go b/business/auth2/authprovider/weixin/weixin_mini.go index e9bb9825a..bd95fb882 100644 --- a/business/auth2/authprovider/weixin/weixin_mini.go +++ b/business/auth2/authprovider/weixin/weixin_mini.go @@ -1,7 +1,6 @@ package weixin import ( - "encoding/base64" "errors" "strings" @@ -55,7 +54,7 @@ func (a *MiniAuther) DecryptData(authInfo *auth2.AuthInfo, encryptedData, iv str if err != nil { return "", err } - return base64.StdEncoding.EncodeToString(decryptedData), nil + return string(decryptedData), nil } func (a *MiniAuther) GetUserType() (userType int8) { diff --git a/controllers/auth2.go b/controllers/auth2.go index 92e207fe5..da3e17101 100644 --- a/controllers/auth2.go +++ b/controllers/auth2.go @@ -6,6 +6,7 @@ import ( "net/http" "strings" + "git.rosy.net.cn/baseapi/platformapi/weixinapi" "git.rosy.net.cn/baseapi/utils" "git.rosy.net.cn/jx-callback/business/auth2" "git.rosy.net.cn/jx-callback/business/auth2/authprovider/dingding" @@ -13,9 +14,9 @@ import ( "git.rosy.net.cn/jx-callback/business/auth2/authprovider/password" "git.rosy.net.cn/jx-callback/business/auth2/authprovider/weixin" "git.rosy.net.cn/jx-callback/business/model" + "git.rosy.net.cn/jx-callback/business/model/dao" "git.rosy.net.cn/jx-callback/globals" "github.com/astaxie/beego" - "git.rosy.net.cn/jx-callback/business/model/dao" ) func GetComposedCode(c *beego.Controller, code string) (composedCode string) { @@ -309,10 +310,14 @@ func (c *Auth2Controller) MiniDecryptData() { c.callMiniDecryptData(func(params *tAuth2MiniDecryptDataParams) (retVal interface{}, errCode string, err error) { authInfo, err := params.Ctx.GetV2AuthInfo() if err == nil { - if retVal, err = weixin.AutherObjMini.DecryptData(authInfo, params.Data, params.Iv); err == nil { - if user:= params.Ctx.GetFullUser(); user != nil { - user.Avatar = "avatar" - dao.UpdateEntity(dao.GetDB(), user, "Avatar") + decryptedDataBase64, err2 := weixin.AutherObjMini.DecryptData(authInfo, params.Data, params.Iv) + if err = err2; err == nil { + var userInfo *weixinapi.MiniUserInfo + if err = utils.UnmarshalUseNumber([]byte(decryptedDataBase64), &userInfo); err == nil { + if user := params.Ctx.GetFullUser(); user != nil { + user.Avatar = userInfo.AvatarURL + dao.UpdateEntity(dao.GetDB(), user, "Avatar") + } } } }