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