You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
96 lines
2.1 KiB
96 lines
2.1 KiB
package app |
|
|
|
import ( |
|
"net" |
|
"server/call" |
|
"server/common" |
|
"server/db" |
|
"server/modules/web/values" |
|
"strings" |
|
|
|
"github.com/go-redis/redis/v8" |
|
"github.com/liangdas/mqant/log" |
|
iptool "github.com/liangdas/mqant/utils/ip" |
|
"gorm.io/gorm" |
|
) |
|
|
|
// VerifyCode 验证短信验证码 |
|
func (g *Gin) VerifyCode(reqContent, reqCode string) bool { |
|
code, err := db.Redis().GetString(common.GetRedisKeyCode(reqContent)) |
|
if err != nil && err != redis.Nil { |
|
log.Error("err:%v", err) |
|
g.Code = values.CodeRetry |
|
return false |
|
} |
|
if code != reqCode { |
|
g.Code = values.CodeCodeError |
|
g.Msg = "Code is wrong." |
|
return false |
|
} |
|
return true |
|
} |
|
|
|
// GetRemoteIP 获取玩家真实IP |
|
func (g *Gin) GetRemoteIP() string { |
|
ip := g.Context.GetHeader("X-Real-IP") |
|
if ip != "" { |
|
if !iptool.IsInnerIp(ip) { |
|
return ip |
|
} |
|
} |
|
ip = iptool.RealIP(g.Context.Request) |
|
if strings.Contains(ip, ":") { |
|
ip, _, _ = net.SplitHostPort(ip) |
|
} |
|
return ip |
|
} |
|
|
|
func (g *Gin) QueryUser(req values.CommonLogin) (user *common.PlayerDBInfo, isNew bool) { |
|
u := &common.PlayerDBInfo{ChannelID: g.Channel} |
|
if len(req.Phone) > 0 { |
|
u.Mobile = req.Phone |
|
} else { |
|
u.Openid = &req.OpenID |
|
} |
|
if err := db.Mysql().Get(u); err != nil && err != gorm.ErrRecordNotFound { |
|
g.Code = values.CodeRetry |
|
log.Error("err:%v", err) |
|
return |
|
} |
|
if req.DeviceID == "" { |
|
req.DeviceID = req.OpenID |
|
} |
|
// if req.Gpsadid == "" { |
|
// req.Gpsadid = req.DeviceID |
|
// } |
|
user = u |
|
if user.Id <= 0 { |
|
user.Nick = req.Nick |
|
user.Avatar = req.Avatar |
|
user.AccountType = req.AccountType |
|
user.ChannelID = g.Channel |
|
user.DeviceId = req.DeviceID |
|
user.ADID = req.Adid |
|
user.GPSADID = req.Gpsadid |
|
user.Openid = &req.OpenID |
|
user.AccountName = req.AccountName |
|
user.Pass = req.Pass |
|
if len(req.Phone) > 0 { |
|
user.Mobile = req.Phone |
|
} |
|
ip := g.GetRemoteIP() |
|
if err := call.NewUser(user, ip, req.Share, req.Fbc, req.Fbp, req.UserAgent); err != nil { |
|
g.Code = values.CodeRetry |
|
if err.Error() == "ip" { |
|
g.Code = values.CodeAccountIPLimit |
|
g.Msg = "ip limit" |
|
} |
|
return |
|
} |
|
isNew = true |
|
} else { |
|
user.ADID = req.Adid |
|
user.GPSADID = req.Gpsadid |
|
} |
|
return |
|
}
|
|
|