印度包网
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.
 
 
 

113 lines
2.7 KiB

package app
import (
"fmt"
"github.com/go-redis/redis/v8"
"github.com/liangdas/mqant/log"
iptool "github.com/liangdas/mqant/utils/ip"
"github.com/olivere/elastic/v7"
"gorm.io/gorm"
"net"
"server/call"
"server/common"
"server/db"
"server/modules/web/values"
"server/util"
"strings"
"time"
)
// 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
if len(req.DeviceID) > 0 {
uuid := req.DeviceID
// 处理一下新增安装
util.Go(func() {
q := elastic.NewBoolQuery()
q.Filter(elastic.NewTermsQuery("UUID.keyword", uuid))
q.Filter(elastic.NewTermQuery("Channel", g.Channel))
if db.ES().Count(common.ESIndexBackOpenRecord, q) > 0 {
return
}
id := fmt.Sprintf("%v_%v", g.Channel, uuid)
db.ES().InsertToESByIDGO(common.ESIndexBackOpenRecord, id, &common.ESOpenRecord{Time: time.Now().Unix(), UUID: uuid, Channel: g.Channel})
})
}
} else {
user.ADID = req.Adid
user.GPSADID = req.Gpsadid
}
return
}