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.
79 lines
1.9 KiB
79 lines
1.9 KiB
package pg4 |
|
|
|
import ( |
|
"encoding/json" |
|
"fmt" |
|
"server/call" |
|
"server/common" |
|
"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 = PG |
|
} |
|
|
|
func (s *Sub) Init() { |
|
API = APITest |
|
AgentMap = AgentMapTest |
|
if config.GetBase().Release { |
|
API = APIRelease |
|
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-Game-Mchid": mchid, |
|
"X-Game-Timestamp": strconv.FormatInt(timestamp, 10), |
|
"Content-Type": "application/json;charset=UTF-8", |
|
} |
|
rechargeInfo := call.GetRechargeInfo(uid) |
|
balance := call.GetUserCurrency(uid, common.CurrencyINR) |
|
playerProfile := call.GetPlayerProfile(uid) |
|
game := call.GetConfigGameListByID(providerID, gameID) |
|
if game == nil { |
|
return "" |
|
} |
|
request := EnterGameRequest{ |
|
Uname: common.GetProviderUserName(fmt.Sprintf("%d", uid)), |
|
GameID: game.GameCode, |
|
Token: common.GetProviderUserToken(token), |
|
Lang: "pt", |
|
Nick: "", |
|
TotalRecharge: rechargeInfo.TotalRecharge, |
|
TotalWithdraw: rechargeInfo.TotalWithdraw + rechargeInfo.TotalWithdrawing, |
|
TotalBet: playerProfile.TotalBet, |
|
Balance: balance / common.DecimalDigits, |
|
} |
|
body, _ := json.Marshal(request) |
|
sign := GenerateSign(string(body), timestamp, key) |
|
headers["X-Game-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 |
|
}
|
|
|