resetAppSecretLogic.go 993 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package logic
  2. import (
  3. "GtDataStore/common/crypto/md5"
  4. "context"
  5. "fmt"
  6. "GtDataStore/app/cmd/organization/internal/svc"
  7. "GtDataStore/app/cmd/organization/pb"
  8. "github.com/zeromicro/go-zero/core/logx"
  9. )
  10. type ResetAppSecretLogic struct {
  11. ctx context.Context
  12. svcCtx *svc.ServiceContext
  13. logx.Logger
  14. }
  15. func NewResetAppSecretLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ResetAppSecretLogic {
  16. return &ResetAppSecretLogic{
  17. ctx: ctx,
  18. svcCtx: svcCtx,
  19. Logger: logx.WithContext(ctx),
  20. }
  21. }
  22. func (l *ResetAppSecretLogic) ResetAppSecret(in *pb.ResetAppSecretReq) (*pb.ResetAppSecretResp, error) {
  23. appInfo, err := l.svcCtx.AppInfo.FindOneByAppName(l.ctx, in.AppName)
  24. if err != nil {
  25. return nil, err
  26. }
  27. appInfo.Secret = md5.Md5([]byte(fmt.Sprintf("%s_%d:%d", in.AppName, appInfo.Status, appInfo.ExpireAt.UnixMilli())))
  28. err = l.svcCtx.AppInfo.Update(l.ctx, appInfo)
  29. if err != nil {
  30. return nil, err
  31. }
  32. return &pb.ResetAppSecretResp{Secret: appInfo.Secret}, nil
  33. }