get_gpts_user_info_logic.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package User
  2. import (
  3. "context"
  4. "github.com/suyuan32/simple-admin-core/rpc/types/core"
  5. "github.com/zeromicro/go-zero/core/errorx"
  6. "wechat-api/internal/svc"
  7. "wechat-api/internal/types"
  8. jwtutils "wechat-api/internal/utils/jwt"
  9. "github.com/zeromicro/go-zero/core/logx"
  10. )
  11. type GetGptsUserInfoLogic struct {
  12. logx.Logger
  13. ctx context.Context
  14. svcCtx *svc.ServiceContext
  15. }
  16. func NewGetGptsUserInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetGptsUserInfoLogic {
  17. return &GetGptsUserInfoLogic{
  18. Logger: logx.WithContext(ctx),
  19. ctx: ctx,
  20. svcCtx: svcCtx}
  21. }
  22. func (l *GetGptsUserInfoLogic) GetGptsUserInfo(tokenStr string) (*types.UserInfoResp, error) {
  23. resp := types.UserInfoResp{}
  24. claims, err := jwtutils.ParseJwtToken(l.svcCtx.Config.Auth.AccessSecret, tokenStr)
  25. if err != nil {
  26. return nil, errorx.NewInvalidArgumentError("用户未登录")
  27. }
  28. userId := claims["userId"].(string)
  29. departmentId := claims["deptId"].(float64)
  30. if userId == "" || departmentId != float64(15) {
  31. return nil, errorx.NewInvalidArgumentError("用户需要登录")
  32. }
  33. userInfo, _ := l.svcCtx.CoreRpc.GetUserById(l.ctx, &core.UUIDReq{Id: userId})
  34. //department, _ := l.svcCtx.CoreRpc.GetDepartmentById(l.ctx, &core.IDReq{Id: uint64(departmentId)})
  35. //resp.Data = fmt.Sprintf("userId=%v departmentId=%v departmentName=%v ", userId, departmentId, *department.Name)
  36. resp.Data.Username = userInfo.Username
  37. resp.Data.Nickname = userInfo.Nickname
  38. resp.Data.Id = &userId
  39. resp.Data.Status = userInfo.Status
  40. return &resp, nil
  41. }