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
@@ -155,6 +155,11 @@ type updateProfileRequest struct {
AvatarURL string `json:"avatar_url"`
}
type miniProgramCodeQuery struct {
Path string `form:"path"`
Width int `form:"width"`
}
func (h *AuthHandler) UpdateProfile(c *gin.Context) {
user := middleware.MustCurrentUser(c)
@@ -181,3 +186,23 @@ func (h *AuthHandler) UpdateProfile(c *gin.Context) {
"avatar_url": updated.AvatarURL,
}))
}
func (h *AuthHandler) GetMiniProgramTestCode(c *gin.Context) {
user := middleware.MustCurrentUser(c)
var query miniProgramCodeQuery
if err := c.ShouldBindQuery(&query); err != nil {
c.JSON(http.StatusBadRequest, model.Error(http.StatusBadRequest, "参数错误"))
return
}
codeBytes, err := h.authService.GetMiniProgramTestCode(c.Request.Context(), user.ID, query.Path, query.Width)
if err != nil {
log.Printf("[get_mini_program_test_code] error: %v", err)
c.JSON(http.StatusInternalServerError, model.Error(http.StatusInternalServerError, "获取小程序码失败"))
return
}
c.Header("Cache-Control", "no-store")
c.Data(http.StatusOK, "image/png", codeBytes)
}