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.
72 lines
1.5 KiB
72 lines
1.5 KiB
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 |
|
}
|
|
|