|
|
|
|
package pg2
|
|
|
|
|
|
|
|
|
|
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.ProviderPG2,
|
|
|
|
|
GameID: id,
|
|
|
|
|
GameCode: item.GameID,
|
|
|
|
|
Icon: item.Icon,
|
|
|
|
|
Name: item.Name,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
db.Mysql().Create(gameList)
|
|
|
|
|
}
|