Compare commits
No commits in common. '6abd764baf47ff904cdc543d445e82d1253f97ce' and 'e44d0e1e63ee72d2e8c3d8b652032ce6c9db4bde' have entirely different histories.
6abd764baf
...
e44d0e1e63
15 changed files with 71 additions and 431 deletions
@ -1,144 +0,0 @@ |
|||||||
package jili2 |
|
||||||
|
|
||||||
import ( |
|
||||||
"fmt" |
|
||||||
"server/common" |
|
||||||
"server/db" |
|
||||||
"server/util" |
|
||||||
"strconv" |
|
||||||
"time" |
|
||||||
) |
|
||||||
|
|
||||||
const ( |
|
||||||
ErrCodeSuccess = 0 |
|
||||||
ErrCodePlayerNotFound = 2000 // 玩家不存在
|
|
||||||
ErrCodePlayerToken = 2001 // Token错误
|
|
||||||
ErrCodeInvalidGameID = 102 // 无效的GameDI
|
|
||||||
ErrCodeInternalError = 3000 // 内部错误
|
|
||||||
ErrCodeInsufficientBal = 2010 // 投注失败,如余额不足
|
|
||||||
) |
|
||||||
|
|
||||||
type GameListResponse struct { |
|
||||||
Code int `json:"code"` |
|
||||||
Msg string `json:"msg"` |
|
||||||
Data GameListData `json:"data"` |
|
||||||
} |
|
||||||
|
|
||||||
type GameListData struct { |
|
||||||
GameList []GameListItem `json:"glist"` |
|
||||||
} |
|
||||||
|
|
||||||
type GameListItem struct { |
|
||||||
Icon string `json:"icon"` |
|
||||||
MapID string `json:"mapid"` |
|
||||||
Name string `json:"name"` |
|
||||||
Site string `json:"site"` |
|
||||||
GameID string `json:"gameid"` |
|
||||||
} |
|
||||||
|
|
||||||
// EnterGameRequest 进入游戏
|
|
||||||
type EnterGameRequest struct { |
|
||||||
Uname string `json:"uname"` |
|
||||||
GameID string `json:"gameid"` |
|
||||||
Token string `json:"token,omitempty"` |
|
||||||
Lang string `json:"lang,omitempty"` |
|
||||||
Nick string `json:"nick,omitempty"` |
|
||||||
} |
|
||||||
|
|
||||||
type EnterGameResponse struct { |
|
||||||
Code int `json:"code"` |
|
||||||
Msg string `json:"msg"` |
|
||||||
Data struct { |
|
||||||
GameURL string `json:"gameurl"` |
|
||||||
} `json:"data"` |
|
||||||
} |
|
||||||
|
|
||||||
// PlaceBetRequest 下注
|
|
||||||
type PlaceBetRequest struct { |
|
||||||
Uname string `json:"uname"` |
|
||||||
Token string `json:"token"` |
|
||||||
BetID string `json:"betid"` |
|
||||||
SessionID string `json:"sessionid"` |
|
||||||
GameID string `json:"gameid"` |
|
||||||
Bet float64 `json:"bet"` |
|
||||||
Award float64 `json:"award"` |
|
||||||
IsEndRound bool `json:"is_end_round"` |
|
||||||
Ctime int64 `json:"ctime"` |
|
||||||
} |
|
||||||
|
|
||||||
type PlaceBetResponse struct { |
|
||||||
Code int `json:"code"` |
|
||||||
Msg string `json:"msg"` |
|
||||||
Data struct { |
|
||||||
Uname string `json:"uname"` |
|
||||||
BetID string `json:"betid"` |
|
||||||
Balance float64 `json:"balance"` |
|
||||||
} `json:"data"` |
|
||||||
} |
|
||||||
|
|
||||||
type VerifySessionReq struct { |
|
||||||
Uname string `json:"uname"` |
|
||||||
Token string `json:"token"` |
|
||||||
} |
|
||||||
|
|
||||||
type VerifySessionResp struct { |
|
||||||
Code int `json:"code"` |
|
||||||
Msg string `json:"msg"` |
|
||||||
Data struct { |
|
||||||
Uname string `json:"uname"` |
|
||||||
Balance float64 `json:"balance"` |
|
||||||
} `json:"data"` |
|
||||||
} |
|
||||||
|
|
||||||
type GetBalanceRequest struct { |
|
||||||
GameId string `json:"gameid"` |
|
||||||
Uname string `json:"uname"` |
|
||||||
} |
|
||||||
|
|
||||||
type GetBalanceResponse struct { |
|
||||||
Code int `json:"code"` |
|
||||||
Msg string `json:"msg"` |
|
||||||
Data struct { |
|
||||||
Uname string `json:"uname"` |
|
||||||
Balance float64 `json:"balance"` |
|
||||||
} `json:"data"` |
|
||||||
} |
|
||||||
|
|
||||||
func GetGameList() { |
|
||||||
API = APITest |
|
||||||
AgentMap = AgentMapTest |
|
||||||
url := fmt.Sprintf("%s/api/game/loadlist", APITest) |
|
||||||
mchid := AgentMap.MchId |
|
||||||
key := AgentMap.Key |
|
||||||
timestamp := time.Now().Unix() |
|
||||||
headers := map[string]string{ |
|
||||||
"X-Atgame-Mchid": mchid, |
|
||||||
"X-Atgame-Timestamp": strconv.FormatInt(timestamp, 10), |
|
||||||
"Content-Type": "application/json;charset=UTF-8", |
|
||||||
} |
|
||||||
type empty struct{} |
|
||||||
var e empty |
|
||||||
// Generate sign
|
|
||||||
emptyBody := "{}" |
|
||||||
sign := GenerateSign(emptyBody, timestamp, key) |
|
||||||
headers["X-Atgame-Sign"] = sign |
|
||||||
|
|
||||||
var response GameListResponse |
|
||||||
err := util.HttpPost(url, e, &response, headers) |
|
||||||
if err != nil { |
|
||||||
return |
|
||||||
} |
|
||||||
|
|
||||||
var gameList []*common.ConfigGameList |
|
||||||
for _, item := range response.Data.GameList { |
|
||||||
id, _ := strconv.Atoi(item.MapID) |
|
||||||
gameList = append(gameList, &common.ConfigGameList{ |
|
||||||
GameProvider: common.ProviderJiLi2, |
|
||||||
GameID: id, |
|
||||||
GameCode: item.GameID, |
|
||||||
Icon: item.Icon, |
|
||||||
Name: item.Name, |
|
||||||
}) |
|
||||||
} |
|
||||||
db.Mysql().Create(gameList) |
|
||||||
} |
|
||||||
@ -1,72 +0,0 @@ |
|||||||
package jili2 |
|
||||||
|
|
||||||
import ( |
|
||||||
"encoding/json" |
|
||||||
"fmt" |
|
||||||
"server/call" |
|
||||||
"server/config" |
|
||||||
"server/modules/web/providers/base" |
|
||||||
utils "server/util" |
|
||||||
"strconv" |
|
||||||
"time" |
|
||||||
|
|
||||||
"github.com/liangdas/mqant/log" |
|
||||||
) |
|
||||||
|
|
||||||
type Sub struct { |
|
||||||
Base *base.Base |
|
||||||
} |
|
||||||
|
|
||||||
func NewSub(base *base.Base) { |
|
||||||
base.Sub = &Sub{Base: base} |
|
||||||
base.SubInitRouter = JiLi |
|
||||||
} |
|
||||||
|
|
||||||
func (s *Sub) Init() { |
|
||||||
API = APITest |
|
||||||
AgentMap = AgentMapTest |
|
||||||
if config.GetBase().Release { |
|
||||||
API = APIRlease |
|
||||||
AgentMap = AgentMapRelease |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
func (s *Sub) EnterGame() string { |
|
||||||
url := fmt.Sprintf("%s/api/usr/ingame", API) |
|
||||||
timestamp := time.Now().Unix() |
|
||||||
uid := s.Base.EnterGameReq.UID |
|
||||||
token := s.Base.EnterGameReq.Token |
|
||||||
providerID := s.Base.EnterGameReq.ProviderID |
|
||||||
gameID := s.Base.EnterGameReq.GameID |
|
||||||
mchid := AgentMap.MchId |
|
||||||
key := AgentMap.Key |
|
||||||
headers := map[string]string{ |
|
||||||
"X-Atgame-Mchid": mchid, |
|
||||||
"X-Atgame-Timestamp": strconv.FormatInt(timestamp, 10), |
|
||||||
"Content-Type": "application/json;charset=UTF-8", |
|
||||||
} |
|
||||||
// Generate sign
|
|
||||||
game := call.GetConfigGameListByID(providerID, gameID) |
|
||||||
if game == nil { |
|
||||||
return "" |
|
||||||
} |
|
||||||
request := EnterGameRequest{ |
|
||||||
Uname: fmt.Sprintf("%d", uid), |
|
||||||
GameID: game.GameCode, |
|
||||||
Token: token, |
|
||||||
Lang: Lang, |
|
||||||
Nick: "", |
|
||||||
} |
|
||||||
body, _ := json.Marshal(request) |
|
||||||
sign := GenerateSign(string(body), timestamp, key) |
|
||||||
headers["X-Atgame-Sign"] = sign |
|
||||||
// Decode response
|
|
||||||
var response EnterGameResponse |
|
||||||
err := utils.HttpPost(url, request, &response, headers) |
|
||||||
if err != nil { |
|
||||||
log.Error("err:%v", err) |
|
||||||
return "" |
|
||||||
} |
|
||||||
|
|
||||||
return response.Data.GameURL |
|
||||||
} |
|
||||||
@ -1,143 +0,0 @@ |
|||||||
package jili2 |
|
||||||
|
|
||||||
import ( |
|
||||||
"server/call" |
|
||||||
"server/common" |
|
||||||
"server/db" |
|
||||||
"server/modules/web/app" |
|
||||||
"server/modules/web/providers/base" |
|
||||||
"server/util" |
|
||||||
"strconv" |
|
||||||
"time" |
|
||||||
|
|
||||||
"github.com/gin-gonic/gin" |
|
||||||
"github.com/liangdas/mqant/log" |
|
||||||
) |
|
||||||
|
|
||||||
func JiLi(e *gin.RouterGroup) { |
|
||||||
e.POST("/VerifySession", VerifySession) |
|
||||||
e.POST("/Cash/Get", GetPlayerBalance) |
|
||||||
e.POST("/Cash/Bet", PlaceBet) |
|
||||||
} |
|
||||||
|
|
||||||
func GetGameID(providerID int, gameCode string) int { |
|
||||||
game := call.GetConfigGameListByCode(providerID, gameCode) |
|
||||||
if game != nil { |
|
||||||
return game.GameID |
|
||||||
} |
|
||||||
return 0 |
|
||||||
} |
|
||||||
|
|
||||||
func VerifySession(c *gin.Context) { |
|
||||||
a := app.NewApp(c) |
|
||||||
defer func() { |
|
||||||
a.ResponseB() |
|
||||||
}() |
|
||||||
req := &VerifySessionReq{} |
|
||||||
resp := &VerifySessionResp{} |
|
||||||
a.RetData = resp |
|
||||||
if !a.SB(req) { |
|
||||||
resp.Code = ErrCodeInternalError |
|
||||||
return |
|
||||||
} |
|
||||||
log.Debug("VerifySession req:%+v", req) |
|
||||||
uid, err := strconv.Atoi(req.Uname) |
|
||||||
if err != nil { |
|
||||||
log.Error("err:%v", err) |
|
||||||
resp.Code = ErrCodePlayerNotFound |
|
||||||
return |
|
||||||
} |
|
||||||
|
|
||||||
currency, err := db.Redis().GetInt(common.GetRedisKeyGameCurrency(uid)) |
|
||||||
if err != nil { |
|
||||||
log.Error("err:%v", err) |
|
||||||
resp.Code = ErrCodeInternalError |
|
||||||
return |
|
||||||
} |
|
||||||
|
|
||||||
resp.Data.Balance = call.GetUserCurrencyFloat(uid, common.CurrencyType(currency), 2) |
|
||||||
|
|
||||||
a.Data = resp |
|
||||||
} |
|
||||||
|
|
||||||
func GetPlayerBalance(c *gin.Context) { |
|
||||||
a := app.NewApp(c) |
|
||||||
defer func() { |
|
||||||
a.ResponseB() |
|
||||||
}() |
|
||||||
req := &GetBalanceRequest{} |
|
||||||
resp := &GetBalanceResponse{} |
|
||||||
a.RetData = resp |
|
||||||
if !a.SB(req) { |
|
||||||
resp.Code = ErrCodeInternalError |
|
||||||
return |
|
||||||
} |
|
||||||
log.Debug("GetPlayerBalance req:%+v", req) |
|
||||||
uid, err := strconv.Atoi(req.Uname) |
|
||||||
if err != nil { |
|
||||||
log.Error("err:%v", err) |
|
||||||
resp.Code = ErrCodePlayerNotFound |
|
||||||
return |
|
||||||
} |
|
||||||
|
|
||||||
currency, err := db.Redis().GetInt(common.GetRedisKeyGameCurrency(uid)) |
|
||||||
if err != nil { |
|
||||||
log.Error("err:%v", err) |
|
||||||
resp.Code = ErrCodeInternalError |
|
||||||
return |
|
||||||
} |
|
||||||
resp.Data.Uname = req.Uname |
|
||||||
resp.Data.Balance = call.GetUserCurrencyFloat(uid, common.CurrencyType(currency), 2) |
|
||||||
a.Data = resp |
|
||||||
} |
|
||||||
|
|
||||||
func PlaceBet(c *gin.Context) { |
|
||||||
a := app.NewApp(c) |
|
||||||
defer func() { |
|
||||||
a.ResponseB() |
|
||||||
}() |
|
||||||
req := &PlaceBetRequest{} |
|
||||||
resp := &PlaceBetResponse{} |
|
||||||
a.RetData = resp |
|
||||||
if !a.SB(req) { |
|
||||||
resp.Code = ErrCodeInternalError |
|
||||||
return |
|
||||||
} |
|
||||||
log.Debug("PlaceBet:%+v", req) |
|
||||||
// 验证token
|
|
||||||
uid, _ := db.Redis().GetInt(common.GetRedisKeyToken(req.Token)) |
|
||||||
if uid == 0 { |
|
||||||
resp.Code = ErrCodePlayerNotFound |
|
||||||
return |
|
||||||
} |
|
||||||
|
|
||||||
provider := call.GetConfigGameProvider(common.ProviderJiLi2) |
|
||||||
now := time.Now().Unix() |
|
||||||
betReq := &base.BetReq{ |
|
||||||
UID: uid, |
|
||||||
CurrencyType: common.CurrencyINR, |
|
||||||
BetAmount: int64(req.Bet * common.DecimalDigits), |
|
||||||
TurnOver: int64(req.Bet * common.DecimalDigits), |
|
||||||
SettleAmount: int64(req.Award * common.DecimalDigits), |
|
||||||
SessionType: common.SessionTypeSettle, |
|
||||||
GameID: GetGameID(common.ProviderJiLi2, req.GameID), |
|
||||||
GameName: req.GameID, |
|
||||||
Provider: provider, |
|
||||||
BetID: req.BetID, |
|
||||||
SessionID: req.SessionID, |
|
||||||
Time: now, |
|
||||||
} |
|
||||||
betResp := base.SessionBet(betReq) |
|
||||||
if betResp.Code != base.CodeOk { |
|
||||||
resp.Code = ErrCodeInternalError |
|
||||||
if betResp.Code == base.CodeAccepted { |
|
||||||
resp.Code = ErrCodeInternalError |
|
||||||
} else if betResp.Code == base.CodeNotEnoughAmount { |
|
||||||
resp.Code = ErrCodeInsufficientBal |
|
||||||
} |
|
||||||
return |
|
||||||
} |
|
||||||
resp.Data.Balance = util.Decimal(float64(betResp.Balance)/common.DecimalDigits, 2) |
|
||||||
|
|
||||||
a.Data = resp |
|
||||||
} |
|
||||||
@ -1,14 +0,0 @@ |
|||||||
package jili2 |
|
||||||
|
|
||||||
import ( |
|
||||||
"crypto/md5" |
|
||||||
"encoding/hex" |
|
||||||
"strconv" |
|
||||||
"strings" |
|
||||||
) |
|
||||||
|
|
||||||
func GenerateSign(body string, timestamp int64, key string) string { |
|
||||||
data := body + strconv.FormatInt(timestamp, 10) + key |
|
||||||
hash := md5.Sum([]byte(data)) |
|
||||||
return strings.ToUpper(hex.EncodeToString(hash[:])) |
|
||||||
} |
|
||||||
@ -1,24 +0,0 @@ |
|||||||
package jili2 |
|
||||||
|
|
||||||
const ( |
|
||||||
APIRlease = "https://openapi-br.atgameapp.com/pub" |
|
||||||
APITest = "https://api.jgameworks.com" |
|
||||||
LaunchGameURL = "/api/usr/ingame" |
|
||||||
GetGameListURL = "/api/game/loadlist" |
|
||||||
Lang = "en" |
|
||||||
) |
|
||||||
|
|
||||||
type Agent struct { |
|
||||||
MchId string `json:"mch_id"` |
|
||||||
Key string `json:"key"` |
|
||||||
} |
|
||||||
|
|
||||||
var ( |
|
||||||
API = "" |
|
||||||
AgentMap Agent |
|
||||||
AgentMapTest = Agent{ |
|
||||||
MchId: "10017", |
|
||||||
Key: "C54E411A1B89C54BFB977EBAA7BB1D39", |
|
||||||
} |
|
||||||
AgentMapRelease = Agent{} |
|
||||||
) |
|
||||||
Loading…
Reference in new issue