feat(auth): add mini program test code endpoint (#51)

This commit is contained in:
hello-dd-code
2026-04-11 01:49:18 +08:00
committed by GitHub
parent a6f0bfd4e8
commit 411ded8a0c
7 changed files with 228 additions and 15 deletions
@@ -265,3 +265,32 @@ func normalizeAvatarURL(raw string) string {
}
return text
}
func (s *AuthService) GetMiniProgramTestCode(ctx context.Context, userID uint, path string, width int) ([]byte, error) {
var user model.User
if err := s.db.WithContext(ctx).Select("id, mini_program_id").First(&user, userID).Error; err != nil {
return nil, fmt.Errorf("find user: %w", err)
}
if user.MiniProgramID == 0 {
return nil, fmt.Errorf("user mini program id missing")
}
miniProgram, err := s.miniProgramSvc.GetByID(ctx, user.MiniProgramID)
if err != nil {
return nil, fmt.Errorf("load mini program: %w", err)
}
if strings.TrimSpace(path) == "" {
path = "pages/nsti/test?resume=0"
}
if width <= 0 {
width = 280
}
client := s.getWeChatClient(miniProgram)
codeBytes, err := client.GetWXACode(ctx, path, width)
if err != nil {
return nil, fmt.Errorf("get mini program test code: %w", err)
}
return codeBytes, nil
}