user/biz/handle/auth.go
timerzz e7e3309896 优化Docker构建流程
- 添加UPX压缩步骤减小可执行文件体积
- 使用多阶段构建减小最终镜像大小
- 更新基础镜像到最新版本
2025-04-22 17:30:36 +08:00

46 lines
1.4 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package handle
import (
"context"
"github.com/cloudwego/hertz/pkg/app"
)
type LoginRequest struct {
WXCode string `json:"wx_code,omitempty"`
Phone string `json:"phone"`
Captcha string `json:"captcha,omitempty"`
Password string `json:"password,omitempty"`
}
type Response[T any] struct {
Code int `json:"code"`
Message string `json:"message"`
Data T `json:"data"`
}
type LoginResponse struct {
Token string `json:"token"`
Expire string `json:"expire"`
Message string `json:"message"`
Code int `json:"code"`
}
// Authenticator 登录
// @Tags 用户模块
// @Summary 登录接口
// @Description 如果是微信登录,需要传递 WXcode和手机号然后调用微信接口获取 openid 和 unionid。
// 如果 unionid 已经存在,就直接登录, 如果不存在,就注册。
// 如果是手机号登录,需要传递 phone 和 password 如果手机号没注册,就直接注册
// @Param request body LoginRequest true "请求参数"
// @Success 200 {object} LoginResponse "成功响应"
// @Accept application/json
// @Produce application/json
// @Router /api/v1/login [post]
func (h *UserHandler) Authenticator(ctx context.Context, c *app.RequestContext) (interface{}, error) {
var req LoginRequest
if err := c.BindJSON(&req); err != nil {
return nil, err
}
return h.userService.Login(ctx, req.Phone, req.Password, req.WXCode, req.Captcha)
}