From 3f5d0d7b2b4b84ec8ae017376170152c7ddf8702 Mon Sep 17 00:00:00 2001 From: denghui <1016848185@qq.com> Date: Wed, 11 Jun 2025 17:31:17 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=BE=AE=E4=BF=A1=E7=99=BB?= =?UTF-8?q?=E5=BD=95=20bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/controller/wx/wx_v1_we_chat_vertify.go | 5 ++++- internal/logic/user/user.go | 5 +++-- utility/wechat/wechat.go | 5 +++++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/internal/controller/wx/wx_v1_we_chat_vertify.go b/internal/controller/wx/wx_v1_we_chat_vertify.go index b75b138..1d96906 100644 --- a/internal/controller/wx/wx_v1_we_chat_vertify.go +++ b/internal/controller/wx/wx_v1_we_chat_vertify.go @@ -5,6 +5,7 @@ import ( "crypto/sha1" "fmt" "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/os/glog" "server/utility/wechat" "sort" "strings" @@ -17,15 +18,17 @@ func (c *ControllerV1) WeChatVertify(ctx context.Context, req *v1.WeChatVertifyR // 1. 排序 params := []string{wechat.GetWeChatClient().GetToken(), req.Timestamp, req.Nonce} sort.Strings(params) + glog.Infof(ctx, "排序后的参数: %s", params) // 2. 拼接成字符串 str := strings.Join(params, "") + glog.Infof(ctx, "拼接后的字符串: %s", str) // 3. SHA1 加密 h := sha1.New() h.Write([]byte(str)) sha1Str := fmt.Sprintf("%x", h.Sum(nil)) - + glog.Infof(ctx, "SHA1 加密后的字符串: %s", sha1Str) // 4. 比较签名 if sha1Str != req.Signature { return nil, fmt.Errorf("签名错误") diff --git a/internal/logic/user/user.go b/internal/logic/user/user.go index f9d3e6d..3ddb1dc 100644 --- a/internal/logic/user/user.go +++ b/internal/logic/user/user.go @@ -53,7 +53,7 @@ func New() service.IUser { } func (s *sUser) Login(ctx context.Context, in *model.UserLoginIn) (out *model.UserLoginOut, err error) { - value, err := dao.Roles.Ctx(ctx).Where(do.Roles{Code: consts.UserRoleCode}).Fields(dao.Roles.Columns().Code).Value() + value, err := dao.Roles.Ctx(ctx).Where(do.Roles{Code: consts.UserRoleCode}).Fields(dao.Roles.Columns().Code, dao.Roles.Columns().Id).One() if err != nil { return nil, ecode.Fail.Sub("查找角色失败") } @@ -93,6 +93,7 @@ func (s *sUser) Login(ctx context.Context, in *model.UserLoginIn) (out *model.Us LastLoginAt: gtime.Now(), WxPopenId: utility.GenerateUserID("WX"), QqPopenId: utility.GenerateUserID("QQ"), + RoleId: value[dao.Roles.Columns().Id].Int64(), } result, err := dao.Users.Ctx(ctx).Insert(user) if err != nil { @@ -117,7 +118,7 @@ func (s *sUser) Login(ctx context.Context, in *model.UserLoginIn) (out *model.Us // 生成 token token, err := jwt.GenerateToken(&jwt.TokenIn{ UserId: userId, - Role: value.String(), + Role: value[dao.Roles.Columns().Code].String(), }) if err != nil { return nil, ecode.Fail.Sub("生成token失败") diff --git a/utility/wechat/wechat.go b/utility/wechat/wechat.go index 28e1509..3970e5e 100644 --- a/utility/wechat/wechat.go +++ b/utility/wechat/wechat.go @@ -40,6 +40,7 @@ func init() { AppId: g.Config().MustGet(ctx, "wechat.appId").String(), AppSecret: g.Config().MustGet(ctx, "wechat.appSecret").String(), TicketExpire: g.Config().MustGet(ctx, "wechat.ticketExpire").Int(), + Token: g.Config().MustGet(ctx, "wechat.token").String(), } go instance.autoRefreshToken(ctx) @@ -168,3 +169,7 @@ func (c *weChatClient) GetQrCode(ticket string) (imagePath string, err error) { func (c *weChatClient) GetToken() string { return c.Token } + +func (c *weChatClient) GetUserUnionId(openid string) (unionId string, err error) { + return +}