优化工作-1

This commit is contained in:
yml2213
2026-06-05 07:41:52 +08:00
parent b7ec5e2755
commit 0b9b0b5ea7
17 changed files with 1807 additions and 127 deletions
+43
View File
@@ -31,6 +31,17 @@ func NewHandler(service *Service) *Handler {
return &Handler{service: service}
}
// SendSMS 发送短信验证码
// @Summary 发送短信验证码
// @Description 发送登录验证码到指定手机号
// @Tags 认证
// @Accept json
// @Produce json
// @Param request body SendSMSRequest true "手机号"
// @Success 200 {object} response.Body "发送成功"
// @Failure 400 {object} response.Body "请求参数错误"
// @Failure 500 {object} response.Body "服务器错误"
// @Router /auth/sms/send [post]
func (h *Handler) SendSMS(c *gin.Context) {
var req SendSMSRequest
if err := c.ShouldBindJSON(&req); err != nil {
@@ -44,6 +55,18 @@ func (h *Handler) SendSMS(c *gin.Context) {
response.OK(c, gin.H{"phone": PublicPhone(req.Phone), "expires_in": 300})
}
// Login 短信验证码登录
// @Summary 短信验证码登录
// @Description 使用手机号和验证码登录
// @Tags 认证
// @Accept json
// @Produce json
// @Param request body LoginRequest true "登录信息"
// @Success 200 {object} response.Body "登录成功,返回用户信息和 token"
// @Failure 400 {object} response.Body "请求参数错误"
// @Failure 401 {object} response.Body "验证码错误"
// @Failure 500 {object} response.Body "服务器错误"
// @Router /auth/sms/login [post]
func (h *Handler) Login(c *gin.Context) {
var req LoginRequest
if err := c.ShouldBindJSON(&req); err != nil {
@@ -58,6 +81,17 @@ func (h *Handler) Login(c *gin.Context) {
response.OK(c, result)
}
// Refresh 刷新访问令牌
// @Summary 刷新访问令牌
// @Description 使用 refresh_token 获取新的 access_token
// @Tags 认证
// @Accept json
// @Produce json
// @Param request body RefreshRequest true "刷新令牌"
// @Success 200 {object} response.Body "刷新成功,返回新的 token"
// @Failure 400 {object} response.Body "请求参数错误"
// @Failure 401 {object} response.Body "refresh_token 无效"
// @Router /auth/refresh [post]
func (h *Handler) Refresh(c *gin.Context) {
var req RefreshRequest
if err := c.ShouldBindJSON(&req); err != nil {
@@ -72,6 +106,15 @@ func (h *Handler) Refresh(c *gin.Context) {
response.OK(c, tokens)
}
// Logout 登出
// @Summary 登出
// @Description 用户登出(客户端需清除本地 token)
// @Tags 认证
// @Accept json
// @Produce json
// @Success 200 {object} response.Body "登出成功"
// @Security BearerAuth
// @Router /auth/logout [post]
func (h *Handler) Logout(c *gin.Context) {
response.OK(c, gin.H{"logged_out": true})
}