Explorar el Código

一键登录

master
huangjiajun hace 1 semana
padre
commit
bd6c7a7c62
Se han modificado 9 ficheros con 490 adiciones y 110 borrados
  1. +43
    -7
      app/hdl/hdl_login.go
  2. +36
    -0
      app/hdl/hdl_user.go
  3. +4
    -0
      app/md/md_login.go
  4. +8
    -0
      app/md/md_user.go
  5. +6
    -4
      app/router/router.go
  6. +146
    -36
      docs/docs.go
  7. +144
    -33
      docs/swagger.json
  8. +102
    -29
      docs/swagger.yaml
  9. +1
    -1
      go.mod

+ 43
- 7
app/hdl/hdl_login.go Ver fichero

@@ -10,8 +10,8 @@ import (
"applet/app/utils/cache"
"code.fnuoos.com/EggPlanet/egg_models.git/src/implement"
"code.fnuoos.com/EggPlanet/egg_models.git/src/model"
"code.fnuoos.com/EggPlanet/egg_system_rules.git/aliyun"
"code.fnuoos.com/EggPlanet/egg_system_rules.git/enum"
"code.fnuoos.com/EggPlanet/egg_system_rules.git/sms"
"github.com/gin-gonic/gin"
"time"
)
@@ -25,7 +25,7 @@ import (
// @Param req body md.SmsSendReq true "注册参数"
// @Success 200 {string} "成功返回"
// @Failure 400 {object} md.Response "具体错误"
// @Router /v1/smsSend [post]
// @Router /api/v1/smsSend [post]
func SmsSend(c *gin.Context) {
var req md.SmsSendReq
err := c.ShouldBindJSON(&req)
@@ -59,14 +59,14 @@ func SmsSend(c *gin.Context) {
}
//校验图形验证码
id, key := svc.AliyunCaptchBase(c)
err = sms.AliyunCheckCaptcha(id, key, param)
err = aliyun.AliyunCheckCaptcha(id, key, param)
if err != nil {
e.OutErr(c, 400, e.NewErr(400, "图形验证码校验失败"))
return
}
data := svc.AliyunSmsBase(c, req.Type)
//发送短信
err = sms.AliyunSendSms(data["aliyun_sms_id"], data["aliyun_sms_secret"], req.Mobile, data["aliyun_sms_sign_name"], data["aliyun_sms_code"], "")
err = aliyun.AliyunSendSms(data["aliyun_sms_id"], data["aliyun_sms_secret"], req.Mobile, data["aliyun_sms_sign_name"], data["aliyun_sms_code"], "")
if err != nil {
e.OutErr(c, 400, e.NewErr(400, "发送失败"))
return
@@ -76,6 +76,39 @@ func SmsSend(c *gin.Context) {
return
}

// fastLogin
// @Summary 一键登录
// @Tags 一键登录
// @Description 一键登录
// @Accept json
// @Produce json
// @Param req body md.FastLoginReq true "注册参数"
// @Success 200 {object} md.LoginResponse "登录成功返回"
// @Failure 400 {object} md.Response "具体错误"
// @Router /api/v1/fastLogin [post]
func FastLogin(c *gin.Context) {
var req md.FastLoginReq
err := c.ShouldBindJSON(&req)
if err != nil {
err = svc.HandleValidateErr(err)
err1 := err.(e.E)
e.OutErr(c, err1.Code, err1.Error())
return
}
data := svc.AliyunSmsBase(c, "")
//获取手机
phone, err := aliyun.AliyunFastPhone(data["aliyun_sms_id"], data["aliyun_sms_secret"], req.Token)
if err != nil {
e.OutErr(c, 400, e.NewErr(400, "获取手机号失败"))
return
}
var reqs = md.RegisterReq{
Mobile: phone,
Type: "app",
}
commReq(c, reqs)
}

// Register
// @Summary 注册
// @Tags 注册
@@ -85,7 +118,7 @@ func SmsSend(c *gin.Context) {
// @Param req body md.RegisterReq true "注册参数"
// @Success 200 {object} md.LoginResponse "登录成功返回"
// @Failure 400 {object} md.Response "具体错误"
// @Router /v1/register [post]
// @Router /api/v1/register [post]
func Register(c *gin.Context) {
var req md.RegisterReq
err := c.ShouldBindJSON(&req)
@@ -97,11 +130,14 @@ func Register(c *gin.Context) {
}
data := svc.AliyunSmsBase(c, req.Type)
//校验短信
err = sms.AliyunCheckSms(data["aliyun_sms_id"], data["aliyun_sms_secret"], req.Mobile, req.Code)
err = aliyun.AliyunCheckSms(data["aliyun_sms_id"], data["aliyun_sms_secret"], req.Mobile, req.Code)
if err != nil {
e.OutErr(c, 400, e.NewErr(400, "验证码错误,请重试"))
return
}
commReq(c, req)
}
func commReq(c *gin.Context, req md.RegisterReq) {
now := time.Now()
userDb := implement.NewUserDb(db.Db)
user, err := userDb.UserGetOneByParams(map[string]interface{}{
@@ -251,7 +287,7 @@ func Register(c *gin.Context) {
// @Param req body md.LoginReq true "用户名密码"
// @Success 200 {object} md.LoginResponse "token"
// @Failure 400 {object} md.Response "具体错误"
// @Router /v1/login [post]
// @Router /api/v1/login [post]
func Login(c *gin.Context) {
var req md.LoginReq
err := c.ShouldBindJSON(&req)


+ 36
- 0
app/hdl/hdl_user.go Ver fichero

@@ -0,0 +1,36 @@
package hdl

import (
"applet/app/e"
"applet/app/md"
"applet/app/svc"
"github.com/gin-gonic/gin"
)

// UserInfo
// @Summary 用户信息
// @Tags 用户信息
// @Description 用户信息
// @Accept json
// @Produce json
// @param Authorization header string true "验证参数Bearer和token空格拼接"
// @Success 200 {object} md.UserInfoResp "具体数据"
// @Failure 400 {object} md.Response "具体错误"
// @Router /api/v1/userInfo [get]
func UserInfo(c *gin.Context) {
user := svc.GetUser(c)
res := md.UserInfoResp{
Phone: user.Phone,
Nickname: user.Phone,
InviteCode: user.SystemInviteCode,
IsBindExtend: "0",
}
if user.CustomInviteCode != "" {
res.InviteCode = user.CustomInviteCode
}
if user.ParentUid > 0 {
res.IsBindExtend = "1"
}
e.OutSuc(c, res, nil)
return
}

+ 4
- 0
app/md/md_login.go Ver fichero

@@ -19,6 +19,10 @@ type RegisterReq struct {
Nickname string `json:"nickname" example:"昵称"`
Sex int `json:"sex"` //性别(0:未知 1:男 2:女)
}
type FastLoginReq struct {
Token string `json:"token" example:"一键登录的token"`
InviteCode string `json:"invite_code" example:"邀请码"`
}

type LoginReq struct {
Phone string `json:"phone" binding:"required" example:"手机号"`


+ 8
- 0
app/md/md_user.go Ver fichero

@@ -0,0 +1,8 @@
package md

type UserInfoResp struct {
Phone string `json:"phone"`
Nickname string `json:"nickname"`
InviteCode string `json:"invite_code"`
IsBindExtend string `json:"is_bind_extend" example:"是否绑定了上级 0否 1是"`
}

+ 6
- 4
app/router/router.go Ver fichero

@@ -52,11 +52,13 @@ func route(r *gin.RouterGroup) {
r.Any("/aesDecryptByECB", hdl.AesDecryptByECB)
r.Use(mw.CheckSign)
r.Any("/testCreateSign", hdl.TestCreateSign)
r.POST("/smsSend", hdl.SmsSend)
r.POST("/register", hdl.Register)
r.POST("/login", hdl.Login)
r.Use(mw.Auth) // 以下接口需要JWT验证
r.POST("/smsSend", hdl.SmsSend) //发送短信
r.POST("/fastLogin", hdl.FastLogin) //一键登录
r.POST("/register", hdl.Register) //注册
r.POST("/login", hdl.Login) //登录
r.Use(mw.Auth) // 以下接口需要JWT验证
rComm(r.Group("/comm"))
r.GET("/userInfo", hdl.UserInfo) //用户基础信息
rHomePage := r.Group("/homePage")
{
rHomePage.GET("/index", hdl.HomePage) // 主页


+ 146
- 36
docs/docs.go Ver fichero

@@ -1,4 +1,5 @@
// Package docs Code generated by swaggo/swag. DO NOT EDIT
// Code generated by swaggo/swag. DO NOT EDIT.

package docs

import "github.com/swaggo/swag"
@@ -346,6 +347,46 @@ const docTemplate = `{
}
}
},
"/api/v1/fastLogin": {
"post": {
"description": "一键登录",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"一键登录"
],
"summary": "一键登录",
"parameters": [
{
"description": "注册参数",
"name": "req",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/md.FastLoginReq"
}
}
],
"responses": {
"200": {
"description": "登录成功返回",
"schema": {
"$ref": "#/definitions/md.LoginResponse"
}
},
"400": {
"description": "具体错误",
"schema": {
"$ref": "#/definitions/md.Response"
}
}
}
}
},
"/api/v1/homePage/adRule": {
"get": {
"description": "视频奖励规则(获取)",
@@ -536,9 +577,9 @@ const docTemplate = `{
}
}
},
"/api/v1/test": {
"get": {
"description": "Demo样例测试",
"/api/v1/login": {
"post": {
"description": "登入",
"consumes": [
"application/json"
],
@@ -546,24 +587,25 @@ const docTemplate = `{
"application/json"
],
"tags": [
"Demo"
"登录"
],
"summary": "Demo测试",
"summary": "登陆",
"parameters": [
{
"description": "任意参数",
"description": "用户名密码",
"name": "req",
"in": "body",
"required": true,
"schema": {}
"schema": {
"$ref": "#/definitions/md.LoginReq"
}
}
],
"responses": {
"200": {
"description": "返回任意参数",
"description": "token",
"schema": {
"type": "object",
"additionalProperties": true
"$ref": "#/definitions/md.LoginResponse"
}
},
"400": {
@@ -575,9 +617,9 @@ const docTemplate = `{
}
}
},
"/v1/login": {
"/api/v1/register": {
"post": {
"description": "登入",
"description": "注册",
"consumes": [
"application/json"
],
@@ -585,23 +627,23 @@ const docTemplate = `{
"application/json"
],
"tags": [
"登录"
"注册"
],
"summary": "登陆",
"summary": "注册",
"parameters": [
{
"description": "用户名密码",
"description": "注册参数",
"name": "req",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/md.LoginReq"
"$ref": "#/definitions/md.RegisterReq"
}
}
],
"responses": {
"200": {
"description": "token",
"description": "登录成功返回",
"schema": {
"$ref": "#/definitions/md.LoginResponse"
}
@@ -615,9 +657,9 @@ const docTemplate = `{
}
}
},
"/v1/register": {
"/api/v1/smsSend": {
"post": {
"description": "注册",
"description": "发送短信",
"consumes": [
"application/json"
],
@@ -625,9 +667,9 @@ const docTemplate = `{
"application/json"
],
"tags": [
"注册"
"发送短信"
],
"summary": "注册",
"summary": "发送短信",
"parameters": [
{
"description": "注册参数",
@@ -635,15 +677,15 @@ const docTemplate = `{
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/md.RegisterReq"
"$ref": "#/definitions/md.SmsSendReq"
}
}
],
"responses": {
"200": {
"description": "登录成功返回",
"description": "成功返回",
"schema": {
"$ref": "#/definitions/md.LoginResponse"
"type": "string"
}
},
"400": {
@@ -655,9 +697,9 @@ const docTemplate = `{
}
}
},
"/v1/smsSend": {
"post": {
"description": "发送短信",
"/api/v1/test": {
"get": {
"description": "Demo样例测试",
"consumes": [
"application/json"
],
@@ -665,25 +707,64 @@ const docTemplate = `{
"application/json"
],
"tags": [
"发送短信"
"Demo"
],
"summary": "发送短信",
"summary": "Demo测试",
"parameters": [
{
"description": "注册参数",
"description": "任意参数",
"name": "req",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/md.SmsSendReq"
"type": "object"
}
}
],
"responses": {
"200": {
"description": "成功返回",
"description": "返回任意参数",
"schema": {
"type": "string"
"type": "object",
"additionalProperties": true
}
},
"400": {
"description": "具体错误",
"schema": {
"$ref": "#/definitions/md.Response"
}
}
}
}
},
"/api/v1/userInfo": {
"get": {
"description": "用户信息",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"用户信息"
],
"summary": "用户信息",
"parameters": [
{
"type": "string",
"description": "验证参数Bearer和token空格拼接",
"name": "Authorization",
"in": "header",
"required": true
}
],
"responses": {
"200": {
"description": "具体数据",
"schema": {
"$ref": "#/definitions/md.UserInfoResp"
}
},
"400": {
@@ -903,6 +984,19 @@ const docTemplate = `{
}
}
},
"md.FastLoginReq": {
"type": "object",
"properties": {
"invite_code": {
"type": "string",
"example": "邀请码"
},
"token": {
"type": "string",
"example": "一键登录的token"
}
}
},
"md.HomePageResp": {
"type": "object",
"properties": {
@@ -1290,6 +1384,24 @@ const docTemplate = `{
"type": "string"
}
}
},
"md.UserInfoResp": {
"type": "object",
"properties": {
"invite_code": {
"type": "string"
},
"is_bind_extend": {
"type": "string",
"example": "是否绑定了上级 0否 1是"
},
"nickname": {
"type": "string"
},
"phone": {
"type": "string"
}
}
}
}
}`
@@ -1304,8 +1416,6 @@ var SwaggerInfo = &swag.Spec{
Description: "APP客户端-Api接口",
InfoInstanceName: "swagger",
SwaggerTemplate: docTemplate,
LeftDelim: "{{",
RightDelim: "}}",
}

func init() {


+ 144
- 33
docs/swagger.json Ver fichero

@@ -340,6 +340,46 @@
}
}
},
"/api/v1/fastLogin": {
"post": {
"description": "一键登录",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"一键登录"
],
"summary": "一键登录",
"parameters": [
{
"description": "注册参数",
"name": "req",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/md.FastLoginReq"
}
}
],
"responses": {
"200": {
"description": "登录成功返回",
"schema": {
"$ref": "#/definitions/md.LoginResponse"
}
},
"400": {
"description": "具体错误",
"schema": {
"$ref": "#/definitions/md.Response"
}
}
}
}
},
"/api/v1/homePage/adRule": {
"get": {
"description": "视频奖励规则(获取)",
@@ -530,9 +570,9 @@
}
}
},
"/api/v1/test": {
"get": {
"description": "Demo样例测试",
"/api/v1/login": {
"post": {
"description": "登入",
"consumes": [
"application/json"
],
@@ -540,24 +580,25 @@
"application/json"
],
"tags": [
"Demo"
"登录"
],
"summary": "Demo测试",
"summary": "登陆",
"parameters": [
{
"description": "任意参数",
"description": "用户名密码",
"name": "req",
"in": "body",
"required": true,
"schema": {}
"schema": {
"$ref": "#/definitions/md.LoginReq"
}
}
],
"responses": {
"200": {
"description": "返回任意参数",
"description": "token",
"schema": {
"type": "object",
"additionalProperties": true
"$ref": "#/definitions/md.LoginResponse"
}
},
"400": {
@@ -569,9 +610,9 @@
}
}
},
"/v1/login": {
"/api/v1/register": {
"post": {
"description": "登入",
"description": "注册",
"consumes": [
"application/json"
],
@@ -579,23 +620,23 @@
"application/json"
],
"tags": [
"登录"
"注册"
],
"summary": "登陆",
"summary": "注册",
"parameters": [
{
"description": "用户名密码",
"description": "注册参数",
"name": "req",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/md.LoginReq"
"$ref": "#/definitions/md.RegisterReq"
}
}
],
"responses": {
"200": {
"description": "token",
"description": "登录成功返回",
"schema": {
"$ref": "#/definitions/md.LoginResponse"
}
@@ -609,9 +650,9 @@
}
}
},
"/v1/register": {
"/api/v1/smsSend": {
"post": {
"description": "注册",
"description": "发送短信",
"consumes": [
"application/json"
],
@@ -619,9 +660,9 @@
"application/json"
],
"tags": [
"注册"
"发送短信"
],
"summary": "注册",
"summary": "发送短信",
"parameters": [
{
"description": "注册参数",
@@ -629,15 +670,15 @@
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/md.RegisterReq"
"$ref": "#/definitions/md.SmsSendReq"
}
}
],
"responses": {
"200": {
"description": "登录成功返回",
"description": "成功返回",
"schema": {
"$ref": "#/definitions/md.LoginResponse"
"type": "string"
}
},
"400": {
@@ -649,9 +690,9 @@
}
}
},
"/v1/smsSend": {
"post": {
"description": "发送短信",
"/api/v1/test": {
"get": {
"description": "Demo样例测试",
"consumes": [
"application/json"
],
@@ -659,25 +700,64 @@
"application/json"
],
"tags": [
"发送短信"
"Demo"
],
"summary": "发送短信",
"summary": "Demo测试",
"parameters": [
{
"description": "注册参数",
"description": "任意参数",
"name": "req",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/md.SmsSendReq"
"type": "object"
}
}
],
"responses": {
"200": {
"description": "成功返回",
"description": "返回任意参数",
"schema": {
"type": "string"
"type": "object",
"additionalProperties": true
}
},
"400": {
"description": "具体错误",
"schema": {
"$ref": "#/definitions/md.Response"
}
}
}
}
},
"/api/v1/userInfo": {
"get": {
"description": "用户信息",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"用户信息"
],
"summary": "用户信息",
"parameters": [
{
"type": "string",
"description": "验证参数Bearer和token空格拼接",
"name": "Authorization",
"in": "header",
"required": true
}
],
"responses": {
"200": {
"description": "具体数据",
"schema": {
"$ref": "#/definitions/md.UserInfoResp"
}
},
"400": {
@@ -897,6 +977,19 @@
}
}
},
"md.FastLoginReq": {
"type": "object",
"properties": {
"invite_code": {
"type": "string",
"example": "邀请码"
},
"token": {
"type": "string",
"example": "一键登录的token"
}
}
},
"md.HomePageResp": {
"type": "object",
"properties": {
@@ -1284,6 +1377,24 @@
"type": "string"
}
}
},
"md.UserInfoResp": {
"type": "object",
"properties": {
"invite_code": {
"type": "string"
},
"is_bind_extend": {
"type": "string",
"example": "是否绑定了上级 0否 1是"
},
"nickname": {
"type": "string"
},
"phone": {
"type": "string"
}
}
}
}
}

+ 102
- 29
docs/swagger.yaml Ver fichero

@@ -141,6 +141,15 @@ definitions:
- $ref: '#/definitions/md.TransferTypeList'
description: 转账类型列表
type: object
md.FastLoginReq:
properties:
invite_code:
example: 邀请码
type: string
token:
example: 一键登录的token
type: string
type: object
md.HomePageResp:
properties:
egg_energy_now_price:
@@ -408,6 +417,18 @@ definitions:
value:
type: string
type: object
md.UserInfoResp:
properties:
invite_code:
type: string
is_bind_extend:
example: 是否绑定了上级 0否 1是
type: string
nickname:
type: string
phone:
type: string
type: object
host: ddxq.izhim.com
info:
contact:
@@ -634,6 +655,32 @@ paths:
summary: 通用请求-对象存储-上传许可链接(获取)
tags:
- 对象存储
/api/v1/fastLogin:
post:
consumes:
- application/json
description: 一键登录
parameters:
- description: 注册参数
in: body
name: req
required: true
schema:
$ref: '#/definitions/md.FastLoginReq'
produces:
- application/json
responses:
"200":
description: 登录成功返回
schema:
$ref: '#/definitions/md.LoginResponse'
"400":
description: 具体错误
schema:
$ref: '#/definitions/md.Response'
summary: 一键登录
tags:
- 一键登录
/api/v1/homePage/adRule:
get:
consumes:
@@ -759,33 +806,7 @@ paths:
summary: 蛋蛋星球-主页-实时数据(获取)
tags:
- 主页
/api/v1/test:
get:
consumes:
- application/json
description: Demo样例测试
parameters:
- description: 任意参数
in: body
name: req
required: true
schema: {}
produces:
- application/json
responses:
"200":
description: 返回任意参数
schema:
additionalProperties: true
type: object
"400":
description: 具体错误
schema:
$ref: '#/definitions/md.Response'
summary: Demo测试
tags:
- Demo
/v1/login:
/api/v1/login:
post:
consumes:
- application/json
@@ -811,7 +832,7 @@ paths:
summary: 登陆
tags:
- 登录
/v1/register:
/api/v1/register:
post:
consumes:
- application/json
@@ -837,7 +858,7 @@ paths:
summary: 注册
tags:
- 注册
/v1/smsSend:
/api/v1/smsSend:
post:
consumes:
- application/json
@@ -863,4 +884,56 @@ paths:
summary: 发送短信
tags:
- 发送短信
/api/v1/test:
get:
consumes:
- application/json
description: Demo样例测试
parameters:
- description: 任意参数
in: body
name: req
required: true
schema:
type: object
produces:
- application/json
responses:
"200":
description: 返回任意参数
schema:
additionalProperties: true
type: object
"400":
description: 具体错误
schema:
$ref: '#/definitions/md.Response'
summary: Demo测试
tags:
- Demo
/api/v1/userInfo:
get:
consumes:
- application/json
description: 用户信息
parameters:
- description: 验证参数Bearer和token空格拼接
in: header
name: Authorization
required: true
type: string
produces:
- application/json
responses:
"200":
description: 具体数据
schema:
$ref: '#/definitions/md.UserInfoResp'
"400":
description: 具体错误
schema:
$ref: '#/definitions/md.Response'
summary: 用户信息
tags:
- 用户信息
swagger: "2.0"

+ 1
- 1
go.mod Ver fichero

@@ -33,7 +33,7 @@ require (

require (
code.fnuoos.com/EggPlanet/egg_models.git v0.2.1-0.20241122012509-ceb61ba8203c
code.fnuoos.com/EggPlanet/egg_system_rules.git v0.0.4-0.20241122005808-60ab25ac1d22
code.fnuoos.com/EggPlanet/egg_system_rules.git v0.0.4-0.20241122035952-de4df98d64dc
code.fnuoos.com/go_rely_warehouse/zyos_go_es.git v1.0.1-0.20241118083738-0f22da9ba0be
code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git v0.0.5
github.com/aliyun/aliyun-oss-go-sdk v3.0.2+incompatible


Cargando…
Cancelar
Guardar