mirror of
https://github.com/FlourishingWorld/hk4e.git
synced 2026-02-09 13:52:27 +08:00
系统架构层面流量控制功能完善
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"hk4e/dispatch/api"
|
||||
"hk4e/dispatch/model"
|
||||
@@ -98,7 +99,7 @@ func (c *Controller) apiLogin(context *gin.Context) {
|
||||
return
|
||||
}
|
||||
if account == nil {
|
||||
// 注册一个原神account
|
||||
// 自动注册
|
||||
accountId, err := c.dao.GetNextAccountId()
|
||||
if err != nil {
|
||||
responseData.Retcode = -201
|
||||
@@ -138,7 +139,7 @@ func (c *Controller) apiLogin(context *gin.Context) {
|
||||
context.JSON(http.StatusOK, responseData)
|
||||
return
|
||||
}
|
||||
// 生产新的token
|
||||
// 生成新的token
|
||||
account.Token = base64.StdEncoding.EncodeToString(random.GetRandomByte(24))
|
||||
_, err = c.dao.UpdateAccountFieldByFieldName("accountID", account.AccountID, "token", account.Token)
|
||||
if err != nil {
|
||||
@@ -147,6 +148,13 @@ func (c *Controller) apiLogin(context *gin.Context) {
|
||||
context.JSON(http.StatusOK, responseData)
|
||||
return
|
||||
}
|
||||
_, err = c.dao.UpdateAccountFieldByFieldName("accountID", account.AccountID, "tokenCreateTime", time.Now().UnixMilli())
|
||||
if err != nil {
|
||||
responseData.Retcode = -201
|
||||
responseData.Message = "服务器内部错误:-5"
|
||||
context.JSON(http.StatusOK, responseData)
|
||||
return
|
||||
}
|
||||
responseData.Message = "OK"
|
||||
responseData.Data.Account.Uid = strconv.FormatInt(int64(account.AccountID), 10)
|
||||
responseData.Data.Account.Token = account.Token
|
||||
@@ -178,6 +186,12 @@ func (c *Controller) apiVerify(context *gin.Context) {
|
||||
context.JSON(http.StatusOK, responseData)
|
||||
return
|
||||
}
|
||||
if uint64(time.Now().UnixMilli())-account.TokenCreateTime > uint64(time.Hour.Milliseconds()*24*7) {
|
||||
responseData.Retcode = -111
|
||||
responseData.Message = "登录已失效"
|
||||
context.JSON(http.StatusOK, responseData)
|
||||
return
|
||||
}
|
||||
responseData.Message = "OK"
|
||||
responseData.Data.Account.Uid = requestData.Uid
|
||||
responseData.Data.Account.Token = requestData.Token
|
||||
@@ -225,6 +239,13 @@ func (c *Controller) v2Login(context *gin.Context) {
|
||||
context.JSON(http.StatusOK, responseData)
|
||||
return
|
||||
}
|
||||
_, err = c.dao.UpdateAccountFieldByFieldName("accountID", account.AccountID, "comboTokenUsed", false)
|
||||
if err != nil {
|
||||
responseData.Retcode = -201
|
||||
responseData.Message = "服务器内部错误:-2"
|
||||
context.JSON(http.StatusOK, responseData)
|
||||
return
|
||||
}
|
||||
responseData.Message = "OK"
|
||||
responseData.Data.OpenID = loginData.Uid
|
||||
responseData.Data.ComboID = "0"
|
||||
|
||||
Reference in New Issue
Block a user