Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
abca5f01ed | ||
|
34de4b0401 | ||
|
71b93169e2 | ||
|
7dc4a177f9 | ||
|
9591e794f0 | ||
|
055fb8abb9 |
@ -6,7 +6,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
VERSION = "2025-04-27"
|
||||
VERSION = "2025-05-28"
|
||||
)
|
||||
|
||||
var HOST = requests.Host{
|
||||
@ -54,3 +54,24 @@ func (c *Client) GetProtocolByGameId(req *GetProtocolByGameIdRep) (resp *GetProt
|
||||
err = c.DoAction(req, resp)
|
||||
return
|
||||
}
|
||||
|
||||
// GetGameSimpleList 获取子游戏简单列表
|
||||
func (c *Client) GetGameSimpleList(req *GetGameSimpleListReq) (resp *GetGameSimpleListResp, err error) {
|
||||
resp = CreateGetGameSimpleListResp()
|
||||
err = c.DoAction(req, resp)
|
||||
return
|
||||
}
|
||||
|
||||
// GetGameServerV2 获取游戏服务器列表v2
|
||||
func (c *Client) GetGameServerV2(req *GetServerV2Request) (resp *GetServerV2Response, err error) {
|
||||
resp = CreateGetServerV2Response()
|
||||
err = c.DoAction(req, resp)
|
||||
return
|
||||
}
|
||||
|
||||
// GetGameCompany 获取单个根游戏信息
|
||||
func (c *Client) GetGameCompany(req *GetGameCompanyReq) (resp *GetGameCompanyResp, err error) {
|
||||
resp = CreateGetGameCompanyResp()
|
||||
err = c.DoAction(req, resp)
|
||||
return
|
||||
}
|
||||
|
@ -77,3 +77,46 @@ func TestGetProtocolByGameId(t *testing.T) {
|
||||
}
|
||||
fmt.Println(info)
|
||||
}
|
||||
|
||||
func TestGetGameSimpleList(t *testing.T) {
|
||||
client, err := NewClient()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
req := CreateGetGameSimpleListReq("8071,8062", "")
|
||||
info, err := client.GetGameSimpleList(req)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
fmt.Println(info)
|
||||
}
|
||||
|
||||
func TestGetGameServerV2(t *testing.T) {
|
||||
client, newErr := NewClient()
|
||||
if newErr != nil {
|
||||
panic(newErr)
|
||||
}
|
||||
req := CreateGetServerV2Request("n2", "", "")
|
||||
info, err := client.GetGameServerV2(req)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
fmt.Println(info)
|
||||
}
|
||||
|
||||
func TestGetGameCompany(t *testing.T) {
|
||||
client, err := NewClient()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
req := CreateGetGameCompanyReq("ascq")
|
||||
gameCompany, err := client.GetGameCompany(req)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
fmt.Println(gameCompany)
|
||||
fmt.Println(gameCompany.Data.System)
|
||||
}
|
||||
|
@ -162,3 +162,96 @@ func CreateGetGameInfoByIdResp() *GetGameInfoResp {
|
||||
BaseResponse: &responses.BaseResponse{},
|
||||
}
|
||||
}
|
||||
|
||||
type GetGameSimpleListReq struct {
|
||||
*requests.RpcRequest
|
||||
}
|
||||
|
||||
type GetGameSimpleListResp struct {
|
||||
*responses.BaseResponse
|
||||
Code int `json:"code"`
|
||||
Msg string `json:"msg"`
|
||||
Data map[string]GameSimple `json:"data"`
|
||||
}
|
||||
|
||||
type GameSimple struct {
|
||||
ID int `json:"id"`
|
||||
Name string `json:"name"`
|
||||
GameSign string `json:"game_sign"`
|
||||
}
|
||||
|
||||
// CreateGetGameSimpleListReq
|
||||
// gids 子游戏字符串,多个子游戏id用英文逗号分割
|
||||
// game_signs 根游戏标识字符串,多个标识用英文逗号分割
|
||||
func CreateGetGameSimpleListReq(gameIds string, gameSigns string) *GetGameSimpleListReq {
|
||||
req := &GetGameSimpleListReq{
|
||||
RpcRequest: &requests.RpcRequest{},
|
||||
}
|
||||
req.InitWithApiInfo(HOST, VERSION, "/api/game/getSimpleList")
|
||||
tmpParams := make(map[string]string)
|
||||
if gameIds != "" {
|
||||
tmpParams["gids"] = gameIds
|
||||
}
|
||||
if gameSigns != "" {
|
||||
tmpParams["game_signs"] = gameSigns
|
||||
}
|
||||
req.FormParams = tmpParams
|
||||
|
||||
req.Method = requests.POST
|
||||
return req
|
||||
}
|
||||
|
||||
func CreateGetGameSimpleListResp() *GetGameSimpleListResp {
|
||||
return &GetGameSimpleListResp{
|
||||
BaseResponse: &responses.BaseResponse{},
|
||||
}
|
||||
}
|
||||
|
||||
// GameCompany
|
||||
// 获取根游戏记录
|
||||
type GameCompany struct {
|
||||
Id int `json:"id"`
|
||||
GameSign string `json:"game_sign"`
|
||||
Name string `json:"name"`
|
||||
GameName string `json:"game_name"`
|
||||
ContractName string `json:"contract_name"`
|
||||
PayKey string `json:"pay_key"`
|
||||
LoginKey string `json:"login_key"`
|
||||
LoginUrlH5 string `json:"login_url_h5"`
|
||||
LoginUrlIos string `json:"login_url_ios"`
|
||||
LoginUrlAndroid string `json:"login_url_android"`
|
||||
PayUrl string `json:"pay_url"`
|
||||
Ext string `json:"ext"`
|
||||
Status int `json:"status"`
|
||||
Company string `json:"company"`
|
||||
System string `json:"system"`
|
||||
Sync int `json:"sync"`
|
||||
Type int `json:"type"`
|
||||
GameProductId int `json:"game_product_id"`
|
||||
}
|
||||
type GetGameCompanyReq struct {
|
||||
*requests.RpcRequest
|
||||
}
|
||||
type GetGameCompanyResp struct {
|
||||
*responses.BaseResponse
|
||||
Code int `json:"code"`
|
||||
Msg string `json:"msg"`
|
||||
Data GameCompany `json:"data"`
|
||||
}
|
||||
|
||||
func CreateGetGameCompanyReq(gameSign string) *GetGameCompanyReq {
|
||||
req := &GetGameCompanyReq{
|
||||
RpcRequest: &requests.RpcRequest{},
|
||||
}
|
||||
req.InitWithApiInfo(HOST, VERSION, "/api/game/getGameCompanyBySign")
|
||||
req.FormParams = map[string]string{
|
||||
"gameSign": gameSign,
|
||||
}
|
||||
req.Method = requests.POST
|
||||
return req
|
||||
}
|
||||
func CreateGetGameCompanyResp() *GetGameCompanyResp {
|
||||
return &GetGameCompanyResp{
|
||||
BaseResponse: &responses.BaseResponse{},
|
||||
}
|
||||
}
|
||||
|
107
services/game/game_server.go
Normal file
107
services/game/game_server.go
Normal file
@ -0,0 +1,107 @@
|
||||
package game
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/requests"
|
||||
"golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/responses"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
gameServerKey = "gaoreapi"
|
||||
)
|
||||
|
||||
// GetGameServerSign 子游戏区服信息,特有验签
|
||||
func GetGameServerSign(gameId int) (ts int64, sign string) {
|
||||
ts = time.Now().Unix()
|
||||
hash := md5.New()
|
||||
hash.Write([]byte(fmt.Sprintf("%v%v%v", gameId, ts, gameServerKey)))
|
||||
hashBytes := hash.Sum(nil)
|
||||
sign = hex.EncodeToString(hashBytes)
|
||||
return
|
||||
}
|
||||
|
||||
type GetServerIdRequest struct {
|
||||
*requests.RpcRequest
|
||||
}
|
||||
|
||||
type GetServerIdResponse struct {
|
||||
*responses.BaseResponse
|
||||
Code int `json:"code"`
|
||||
Msg string `json:"msg"`
|
||||
Data map[string]string `json:"data"`
|
||||
}
|
||||
|
||||
// CreateGetServerIdRequest
|
||||
// Deprecated 方法已废弃,不要用
|
||||
func CreateGetServerIdRequest(gameId int) (req *GetServerIdRequest) {
|
||||
req = &GetServerIdRequest{
|
||||
RpcRequest: &requests.RpcRequest{},
|
||||
}
|
||||
req.InitWithApiInfo(HOST, VERSION, "/api/game/getServerId")
|
||||
// 获取时间戳、签名
|
||||
ts, sign := GetGameServerSign(gameId)
|
||||
|
||||
req.FormParams = map[string]string{
|
||||
"appid": fmt.Sprintf("%v", gameId),
|
||||
"time": fmt.Sprintf("%v", ts),
|
||||
"sign": sign,
|
||||
}
|
||||
|
||||
req.Method = requests.POST
|
||||
return
|
||||
}
|
||||
|
||||
// CreateGetServerIdResponse
|
||||
// Deprecated 方法已废弃,不要用
|
||||
func CreateGetServerIdResponse() (response *GetServerIdResponse) {
|
||||
response = &GetServerIdResponse{
|
||||
BaseResponse: &responses.BaseResponse{},
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// --------------游戏区服v2列表查询----------
|
||||
|
||||
// GetServerV2Request 请求结构体
|
||||
type GetServerV2Request struct {
|
||||
*requests.RpcRequest
|
||||
}
|
||||
|
||||
type GetServerV2Response struct {
|
||||
*responses.BaseResponse
|
||||
Code int `json:"code"`
|
||||
Msg string `json:"msg"`
|
||||
Data []GameServerV2 `json:"data"`
|
||||
}
|
||||
|
||||
type GameServerV2 struct {
|
||||
ServerId int `json:"server_id"`
|
||||
Name string `json:"name"`
|
||||
GameSign string `json:"game_sign"`
|
||||
ServerSign int `json:"server_sign"`
|
||||
}
|
||||
|
||||
func CreateGetServerV2Request(gameSign string, serverSigns string, types string) (req *GetServerV2Request) {
|
||||
req = &GetServerV2Request{
|
||||
RpcRequest: &requests.RpcRequest{},
|
||||
}
|
||||
req.InitWithApiInfo(HOST, VERSION, "/api/game/getServerV2")
|
||||
|
||||
req.FormParams = map[string]string{
|
||||
"game_sign": gameSign,
|
||||
"server_signs": serverSigns,
|
||||
"types": types,
|
||||
}
|
||||
req.Method = requests.POST
|
||||
return
|
||||
}
|
||||
|
||||
func CreateGetServerV2Response() (response *GetServerV2Response) {
|
||||
response = &GetServerV2Response{
|
||||
BaseResponse: &responses.BaseResponse{},
|
||||
}
|
||||
return
|
||||
}
|
42
services/passport/client.go
Normal file
42
services/passport/client.go
Normal file
@ -0,0 +1,42 @@
|
||||
package passport
|
||||
|
||||
import (
|
||||
"golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk"
|
||||
"golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/requests"
|
||||
)
|
||||
|
||||
const (
|
||||
VERSION = "2025-05-28"
|
||||
// 对称加密密钥
|
||||
appKey = "#gr*%com#"
|
||||
)
|
||||
|
||||
var HOST requests.Host = requests.Host{
|
||||
Default: "passport.gaore.com",
|
||||
}
|
||||
|
||||
type Client struct {
|
||||
sdk.Client
|
||||
}
|
||||
|
||||
func NewClient() (client *Client, err error) {
|
||||
client = new(Client)
|
||||
err = client.Init()
|
||||
return
|
||||
}
|
||||
|
||||
// GetUserList
|
||||
// 获取用户列表
|
||||
func (c *Client) GetUserList(req *GetUserListRequest) (response *GetUserListResponse, err error) {
|
||||
response = CreateGetUserListResponse()
|
||||
err = c.DoAction(req, response)
|
||||
return
|
||||
}
|
||||
|
||||
// GetUserRoleList
|
||||
// 获取用户角色列表
|
||||
func (c *Client) GetUserRoleList(req *GetUserRoleListRequest) (response *GetUserRoleListResponse, err error) {
|
||||
response = CreateGetUserRoleListResponse()
|
||||
err = c.DoAction(req, response)
|
||||
return
|
||||
}
|
33
services/passport/client_test.go
Normal file
33
services/passport/client_test.go
Normal file
@ -0,0 +1,33 @@
|
||||
package passport
|
||||
|
||||
import "testing"
|
||||
|
||||
// 单元测试
|
||||
|
||||
func TestGetUserList(t *testing.T) {
|
||||
client, err := NewClient()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
req := CreateGetUserListRequest("ws45265737")
|
||||
resp, err := client.GetUserList(req)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
t.Logf("resp code:%+v", resp.Code)
|
||||
t.Logf("resp data:%+v", resp.Data)
|
||||
}
|
||||
|
||||
func TestGetUserRoleList(t *testing.T) {
|
||||
client, err := NewClient()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
req := CreateGetUserRoleListRequest(63610626, 2850)
|
||||
resp, err := client.GetUserRoleList(req)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
t.Logf("resp code:%+v", resp.Code)
|
||||
t.Logf("resp data:%+v", resp.Data)
|
||||
}
|
114
services/passport/userinfo.go
Normal file
114
services/passport/userinfo.go
Normal file
@ -0,0 +1,114 @@
|
||||
package passport
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/requests"
|
||||
"golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/responses"
|
||||
"time"
|
||||
)
|
||||
|
||||
type GetUserListRequest struct {
|
||||
*requests.RpcRequest
|
||||
}
|
||||
|
||||
type GetUserListResponse struct {
|
||||
*responses.BaseResponse
|
||||
Code int `json:"code"`
|
||||
Msg string `json:"msg"`
|
||||
Data []UserInfo `json:"data"`
|
||||
}
|
||||
|
||||
type UserInfo struct {
|
||||
UserName string `json:"user_name"` // 用户名
|
||||
Uid string `json:"uid"` // uid
|
||||
Telephone string `json:"telephone"` // 手机号
|
||||
}
|
||||
|
||||
// CreateGetUserListRequest 获取玩家用户列表
|
||||
func CreateGetUserListRequest(userName string) (req *GetUserListRequest) {
|
||||
ts, sign := GetSign()
|
||||
|
||||
req = &GetUserListRequest{
|
||||
RpcRequest: &requests.RpcRequest{},
|
||||
}
|
||||
req.InitWithApiInfo(HOST, VERSION, "/remote_login.php")
|
||||
req.FormParams = map[string]string{
|
||||
"act": "info",
|
||||
"do": "get_user_list",
|
||||
"user_names": userName,
|
||||
"time": fmt.Sprintf("%v", ts),
|
||||
"sign": sign,
|
||||
}
|
||||
|
||||
req.Method = requests.POST
|
||||
return
|
||||
}
|
||||
|
||||
func CreateGetUserListResponse() (response *GetUserListResponse) {
|
||||
response = &GetUserListResponse{
|
||||
BaseResponse: &responses.BaseResponse{},
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
type GetUserRoleListRequest struct {
|
||||
*requests.RpcRequest
|
||||
}
|
||||
|
||||
type GetUserRoleListResponse struct {
|
||||
*responses.BaseResponse
|
||||
Code int `json:"code"`
|
||||
Msg string `json:"msg"`
|
||||
Data []UserRoleInfo `json:"data"`
|
||||
}
|
||||
|
||||
type UserRoleInfo struct {
|
||||
Uid string `json:"uid"` // uid
|
||||
GameId string `json:"game_id"` // 子游戏id
|
||||
RoleId string `json:"role_id"` // 角色id
|
||||
RoleName string `json:"role_name"` // 角色名
|
||||
RoleServer string `json:"role_server"` // 角色服务器名
|
||||
AddTime string `json:"add_time"` // 创建时间戳
|
||||
UpdateTime string `json:"update_time"` // 更新时间戳
|
||||
}
|
||||
|
||||
// GetSign 封装一个方法,获取当天时间戳和api签名
|
||||
func GetSign() (ts int64, sign string) {
|
||||
ts = time.Now().Unix()
|
||||
hash := md5.New()
|
||||
hash.Write([]byte(fmt.Sprintf("%v%v", ts, appKey)))
|
||||
hashBytes := hash.Sum(nil)
|
||||
sign = hex.EncodeToString(hashBytes)
|
||||
return
|
||||
}
|
||||
|
||||
// CreateGetUserRoleListRequest 获取玩家角色列表
|
||||
func CreateGetUserRoleListRequest(uid int, gameId int) (req *GetUserRoleListRequest) {
|
||||
ts, sign := GetSign()
|
||||
|
||||
req = &GetUserRoleListRequest{
|
||||
RpcRequest: &requests.RpcRequest{},
|
||||
}
|
||||
req.InitWithApiInfo(HOST, VERSION, "/remote_login.php")
|
||||
req.FormParams = map[string]string{
|
||||
"act": "info",
|
||||
"do": "user_role",
|
||||
"method": "get",
|
||||
"uid": fmt.Sprintf("%d", uid),
|
||||
"game_id": fmt.Sprintf("%d", gameId),
|
||||
"time": fmt.Sprintf("%v", ts),
|
||||
"sign": sign,
|
||||
}
|
||||
|
||||
req.Method = requests.POST
|
||||
return
|
||||
}
|
||||
|
||||
func CreateGetUserRoleListResponse() (response *GetUserRoleListResponse) {
|
||||
response = &GetUserRoleListResponse{
|
||||
BaseResponse: &responses.BaseResponse{},
|
||||
}
|
||||
return
|
||||
}
|
Loading…
Reference in New Issue
Block a user