印度包网
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.

173 lines
4.0 KiB

2 months ago
package sn
import (
"encoding/json"
"fmt"
"server/call"
"server/config"
"server/modules/web/providers/base"
"server/util"
"time"
"github.com/liangdas/mqant/log"
)
type Sub struct {
Base *base.Base
}
func NewSub(base *base.Base) {
base.Sub = &Sub{Base: base}
base.SubInitRouter = Sn
}
func (s *Sub) Init() {
API = APITest
APICreate = APICreateUserTest
APIControl = APIControlTest
SnAccount = TestSnAccount
DefaultLanguage = TestDefaultLanguage
ApiKey = TestApiKey
WalletKey = TestWalletKey
ControlKey = TestControlKey
AgentId = TestAgentId
SnId = TestSnId
2 months ago
if config.GetBase().Release {
API = APIRlease
APICreate = APICreateUserRlease
APIControl = APIControlRlease
SnAccount = ReleaseSnAccount
DefaultLanguage = ReleaseDefaultLanguage
ApiKey = ReleaseApiKey
WalletKey = ReleaseWalletKey
ControlKey = ReleaseControlKey
AgentId = ReleaseAgentId
SnId = ReleaseSnId
2 months ago
}
}
type EnterReq struct {
BaseReq
GameId int `json:"game_id"` // 游戏id
AgentId int `json:"agent_id"` // 代理id
ThirdName string `json:"third_name"` // 第三方昵称
ClientIp string `json:"client_ip"`
Language string `json:"language"` // 语言
}
type EnterResp struct {
Code int `json:"code"`
Success bool `json:"success"`
StatusCode int `json:"status_code"`
System int `json:"system"`
Msg string `json:"msg"`
Prompt string `json:"prompt"`
RequestId string `json:"request_id"`
RequestMethod string `json:"request_method"`
Provider string `json:"provider"`
Doc string `json:"doc"`
Data struct {
GameUrl string `json:"game_url"`
GameIdBase64 string `json:"game_id_base64"`
ApiGameBase64 string `json:"api_game_base64"`
ApiGameToken string `json:"api_game_token"`
Language string `json:"language"`
OrderIdList interface{} `json:"order_id_list"`
} `json:"data"`
}
type CreateUserReq struct {
BaseReq
ThirdName string `json:"third_name"`
AgentId int `json:"agent_id"`
UserType int `json:"user_type"`
}
type CreateUserResp struct {
Code int `json:"code"`
Msg string `json:"msg"`
Data struct {
OpenId int64 `json:"open_id"`
} `json:"data"`
}
func (s *Sub) EnterGame() string {
log.Debug("sn enter game, %+v", *s.Base.EnterGameReq)
providerID := s.Base.EnterGameReq.ProviderID
gameID := s.Base.EnterGameReq.GameID
game := call.GetGameListByByID(providerID, gameID)
if game == nil {
return ""
}
req := &EnterReq{
BaseReq: BaseReq{
SnAccount: SnAccount,
Time: time.Now().Unix(),
},
GameId: game.GameID,
AgentId: AgentId,
ThirdName: call.GetProviderUserName(fmt.Sprintf("%d", s.Base.UID)),
ClientIp: s.Base.IP,
Language: DefaultLanguage,
}
reqBody, _ := json.Marshal(req)
var tmpValue map[string]interface{}
json.Unmarshal(reqBody, &tmpValue)
req.Sign = GeneratedSign(tmpValue, ApiKey)
2 months ago
var resp EnterResp
err := util.HttpPost(API, req, &resp, nil)
if err != nil {
log.Error("err:%v", err)
return ""
}
if resp.Code == CodeRequestInvalidUser {
err = s.createUser()
if err != nil {
log.Error("create err, %s", err.Error())
return ""
}
return s.EnterGame()
}
if resp.Data.GameUrl == "" {
log.Error("err:%+v", resp)
return ""
}
return resp.Data.GameUrl
}
func (s *Sub) createUser() error {
log.Debug("sn create user, %+v", *s.Base.EnterGameReq)
req := &CreateUserReq{
BaseReq: BaseReq{
SnAccount: SnAccount,
Time: time.Now().Unix(),
},
AgentId: AgentId,
ThirdName: call.GetProviderUserName(fmt.Sprintf("%d", s.Base.UID)),
}
reqBody, _ := json.Marshal(req)
var tmpValue map[string]interface{}
json.Unmarshal(reqBody, &tmpValue)
req.Sign = GeneratedSign(tmpValue, ApiKey)
2 months ago
var resp CreateUserResp
err := util.HttpPost(APICreate, req, &resp, nil)
if err != nil {
log.Error("err:%v", err)
return err
}
if resp.Code != CodeRequestSuccess && resp.Code != CodeRequestExist {
log.Error("create uer err, %+v", resp)
return fmt.Errorf("create err, %+v ", resp)
}
return nil
}