This commit is contained in:
邹宗楠
2022-08-15 16:24:41 +08:00
parent 949dd96a0a
commit be87623211
15 changed files with 321 additions and 103 deletions

View File

@@ -16,15 +16,15 @@ var Auth2ControllerController = new(Auth2Controller)
// Login 登录接口
// @Title 登录接口
// @Description 登录接口(微信与公众号登录不能直接调用此接口)
// @Param data body app_model.WeChatPhoneNumberParam true "请求参数"
// @Param data body app_model.WxLoginReq true "请求参数"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /Login [post]
// @router /login [post]
func (a *Auth2Controller) Login(c *gin.Context) {
// 参数绑定
var (
err error
params *app_model.WeChatPhoneNumberParam
params *app_model.WxLoginReq
service = app_server.UserLogin{}
)
@@ -51,6 +51,44 @@ func (a *Auth2Controller) Login(c *gin.Context) {
})
}
// Login4Mobile 登录接口验证码登录
// @Title 登录接口验证码登录
// @Description 登录接口(验证码登录)
// @Param data body app_model.MobileLogin true "请求参数"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /loginMobile [post]
func (a *Auth2Controller) Login4Mobile(c *gin.Context) {
// 参数绑定
var (
err error
params *app_model.MobileLogin
service = app_server.UserLogin{}
)
if err = c.ShouldBind(&params); err != nil {
c.JSON(http.StatusOK, &model.CallBack{
Code: model.ErrCodeNormal,
Desc: err.Error(),
})
return
}
controllers.CallFunc(c, func() (retVal interface{}, errCode string, err error) {
user, err := service.MobileLogin(c, params)
if err != nil {
return nil, "", err
}
// 获取token
token, err := controllers.SetToken(user)
if err != nil {
return nil, "", err
}
return map[string]interface{}{"token": token, "user": user}, "", nil
})
}
// GetUserPhoneByWeChat 获取用户电话号码
// @Title 获取用户电话号码
// @Description 获取用户电话号码
@@ -75,12 +113,12 @@ func (a *Auth2Controller) GetUserPhoneByWeChat(c *gin.Context) {
}
controllers.CallFunc(c, func() (retVal interface{}, errCode string, err error) {
phone, err := service.GetUserPhoneNum(params)
phone, isRegister, err := service.GetUserPhoneNum(params)
if err != nil {
return nil, "", err
}
return map[string]interface{}{"phone": phone}, "", nil
return map[string]interface{}{"phone": phone, "isRegister": isRegister}, "", nil
})
}