feat(auth): add mini program test code endpoint (#51)
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user