Compare commits
2 Commits
dee3b1ad0c
...
642aefcd16
| Author | SHA1 | Date | |
|---|---|---|---|
| 642aefcd16 | |||
| 1cab5442a2 |
@ -50,18 +50,18 @@ type Client struct {
|
||||
header *requests.RefererHeader
|
||||
}
|
||||
|
||||
func (c *Client) SetRefererHeader(header *requests.RefererHeader) {
|
||||
c.header = header
|
||||
func (client *Client) SetRefererHeader(header *requests.RefererHeader) {
|
||||
client.header = header
|
||||
}
|
||||
|
||||
func (c *Client) GetRefererHeader() map[string]string {
|
||||
func (client *Client) getRefererHeader() map[string]string {
|
||||
var header *requests.RefererHeader
|
||||
if c.header == nil {
|
||||
if client.header == nil {
|
||||
header = &requests.RefererHeader{
|
||||
TraceId: utils.MakeTraceId(),
|
||||
}
|
||||
} else {
|
||||
header = c.header
|
||||
header = client.header
|
||||
}
|
||||
return map[string]string{
|
||||
"Referer": header.Referer,
|
||||
@ -181,7 +181,7 @@ func (client *Client) ProcessCommonRequestWithSigner(request *requests.CommonReq
|
||||
panic("should not be here")
|
||||
}
|
||||
|
||||
func Timeout(connectTimeout time.Duration) func(ctx context.Context, net, addr string) (c net.Conn, err error) {
|
||||
func timeout(connectTimeout time.Duration) func(ctx context.Context, net, addr string) (c net.Conn, err error) {
|
||||
return func(ctx context.Context, network, address string) (c net.Conn, err error) {
|
||||
return (&net.Dialer{
|
||||
Timeout: connectTimeout,
|
||||
@ -194,11 +194,11 @@ func (client *Client) setTimeOut(request requests.AcsRequest) {
|
||||
readTimeout, connectTimeout := client.getTimeOut(request)
|
||||
client.httpClient.Timeout = readTimeout
|
||||
if trans, ok := client.httpClient.Transport.(*http.Transport); ok && trans != nil {
|
||||
trans.DialContext = Timeout(connectTimeout)
|
||||
trans.DialContext = timeout(connectTimeout)
|
||||
client.httpClient.Transport = trans
|
||||
} else if client.httpClient.Transport == nil {
|
||||
client.httpClient.Transport = &http.Transport{
|
||||
DialContext: Timeout(connectTimeout),
|
||||
DialContext: timeout(connectTimeout),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -239,7 +239,7 @@ func (client *Client) DoAction(request requests.AcsRequest, response responses.A
|
||||
}
|
||||
|
||||
func (client *Client) DoActionWithSigner(request requests.AcsRequest, response responses.AcsResponse, signer auth.Signer) (err error) {
|
||||
request.AddHeaders(client.GetRefererHeader())
|
||||
request.AddHeaders(client.getRefererHeader())
|
||||
httpRequest, err := client.buildRequestWithSigner(request, signer)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@ -277,6 +277,15 @@ func flatRepeatedList(reflectValue reflect.Value, request AcsRequest, position s
|
||||
reflectType := reflectValue.Type()
|
||||
for i := 0; i < reflectType.NumField(); i++ {
|
||||
field := reflectType.Field(i)
|
||||
|
||||
if field.Anonymous && field.Type.Kind() == reflect.Struct {
|
||||
err = flatRepeatedList(reflectValue.Field(i), request, "")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
name, isContiansNameTag := field.Tag.Lookup("field")
|
||||
|
||||
fieldPosition := position
|
||||
|
||||
@ -1,8 +1,10 @@
|
||||
package stat
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk"
|
||||
"golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/requests"
|
||||
"golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/responses"
|
||||
"time"
|
||||
)
|
||||
|
||||
@ -84,3 +86,24 @@ func (c *Client) GetGameServerCountData(req *GetGameServerCountDataReq) (resp *G
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (c *Client) UserReg(req *UserRegRequest) (resp *UserRegResponse, err error) {
|
||||
resp = &UserRegResponse{
|
||||
BaseResponse: &responses.BaseResponse{},
|
||||
}
|
||||
if req == nil {
|
||||
err = fmt.Errorf("request is nil")
|
||||
return
|
||||
}
|
||||
req.Electric = req.Battery
|
||||
err = c.DoAction(req, resp)
|
||||
return
|
||||
}
|
||||
|
||||
func (c *Client) UserLogin(req *UserLoginRequest) (resp *UserLoginResponse, err error) {
|
||||
resp = &UserLoginResponse{
|
||||
BaseResponse: &responses.BaseResponse{},
|
||||
}
|
||||
err = c.DoAction(req, resp)
|
||||
return
|
||||
}
|
||||
|
||||
@ -1,8 +1,10 @@
|
||||
package stat
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestSyncGameServerList(t *testing.T) {
|
||||
@ -135,3 +137,118 @@ func TestGetGameServerCountData(t *testing.T) {
|
||||
|
||||
fmt.Printf("%+v", resp.Data)
|
||||
}
|
||||
|
||||
func TestUserReg(t *testing.T) {
|
||||
|
||||
param := &UserRegParam{}
|
||||
// DeviceInfo 字段
|
||||
param.Network = "WiFi"
|
||||
param.ScreenResolution = "1920x1080"
|
||||
param.System = "Android 11"
|
||||
param.Electric = "80"
|
||||
param.ProcessorModel = "Snapdragon 888"
|
||||
param.BaseBand = "qualcomm"
|
||||
param.Model = "Xiaomi Mi 11"
|
||||
param.Battery = "80"
|
||||
param.Package = "com.game.test"
|
||||
param.LongId = "device_long_id_123456"
|
||||
param.Imei = "123456789012345"
|
||||
param.Oaid = "oaid_1234567890"
|
||||
param.Idfa = "idfa_1234567890"
|
||||
param.Idfv = "idfv_1234567890"
|
||||
param.AdDevice = "ad_device_info"
|
||||
param.Os = "Android"
|
||||
param.IP = "192.168.1.100"
|
||||
param.Ua = "Mozilla/5.0..."
|
||||
param.WxPlatform = "WeChat MiniProgram"
|
||||
param.Adinfo = "ad_info_data"
|
||||
|
||||
// UserRegparamuest 特有字段
|
||||
param.ChannelId = 1
|
||||
param.GameId = 7275
|
||||
param.LoginGameId = 7275
|
||||
param.GameSign = "qwldy"
|
||||
param.Uid = 123456
|
||||
param.UserName = "test_user"
|
||||
param.Openid = "123456"
|
||||
param.ComeBackUser = 1
|
||||
param.RegTime = time.Now().Unix()
|
||||
param.Logined = 1
|
||||
param.RegType = 1
|
||||
param.LpReg = 0
|
||||
param.MatchType = 1
|
||||
param.AgentId = 100
|
||||
param.SiteId = 1001
|
||||
param.PkgAgentId = 100
|
||||
param.PkgSiteId = 1001
|
||||
param.FromAd = 0
|
||||
param.FanCode = "FAN123456"
|
||||
param.InvalidUuid = 0
|
||||
req := CreateUserRegRequest(param)
|
||||
client, err := NewClient()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
resp, err := client.UserReg(req)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
t.Log(resp.Code)
|
||||
}
|
||||
|
||||
func TestUserLogin(t *testing.T) {
|
||||
param := &UserLoginParam{}
|
||||
// DeviceInfo 字段
|
||||
param.Network = "WiFi"
|
||||
param.ScreenResolution = "1920x1080"
|
||||
param.System = "Android 11"
|
||||
param.Electric = "80"
|
||||
param.ProcessorModel = "Snapdragon 888"
|
||||
param.BaseBand = "qualcomm"
|
||||
param.Model = "Xiaomi Mi 11"
|
||||
param.Battery = "80"
|
||||
param.Package = "com.game.test"
|
||||
param.LongId = "device_long_id_123456"
|
||||
param.Imei = "123456789012345"
|
||||
param.Oaid = "oaid_1234567890"
|
||||
param.Idfa = "idfa_1234567890"
|
||||
param.Idfv = "idfv_1234567890"
|
||||
param.AdDevice = "ad_device_info"
|
||||
param.Os = "Android"
|
||||
param.IP = "192.168.1.100"
|
||||
param.Ua = "Mozilla/5.0..."
|
||||
param.WxPlatform = "WeChat MiniProgram"
|
||||
param.Adinfo = "ad_info_data"
|
||||
|
||||
// UserRegparamuest 特有字段
|
||||
param.ChannelId = 1
|
||||
param.GameId = 7275
|
||||
param.GameSign = "qwldy"
|
||||
param.Uid = 123456
|
||||
param.UserName = "test_user"
|
||||
param.RegTime = time.Now().Unix()
|
||||
param.OriginalImei = param.Imei
|
||||
param.LoginTime = time.Now().Unix()
|
||||
param.LoginAgentId = 100
|
||||
param.LoginSiteId = 1001
|
||||
param.PkgAgentId = 100
|
||||
param.PkgSiteId = 1001
|
||||
param.Version = "2.7.1"
|
||||
b, err := json.Marshal(param)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Log(string(b))
|
||||
req := CreateUserLoginRequest(param)
|
||||
client, err := NewClient()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
resp, err := client.UserLogin(req)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Log(resp.Code, resp.Data)
|
||||
}
|
||||
|
||||
@ -113,3 +113,121 @@ func CreateUserRoleRegPageResp() *UserRoleRegResp {
|
||||
BaseResponse: &responses.BaseResponse{},
|
||||
}
|
||||
}
|
||||
|
||||
type DeviceInfo struct {
|
||||
Network string `position:"Body" field:"network" default:"" json:"network"`
|
||||
ScreenResolution string `position:"Body" field:"screen_resolution" default:"" json:"screen_resolution"`
|
||||
System string `position:"Body" field:"system" default:"" json:"system"`
|
||||
Electric string `position:"Body" field:"electric" default:"" json:"electric"`
|
||||
ProcessorModel string `position:"Body" field:"processor_model" default:"" json:"processor_model"`
|
||||
BaseBand string `position:"Body" field:"baseband" default:"" json:"baseband"`
|
||||
Model string `position:"Body" field:"model" default:"" json:"model"`
|
||||
Battery string `position:"Body" field:"battery" default:"" json:"battery"`
|
||||
Package string `position:"Body" field:"package" default:"" json:"package"`
|
||||
LongId string `position:"Body" field:"long_id" default:"" json:"long_id"`
|
||||
Imei string `position:"Body" field:"imei" default:"" json:"imei"`
|
||||
Oaid string `position:"Body" field:"oaid" default:"" json:"oaid"`
|
||||
Idfa string `position:"Body" field:"idfa" default:"" json:"idfa"`
|
||||
Idfv string `position:"Body" field:"idfv" default:"" json:"idfv"`
|
||||
AdDevice string `position:"Body" field:"ad_device" default:"" json:"ad_device"`
|
||||
Os string `position:"Body" field:"os" default:"" json:"os"`
|
||||
IP string `position:"Body" field:"ip" default:"" json:"ip"`
|
||||
Ua string `position:"Body" field:"ua" default:"" json:"ua"`
|
||||
WxPlatform string `position:"Body" field:"wx_platform" default:"" json:"wx_platform"`
|
||||
Adinfo string `position:"Body" field:"adinfo" default:"" json:"adinfo"`
|
||||
}
|
||||
|
||||
type UserRegParam struct {
|
||||
DeviceInfo
|
||||
ChannelId int64 `position:"Body" field:"mtype" default:"1" json:"mtype"`
|
||||
GameId int64 `position:"Body" field:"game_id" default:"0" json:"game_id"`
|
||||
LoginGameId int64 `position:"Body" field:"login_game_id" default:"0" json:"login_game_id"`
|
||||
GameSign string `position:"Body" field:"game_sign" default:"" json:"game_sign"`
|
||||
Uid int64 `position:"Body" field:"uid" default:"0" json:"uid"`
|
||||
UserName string `position:"Body" field:"user_name" default:"" json:"user_name"`
|
||||
Openid string `position:"Body" field:"openid" default:"" json:"openid"`
|
||||
Phone string `position:"Body" field:"mobile_phone" default:"" json:"mobile_phone"`
|
||||
ComeBackUser int64 `position:"Body" field:"come_back_user" default:"0" json:"come_back_user"`
|
||||
RegTime int64 `position:"Body" field:"reg_time" default:"" json:"reg_time"`
|
||||
Logined int64 `position:"Body" field:"logined" default:"1" json:"logined"`
|
||||
RegType int64 `position:"Body" field:"reg_type" default:"" json:"reg_type"`
|
||||
LpReg int64 `position:"Body" field:"lp_reg" default:"0" json:"lp_reg"`
|
||||
MatchType int64 `position:"Body" field:"match_type" default:"0" json:"match_type"`
|
||||
AgentId int64 `position:"Body" field:"agent_id" default:"100" json:"agent_id"`
|
||||
SiteId int64 `position:"Body" field:"site_id" default:"1001" json:"site_id"`
|
||||
PkgAgentId int64 `position:"Body" field:"pkg_agent_id" default:"0" json:"pkg_agent_id"`
|
||||
PkgSiteId int64 `position:"Body" field:"pkg_site_id" default:"0" json:"pkg_site_id"`
|
||||
FromAd int64 `position:"Body" field:"from_ad" default:"0" json:"from_ad"`
|
||||
FanCode string `position:"Body" field:"fan_code" default:"" json:"fan_code"`
|
||||
InvalidUuid int64 `position:"Body" field:"invalid_uuid" default:"0" json:"invalid_uuid"`
|
||||
}
|
||||
|
||||
type UserRegRequest struct {
|
||||
*requests.RpcRequest
|
||||
UserRegParam
|
||||
}
|
||||
|
||||
type UserRegResponse struct {
|
||||
*responses.BaseResponse
|
||||
Code int64 `json:"code"`
|
||||
Msg string `json:"msg"`
|
||||
Data struct {
|
||||
Result any `json:"result,omitempty"`
|
||||
RegNum int64 `json:"reg_num,omitempty"`
|
||||
} `json:"data"`
|
||||
}
|
||||
|
||||
func CreateUserRegRequest(param *UserRegParam) *UserRegRequest {
|
||||
req := &UserRegRequest{
|
||||
RpcRequest: &requests.RpcRequest{},
|
||||
UserRegParam: *param,
|
||||
}
|
||||
req.InitWithApiInfo(HOST, VERSION, "/user/reg")
|
||||
req.Method = requests.POST
|
||||
return req
|
||||
}
|
||||
|
||||
type UserLoginParam struct {
|
||||
DeviceInfo
|
||||
ChannelId int64 `position:"Body" field:"mtype" default:"0" json:"mtype"`
|
||||
GameId int64 `position:"Body" field:"game_id" default:"0" json:"game_id"`
|
||||
GameSign string `position:"Body" field:"game_sign" default:"" json:"game_sign"`
|
||||
Version string `position:"Body" field:"version" default:"" json:"version"`
|
||||
UserName string `position:"Body" field:"user_name" default:"" json:"user_name"`
|
||||
Uid int64 `position:"Body" field:"uid" default:"0" json:"uid"`
|
||||
RegTime int64 `position:"Body" field:"reg_time" default:"0" json:"reg_time"`
|
||||
LoginTime int64 `position:"Body" field:"login_time" default:"0" json:"login_time"`
|
||||
LoginAgentId int64 `position:"Body" field:"login_agent_id" default:"0" json:"login_agent_id"`
|
||||
LoginSiteId int64 `position:"Body" field:"login_site_id" default:"0" json:"login_site_id"`
|
||||
PkgAgentId int64 `position:"Body" field:"pkg_agent_id" default:"0" json:"pkg_agent_id"`
|
||||
PkgSiteId int64 `position:"Body" field:"pkg_site_id" default:"0" json:"pkg_site_id"`
|
||||
FromAd int64 `position:"Body" field:"from_ad" default:"0" json:"from_ad"`
|
||||
CpData string `position:"Body" field:"cp_data" default:"" json:"cp_data"`
|
||||
OriginalImei string `position:"Body" field:"originalimei" default:"" json:"originalimei"`
|
||||
InvalidUuid int64 `position:"Body" field:"invalid_uuid" default:"0" json:"invalid_uuid"`
|
||||
ServerId int64 `position:"Body" field:"server_id" default:"1" json:"server_id"`
|
||||
}
|
||||
|
||||
type UserLoginRequest struct {
|
||||
*requests.RpcRequest
|
||||
UserLoginParam
|
||||
}
|
||||
|
||||
type UserLoginResponse struct {
|
||||
*responses.BaseResponse
|
||||
Code int64 `json:"code"`
|
||||
Msg string `json:"msg"`
|
||||
Data struct {
|
||||
Result any `json:"result,omitempty"`
|
||||
} `json:"data"`
|
||||
}
|
||||
|
||||
func CreateUserLoginRequest(param *UserLoginParam) *UserLoginRequest {
|
||||
req := &UserLoginRequest{
|
||||
RpcRequest: &requests.RpcRequest{},
|
||||
UserLoginParam: *param,
|
||||
}
|
||||
req.InitWithApiInfo(HOST, VERSION, "/user/login")
|
||||
req.Method = requests.POST
|
||||
return req
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user