From 1faace6bce9f3ae9f72fa012ed8a7e349ce9ddbf Mon Sep 17 00:00:00 2001 From: xuyang Date: Thu, 19 Sep 2024 10:21:07 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E6=B8=B8=E6=88=8F=E4=B8=AD?= =?UTF-8?q?=E5=BF=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- services/script/client.go | 35 +++++++++++++++++++++++++++++ services/script/client_test.go | 21 +++++++++++++++++ services/script/script.go | 41 ++++++++++++++++++++++++++++++++++ 3 files changed, 97 insertions(+) create mode 100644 services/script/client.go create mode 100644 services/script/client_test.go create mode 100644 services/script/script.go diff --git a/services/script/client.go b/services/script/client.go new file mode 100644 index 0000000..69096a0 --- /dev/null +++ b/services/script/client.go @@ -0,0 +1,35 @@ +package script + +import ( + "golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk" + "golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/requests" +) + +const ( + VERSION = "2020-11-16" +) + +var HOST = requests.Host{ + Default: "script", +} + +type Client struct { + sdk.Client +} + +func NewClient() (client *Client, err error) { + client = new(Client) + err = client.Init() + return +} + +// OpenGame 同步到游戏中心 +func (c *Client) OpenGame(req *OpenGameReq) (resp *OpenGameResp, err error) { + resp = CreateOpenGameResp() + err = c.DoAction(req, resp) + if err != nil { + return + } + + return +} diff --git a/services/script/client_test.go b/services/script/client_test.go new file mode 100644 index 0000000..3834fe1 --- /dev/null +++ b/services/script/client_test.go @@ -0,0 +1,21 @@ +package script + +import ( + "fmt" + "testing" +) + +func TestOpenGame(t *testing.T) { + client, err := NewClient() + if err != nil { + panic(err) + } + req := CreateOpenGameReq(7275) + + resp, err := client.OpenGame(req) + if err != nil { + panic(err) + } + + fmt.Println(resp.Code, resp.Msg) +} diff --git a/services/script/script.go b/services/script/script.go new file mode 100644 index 0000000..30287f7 --- /dev/null +++ b/services/script/script.go @@ -0,0 +1,41 @@ +package script + +import ( + "encoding/json" + "fmt" + "golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/requests" + "golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/responses" +) + +type OpenGameReq struct { + *requests.RpcRequest +} + +type OpenGameResp struct { + *responses.BaseResponse +} + +// GetHttpContentBytes 因为http://script.gaore.com/open_game.php?game_id=这个接口返回的不是json,反序列化会报错,所以返回一个固定的json +func (baseResponse *OpenGameResp) GetHttpContentBytes() []byte { + b, _ := json.Marshal(map[string]interface{}{"code": 200, "msg": "success"}) + return b +} + +// CreateOpenGameReq 创建同步到游戏中心请求 +func CreateOpenGameReq(gameId int) *OpenGameReq { + req := &OpenGameReq{ + &requests.RpcRequest{}, + } + + req.InitWithApiInfo(HOST, VERSION, "open_game.php?game_id="+fmt.Sprintf("%v", gameId)) + req.Method = requests.POST + + return req +} + +// CreateOpenGameResp 创建同步到游戏中心响应 +func CreateOpenGameResp() *OpenGameResp { + return &OpenGameResp{ + BaseResponse: &responses.BaseResponse{}, + } +}