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.
169 lines
3.9 KiB
169 lines
3.9 KiB
package jili2 |
|
|
|
import ( |
|
"fmt" |
|
"github.com/liangdas/mqant/log" |
|
"gorm.io/gorm/clause" |
|
"server/common" |
|
"server/db" |
|
"server/util" |
|
"strconv" |
|
"strings" |
|
"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"` |
|
RtpPool int `json:"rtp_pool"` |
|
} |
|
|
|
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 |
|
} |
|
|
|
for _, item := range response.Data.GameList { |
|
id, _ := strconv.Atoi(item.MapID) |
|
if strings.Contains(item.GameID, "jili") { |
|
tmpGameList := common.ConfigGameList{ |
|
GameProvider: common.ProviderJiLi2, |
|
GameID: id, |
|
GameCode: item.GameID, |
|
Icon: item.Icon, |
|
Name: item.Name, |
|
} |
|
updates := make(map[string]interface{}) |
|
if item.GameID != "" { |
|
updates["game_code"] = item.GameID |
|
} |
|
if item.Icon != "" { |
|
updates["icon"] = item.Icon |
|
} |
|
if item.Name != "" { |
|
updates["name"] = item.Name |
|
} |
|
// todo 改为协程池 |
|
util.Go(func() { |
|
err = db.Mysql().C().Model(&common.ConfigGameList{}).Clauses(clause.OnConflict{ |
|
Columns: []clause.Column{{Name: "game_id"}, {Name: "game_provider"}}, |
|
DoUpdates: clause.Assignments(updates), |
|
}).Create(&tmpGameList).Error |
|
if err != nil { |
|
log.Error("update game list err, %s", err.Error()) |
|
} |
|
}) |
|
} |
|
|
|
} |
|
}
|
|
|