Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
156ea6409c | ||
10283347b6 | |||
67b30db9b4 | |||
daadddc8a2 | |||
9a2e21d646 | |||
710f74a50c | |||
f0fe02d420 |
@ -25,7 +25,13 @@ func signRpcRequest(request requests.AcsRequest, signer Signer) (err error) {
|
||||
stringToSign := buildRpcStringToSign(request)
|
||||
request.SetStringToSign(stringToSign)
|
||||
signature := signer.Sign(stringToSign, "&")
|
||||
accessKeyForm, err := signer.GetAccessKeyFrom()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if accessKeyForm != "" {
|
||||
request.GetQueryParams()["sign"] = signature
|
||||
}
|
||||
debug("GrSdk sign: %s", signature)
|
||||
debug("GrSdk sign string: %s", stringToSign)
|
||||
debug("GrSdk sign: \r\n")
|
||||
@ -38,7 +44,7 @@ func completeRpcSignParams(request requests.AcsRequest, signer Signer) (err erro
|
||||
if accessKeyFrom, err = signer.GetAccessKeyFrom(); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if accessKeyFrom != "" {
|
||||
queryParams := request.GetQueryParams()
|
||||
queryParams["access_time"] = fmt.Sprintf("%d", time.Now().Unix())
|
||||
queryParams["access_key"], err = signer.GetAccessKeyId()
|
||||
@ -47,9 +53,10 @@ func completeRpcSignParams(request requests.AcsRequest, signer Signer) (err erro
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
request.GetHeaders()["Gr-Sdk-From"] = accessKeyFrom
|
||||
}
|
||||
|
||||
request.GetHeaders()["Content-type"] = requests.Form
|
||||
request.GetHeaders()["Gr-Sdk-From"] = accessKeyFrom
|
||||
formString := utils.GetUrlFormedMap(request.GetFormParams())
|
||||
request.SetContent(bytes.NewBufferString(formString).Bytes())
|
||||
return
|
||||
|
@ -83,6 +83,15 @@ func (client *Client) InitClientConfig() (config *Config) {
|
||||
|
||||
}
|
||||
|
||||
func (client *Client) InitWithArea(area string, env ...string) error {
|
||||
config := client.InitClientConfig()
|
||||
if len(env) >= 1 {
|
||||
config.Env = env[0]
|
||||
}
|
||||
config.Area = area
|
||||
return client.InitWithOptions(config, new(credentials.BaseCredential))
|
||||
}
|
||||
|
||||
func (client *Client) InitWithAccessKey(accessKeyId, accessKeySecret, accessKeyFrom string) (err error) {
|
||||
config := client.InitWithConfig()
|
||||
credential := &credentials.BaseCredential{
|
||||
@ -279,6 +288,10 @@ func (client *Client) buildRequestWithSigner(request requests.AcsRequest, signer
|
||||
request.SetEnv(client.config.Env)
|
||||
}
|
||||
|
||||
if request.GetArea() == "" && client.config.Area != "" {
|
||||
request.SetArea(client.config.Area)
|
||||
}
|
||||
|
||||
err = requests.InitParam(request)
|
||||
if err != nil {
|
||||
return
|
||||
|
@ -15,6 +15,7 @@ type Config struct {
|
||||
Scheme string `default:"HTTP"`
|
||||
Timeout time.Duration `default:"5"`
|
||||
Env string `default:""`
|
||||
Area string `default:""`
|
||||
}
|
||||
|
||||
func NewConfig() *Config {
|
||||
|
71
sdk/requests/json_request.go
Normal file
71
sdk/requests/json_request.go
Normal file
@ -0,0 +1,71 @@
|
||||
package requests
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"golib.gaore.com/GaoreGo/haiwai-common-sdk-go/sdk/utils"
|
||||
"io"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type JsonRequest struct {
|
||||
*baseRequest
|
||||
}
|
||||
|
||||
func (request *JsonRequest) init() {
|
||||
request.baseRequest = defaultBaseRequest()
|
||||
request.baseRequest.AddHeaderParam("Content-Type", Json)
|
||||
request.Method = POST
|
||||
}
|
||||
|
||||
func (request *JsonRequest) BuildUrl() string {
|
||||
|
||||
var hostname string
|
||||
if request.Domain.Func == nil {
|
||||
hostname = request.Domain.Default
|
||||
} else if hostname = request.Domain.Func(request.GetEnv(), request.GetArea()); hostname == "" {
|
||||
hostname = request.Domain.Default
|
||||
}
|
||||
|
||||
url := fmt.Sprintf("%s://%s", strings.ToLower(request.Scheme), hostname)
|
||||
if len(request.Port) > 0 {
|
||||
url = fmt.Sprintf("%s:%s", url, request.Port)
|
||||
}
|
||||
return url + request.BuildQueries()
|
||||
}
|
||||
|
||||
func (request *JsonRequest) GetStyle() string {
|
||||
return STREAM
|
||||
}
|
||||
|
||||
func (request *JsonRequest) BuildQueries() string {
|
||||
path := strings.TrimLeft(strings.TrimSpace(request.GetActionName()), "/")
|
||||
mod := "&"
|
||||
if !strings.Contains(path, "?") {
|
||||
mod = "?"
|
||||
}
|
||||
request.queries = "/" + path + mod + utils.GetUrlFormedMap(request.QueryParams)
|
||||
return request.queries
|
||||
}
|
||||
|
||||
func (request *JsonRequest) GetActionName() string {
|
||||
return request.actionName
|
||||
}
|
||||
|
||||
func (request *JsonRequest) InitWithApiInfo(domain Host, version, urlPath string) {
|
||||
request.init()
|
||||
request.SetDomain(domain)
|
||||
request.version = version
|
||||
request.actionName = urlPath
|
||||
}
|
||||
|
||||
func (request *JsonRequest) GetBodyReader() io.Reader {
|
||||
if request.JsonParams != nil && len(request.JsonParams) > 0 {
|
||||
body, err := json.Marshal(request.JsonParams)
|
||||
if err == nil {
|
||||
return bytes.NewReader(body)
|
||||
}
|
||||
}
|
||||
return strings.NewReader("")
|
||||
}
|
@ -14,6 +14,7 @@ import (
|
||||
const (
|
||||
RPC = "RPC"
|
||||
ROA = "ROA"
|
||||
STREAM = "STREAM"
|
||||
|
||||
HTTP = "HTTP"
|
||||
HTTPS = "HTTPS"
|
||||
@ -39,6 +40,7 @@ const (
|
||||
Header = "Header"
|
||||
Query = "Query"
|
||||
Body = "Body"
|
||||
BodyJson = "Json"
|
||||
Path = "Path"
|
||||
|
||||
TEST = "TEST"
|
||||
@ -50,7 +52,7 @@ const (
|
||||
|
||||
type Host struct {
|
||||
Default string
|
||||
Func func(string) string
|
||||
Func func(string, string) string
|
||||
}
|
||||
|
||||
var debug utils.Debug
|
||||
@ -80,6 +82,8 @@ type AcsRequest interface {
|
||||
InitWithApiInfo(domain Host, version, urlPath string)
|
||||
GetEnv() string
|
||||
SetEnv(string)
|
||||
GetArea() string
|
||||
SetArea(string)
|
||||
|
||||
BuildUrl() string
|
||||
BuildQueries() string
|
||||
@ -94,6 +98,7 @@ type AcsRequest interface {
|
||||
AddHeaderParam(key, value string)
|
||||
addQueryParam(key, value string)
|
||||
addFormParam(key, value string)
|
||||
addJsonParam(string, interface{})
|
||||
}
|
||||
|
||||
type baseRequest struct {
|
||||
@ -117,10 +122,12 @@ type baseRequest struct {
|
||||
QueryParams map[string]string
|
||||
Headers map[string]string
|
||||
FormParams map[string]string
|
||||
JsonParams map[string]interface{}
|
||||
Content []byte
|
||||
|
||||
queries string
|
||||
stringToSign string
|
||||
area string
|
||||
}
|
||||
|
||||
func (request *baseRequest) GetEnv() string {
|
||||
@ -131,6 +138,14 @@ func (request *baseRequest) SetEnv(e string) {
|
||||
request.Env = e
|
||||
}
|
||||
|
||||
func (request *baseRequest) GetArea() string {
|
||||
return request.area
|
||||
}
|
||||
|
||||
func (request *baseRequest) SetArea(area string) {
|
||||
request.area = area
|
||||
}
|
||||
|
||||
func (request *baseRequest) GetStringToSign() string {
|
||||
return request.stringToSign
|
||||
}
|
||||
@ -229,6 +244,10 @@ func (request *baseRequest) addFormParam(key, val string) {
|
||||
request.FormParams[key] = val
|
||||
}
|
||||
|
||||
func (request *baseRequest) addJsonParam(key string, val interface{}) {
|
||||
request.JsonParams[key] = val
|
||||
}
|
||||
|
||||
func defaultBaseRequest() (request *baseRequest) {
|
||||
request = &baseRequest{
|
||||
Scheme: HTTP,
|
||||
@ -241,6 +260,7 @@ func defaultBaseRequest() (request *baseRequest) {
|
||||
"Accept-Encoding": Json,
|
||||
},
|
||||
FormParams: make(map[string]string),
|
||||
JsonParams: make(map[string]interface{}),
|
||||
}
|
||||
return
|
||||
}
|
||||
@ -289,14 +309,14 @@ func flatRepeatedList(reflectValue reflect.Value, request AcsRequest, position s
|
||||
value = fieldDefault
|
||||
}
|
||||
|
||||
err = addParam(request, fieldPosition, name, value)
|
||||
err = addParam(request, fieldPosition, name, value, reflectValue.Field(i).Interface())
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func addParam(request AcsRequest, position, key, value string) (err error) {
|
||||
func addParam(request AcsRequest, position, key, value string, vAny interface{}) (err error) {
|
||||
if len(value) > 0 {
|
||||
switch position {
|
||||
case Header:
|
||||
@ -305,6 +325,8 @@ func addParam(request AcsRequest, position, key, value string) (err error) {
|
||||
request.addQueryParam(key, value)
|
||||
case Body:
|
||||
request.addFormParam(key, value)
|
||||
case BodyJson:
|
||||
request.addJsonParam(key, vAny)
|
||||
default:
|
||||
errmsg := fmt.Sprintf("unsupport positions add param `%s`", position)
|
||||
err = errors.New(errmsg)
|
||||
|
@ -21,7 +21,7 @@ func (request *RpcRequest) BuildUrl() string {
|
||||
var hostname string
|
||||
if request.Domain.Func == nil {
|
||||
hostname = request.Domain.Default
|
||||
} else if hostname = request.Domain.Func(request.GetEnv()); hostname == "" {
|
||||
} else if hostname = request.Domain.Func(request.GetEnv(), request.GetArea()); hostname == "" {
|
||||
hostname = request.Domain.Default
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,7 @@ const (
|
||||
|
||||
var HOST requests.Host = requests.Host{
|
||||
Default: "c.api.gaore.com",
|
||||
Func: func(s string) string {
|
||||
Func: func(s string, area string) string {
|
||||
var a = map[string]string{
|
||||
requests.RELEASE: "c.api.gaore.com",
|
||||
requests.PRE: "c.api.gaore.com",
|
||||
|
@ -11,7 +11,7 @@ const (
|
||||
|
||||
var HOST requests.Host = requests.Host{
|
||||
Default: "callback.api.gaore.com",
|
||||
Func: func(s string) string {
|
||||
Func: func(s string, area string) string {
|
||||
var a = map[string]string{
|
||||
requests.RELEASE: "callback.api.gaore.com",
|
||||
requests.PRE: "callback.api.gaore.com",
|
||||
|
44
services/ip/client.go
Normal file
44
services/ip/client.go
Normal file
@ -0,0 +1,44 @@
|
||||
package ip
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"golib.gaore.com/GaoreGo/haiwai-common-sdk-go/sdk"
|
||||
"golib.gaore.com/GaoreGo/haiwai-common-sdk-go/sdk/requests"
|
||||
)
|
||||
|
||||
const (
|
||||
VERSION = "2025-06-24"
|
||||
)
|
||||
|
||||
var HOST = requests.Host{
|
||||
Default: "ip.gaore.com",
|
||||
Func: func(s string, area string) string {
|
||||
if area != "" {
|
||||
fmt.Println("ip.gaore.com." + area)
|
||||
return "ip.gaore.com." + area
|
||||
}
|
||||
return "ip.gaore.com.hk"
|
||||
},
|
||||
}
|
||||
|
||||
type Client struct {
|
||||
sdk.Client
|
||||
}
|
||||
|
||||
func NewClient(area string, env ...string) (client *Client, err error) {
|
||||
client = new(Client)
|
||||
err = client.InitWithArea(area, env...)
|
||||
return
|
||||
}
|
||||
|
||||
func (client *Client) CreateGetIpRequest(req *IpRequest) (resp *IpResponse, err error) {
|
||||
resp = CreateIpResponse()
|
||||
err = client.DoAction(req, resp)
|
||||
return
|
||||
}
|
||||
|
||||
func (client *Client) CreateGetIpsRequest(req *IpsRequest) (resp *IpsResponse, err error) {
|
||||
resp = CreateIpsResponse()
|
||||
err = client.DoAction(req, resp)
|
||||
return
|
||||
}
|
48
services/ip/client_test.go
Normal file
48
services/ip/client_test.go
Normal file
@ -0,0 +1,48 @@
|
||||
package ip
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// 测试获取单个ip地区信息
|
||||
func TestGetIp(t *testing.T) {
|
||||
client, newErr := NewClient("hk")
|
||||
if newErr != nil {
|
||||
panic(newErr)
|
||||
}
|
||||
req := CreateIpRequest(IpParam{
|
||||
Ip: "114.234.202.136",
|
||||
})
|
||||
res, doErr := client.CreateGetIpRequest(req)
|
||||
if doErr != nil {
|
||||
panic(doErr)
|
||||
}
|
||||
if res.Code != 0 {
|
||||
t.Error("查询多个ip失败")
|
||||
}
|
||||
fmt.Printf(fmt.Sprintf("%v", res))
|
||||
}
|
||||
|
||||
// 测试获取多个ip地区信息
|
||||
func TestGetIps(t *testing.T) {
|
||||
client, newErr := NewClient("hk")
|
||||
if newErr != nil {
|
||||
panic(newErr)
|
||||
}
|
||||
req := CreateIpsRequest(IpsParam{
|
||||
Ips: []string{
|
||||
"2001:ee0:5208:e600:4c51:3189:28a4:b668",
|
||||
"114.234.202.136",
|
||||
},
|
||||
})
|
||||
res, err := client.CreateGetIpsRequest(req)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
if res.Code != 0 {
|
||||
t.Error("查询多个ip失败")
|
||||
}
|
||||
fmt.Printf(fmt.Sprintf("%v", res))
|
||||
}
|
100
services/ip/ip.go
Normal file
100
services/ip/ip.go
Normal file
@ -0,0 +1,100 @@
|
||||
package ip
|
||||
|
||||
import (
|
||||
"golib.gaore.com/GaoreGo/haiwai-common-sdk-go/sdk/requests"
|
||||
"golib.gaore.com/GaoreGo/haiwai-common-sdk-go/sdk/responses"
|
||||
)
|
||||
|
||||
type IpInfo struct {
|
||||
Ip string `json:"ip"`
|
||||
City string `json:"city"`
|
||||
Province string `json:"province"`
|
||||
Country string `json:"country"`
|
||||
Isp string `json:"isp"`
|
||||
Owner string `json:"owner"`
|
||||
Continent string `json:"continent"`
|
||||
Accuracy string `json:"accuracy"`
|
||||
Adcode string `json:"adcode"`
|
||||
Areacode string `json:"areacode"`
|
||||
Asnumber string `json:"asnumber"`
|
||||
Radius string `json:"radius"`
|
||||
Latwgs string `json:"latwgs"`
|
||||
Lngwgs string `json:"lngwgs"`
|
||||
Source string `json:"source"`
|
||||
Timezone string `json:"timezone"`
|
||||
Zipcode string `json:"zipcode"`
|
||||
District string `json:"district"`
|
||||
}
|
||||
|
||||
// IpsParam
|
||||
// 单个ip请求参数
|
||||
type IpParam struct {
|
||||
Ip string `json:"ip"`
|
||||
}
|
||||
type IpRequest struct {
|
||||
*requests.JsonRequest
|
||||
Ip string `position:"Json" field:"ip"`
|
||||
}
|
||||
|
||||
// IpResponse
|
||||
// 单个ip返回参数
|
||||
type IpResponse struct {
|
||||
*responses.BaseResponse
|
||||
Code int `json:"code"`
|
||||
Msg string `json:"msg"`
|
||||
Data IpInfo `json:"data"`
|
||||
}
|
||||
|
||||
// CreateIpRequest
|
||||
// 同时支持ipv4、ipv6格式查询
|
||||
func CreateIpRequest(param IpParam) (req *IpRequest) {
|
||||
req = &IpRequest{
|
||||
JsonRequest: &requests.JsonRequest{},
|
||||
Ip: param.Ip,
|
||||
}
|
||||
req.InitWithApiInfo(HOST, VERSION, "/v1/getIp")
|
||||
req.Method = requests.POST
|
||||
return
|
||||
}
|
||||
func CreateIpResponse() (resp *IpResponse) {
|
||||
resp = &IpResponse{
|
||||
BaseResponse: &responses.BaseResponse{},
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// 多个ip请求参数
|
||||
type IpsParam struct {
|
||||
Ips []string `json:"ips"`
|
||||
}
|
||||
type IpsRequest struct {
|
||||
*requests.JsonRequest
|
||||
Ips []string `position:"Json" field:"ips"`
|
||||
}
|
||||
|
||||
// IpsResponse
|
||||
// 多个ip返回参数
|
||||
type IpsResponse struct {
|
||||
*responses.BaseResponse
|
||||
Code int `json:"code"`
|
||||
Msg string `json:"msg"`
|
||||
Data map[string]IpInfo `json:"data"`
|
||||
}
|
||||
|
||||
// CreateIpsRequest
|
||||
// 同时支持ipv4、ipv6格式查询
|
||||
func CreateIpsRequest(param IpsParam) (req *IpsRequest) {
|
||||
req = &IpsRequest{
|
||||
JsonRequest: &requests.JsonRequest{},
|
||||
Ips: param.Ips,
|
||||
}
|
||||
req.InitWithApiInfo(HOST, VERSION, "/v1/getIps")
|
||||
req.Method = requests.POST
|
||||
return
|
||||
}
|
||||
func CreateIpsResponse() (resp *IpsResponse) {
|
||||
resp = &IpsResponse{
|
||||
BaseResponse: &responses.BaseResponse{},
|
||||
}
|
||||
return
|
||||
}
|
@ -12,7 +12,7 @@ const (
|
||||
|
||||
var HOST requests.Host = requests.Host{
|
||||
Default: "jedi.api.gaore.com",
|
||||
Func: func(s string) string {
|
||||
Func: func(s string, area string) string {
|
||||
var a = map[string]string{
|
||||
requests.RELEASE: "jedi.api.gaore.com",
|
||||
requests.PRE: "jedi.api.gaore.com",
|
||||
|
@ -14,7 +14,7 @@ const (
|
||||
|
||||
var HOST requests.Host = requests.Host{
|
||||
Default: "mail.gaore.com",
|
||||
Func: func(s string) string {
|
||||
Func: func(s string, area string) string {
|
||||
var a = map[string]string{
|
||||
requests.RELEASE: "mail.gaore.com",
|
||||
requests.PRE: "mail.gaore.com",
|
||||
|
40
services/msdk/client.go
Normal file
40
services/msdk/client.go
Normal file
@ -0,0 +1,40 @@
|
||||
package msdk
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"golib.gaore.com/GaoreGo/haiwai-common-sdk-go/sdk"
|
||||
"golib.gaore.com/GaoreGo/haiwai-common-sdk-go/sdk/requests"
|
||||
)
|
||||
|
||||
const (
|
||||
VERSION = "2023-03-16"
|
||||
KEY = "gaore!@#msdk"
|
||||
)
|
||||
|
||||
var Host = requests.Host{
|
||||
Default: "msdk.api.gaore.com.hk",
|
||||
Func: func(s string, area string) string {
|
||||
if area != "" {
|
||||
fmt.Println("msdk.api.gaore.com." + area)
|
||||
return "msdk.api.gaore.com." + area
|
||||
}
|
||||
return "msdk.api.gaore.com.hk"
|
||||
},
|
||||
}
|
||||
|
||||
type Client struct {
|
||||
sdk.Client
|
||||
ident string
|
||||
}
|
||||
|
||||
func (c *Client) UpdateAdjustId(req *UpdateAdjustIdRequest) (resp *UpdateAdjustIdResponse, err error) {
|
||||
resp = CreateUpdateAdjustIdResponse()
|
||||
err = c.DoAction(req, resp)
|
||||
return
|
||||
}
|
||||
|
||||
func NewClient(area string, env ...string) (client *Client, err error) {
|
||||
client = new(Client)
|
||||
err = client.InitWithArea(area, env...)
|
||||
return
|
||||
}
|
25
services/msdk/client_test.go
Normal file
25
services/msdk/client_test.go
Normal file
@ -0,0 +1,25 @@
|
||||
package msdk
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestClient_UpdateAdjustId(t *testing.T) {
|
||||
|
||||
req := CreateUpdateAdjustIdRequest()
|
||||
req.AdjustId = "8834ca659b22316354e9e9d6dd6b1904"
|
||||
req.Username = "xn94941370"
|
||||
req.GameSign = "testcw"
|
||||
req.LongId = "ba19fc578664f7c73c424b4c2919f9d1"
|
||||
req.GameId = 10002
|
||||
req.RegTime = 1678949413
|
||||
req.Os = "ios"
|
||||
req.MakeSign()
|
||||
client, _ := NewClient("hk")
|
||||
resp, err := client.UpdateAdjustId(req)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
fmt.Println(resp.Msg)
|
||||
}
|
52
services/msdk/update_adjustid.go
Normal file
52
services/msdk/update_adjustid.go
Normal file
@ -0,0 +1,52 @@
|
||||
package msdk
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
"fmt"
|
||||
"golib.gaore.com/GaoreGo/haiwai-common-sdk-go/sdk/requests"
|
||||
"golib.gaore.com/GaoreGo/haiwai-common-sdk-go/sdk/responses"
|
||||
"time"
|
||||
)
|
||||
|
||||
type UpdateAdjustIdRequest struct {
|
||||
*requests.RpcRequest
|
||||
LongId string `position:"Body" field:"long_id" default:""`
|
||||
GameId int `position:"Body" field:"game_id" default:"0"`
|
||||
Username string `position:"Body" field:"username" default:""`
|
||||
GameSign string `position:"Body" field:"game_sign" default:""`
|
||||
RegTime int64 `position:"Body" field:"reg_time" default:"0"`
|
||||
Os string `position:"Body" field:"os" default:""`
|
||||
AdjustId string `position:"Body" field:"adjust_id" default:""`
|
||||
ts int64 `position:"Body" field:"ts" default:"0"`
|
||||
sign string `position:"Body" field:"sign" default:""`
|
||||
}
|
||||
|
||||
func (u *UpdateAdjustIdRequest) MakeSign() {
|
||||
u.ts = time.Now().Unix()
|
||||
rawStr := fmt.Sprintf("%d%s%s%d%s", u.GameId, u.LongId, u.Username, u.ts, KEY)
|
||||
sign := md5.Sum([]byte(rawStr))
|
||||
u.sign = fmt.Sprintf("%x", sign)
|
||||
}
|
||||
|
||||
type UpdateAdjustIdResponse struct {
|
||||
*responses.BaseResponse
|
||||
Ret int `json:"ret"`
|
||||
Msg string `json:"msg"`
|
||||
}
|
||||
|
||||
func CreateUpdateAdjustIdRequest() (req *UpdateAdjustIdRequest) {
|
||||
req = &UpdateAdjustIdRequest{
|
||||
RpcRequest: &requests.RpcRequest{},
|
||||
}
|
||||
req.ts = time.Now().Unix()
|
||||
req.InitWithApiInfo(Host, VERSION, "/updateAdjustId.php")
|
||||
req.Method = requests.POST
|
||||
return
|
||||
}
|
||||
|
||||
func CreateUpdateAdjustIdResponse() (resp *UpdateAdjustIdResponse) {
|
||||
resp = &UpdateAdjustIdResponse{
|
||||
BaseResponse: &responses.BaseResponse{},
|
||||
}
|
||||
return
|
||||
}
|
40
services/passport/client.go
Normal file
40
services/passport/client.go
Normal file
@ -0,0 +1,40 @@
|
||||
package passport
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"golib.gaore.com/GaoreGo/haiwai-common-sdk-go/sdk"
|
||||
"golib.gaore.com/GaoreGo/haiwai-common-sdk-go/sdk/requests"
|
||||
)
|
||||
|
||||
const (
|
||||
VERSION = "2023-04-18"
|
||||
KEY = "#gr*%com#"
|
||||
)
|
||||
|
||||
var Host = requests.Host{
|
||||
Default: "passport.gaore.com.hk",
|
||||
Func: func(s string, area string) string {
|
||||
if area != "" {
|
||||
fmt.Println("passport.gaore.com." + area)
|
||||
return "passport.gaore.com." + area
|
||||
}
|
||||
return "passport.gaore.com.hk"
|
||||
},
|
||||
}
|
||||
|
||||
type Client struct {
|
||||
sdk.Client
|
||||
ident string
|
||||
}
|
||||
|
||||
func (c *Client) GetRegDeviceByUsers(req *RegDeviceRequest) (resp *RegDeviceResponse, err error) {
|
||||
resp = CreateRegDeviceResponse()
|
||||
err = c.DoAction(req, resp)
|
||||
return
|
||||
}
|
||||
|
||||
func NewClient(area string, env ...string) (client *Client, err error) {
|
||||
client = new(Client)
|
||||
err = client.InitWithArea(area, env...)
|
||||
return
|
||||
}
|
21
services/passport/client_test.go
Normal file
21
services/passport/client_test.go
Normal file
@ -0,0 +1,21 @@
|
||||
package passport
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestInfo(t *testing.T) {
|
||||
client, err := NewClient("hk")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
req := CreateRegDeviceRequest("dv35054132", "zf43712598")
|
||||
|
||||
resp, err := client.GetRegDeviceByUsers(req)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
fmt.Println(resp.Data)
|
||||
}
|
63
services/passport/info.go
Normal file
63
services/passport/info.go
Normal file
@ -0,0 +1,63 @@
|
||||
package passport
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
"fmt"
|
||||
"golib.gaore.com/GaoreGo/haiwai-common-sdk-go/sdk/requests"
|
||||
"golib.gaore.com/GaoreGo/haiwai-common-sdk-go/sdk/responses"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type RegDeviceRequest struct {
|
||||
*requests.RpcRequest
|
||||
do string `position:"Body" field:"do" default:""`
|
||||
act string `position:"Body" field:"act" default:""`
|
||||
time int64 `position:"Body" field:"time" default:"0"`
|
||||
sign string `position:"Body" field:"sign" default:""`
|
||||
users string `position:"Body" field:"username" default:""`
|
||||
}
|
||||
|
||||
func (b *RegDeviceRequest) getSign() {
|
||||
b.time = time.Now().Unix()
|
||||
rawStr := fmt.Sprintf("%d%s", b.time, KEY)
|
||||
sign := md5.Sum([]byte(rawStr))
|
||||
b.sign = fmt.Sprintf("%x", sign)
|
||||
}
|
||||
|
||||
func (b *RegDeviceRequest) initRemoteLoginRequest() {
|
||||
b.InitWithApiInfo(Host, VERSION, "/remote_login.php")
|
||||
b.Method = requests.POST
|
||||
}
|
||||
|
||||
type RegDeviceResponse struct {
|
||||
*responses.BaseResponse
|
||||
Code int `json:"code"`
|
||||
Msg string `json:"msg"`
|
||||
Data []struct {
|
||||
DeviceId string `json:"imei"`
|
||||
Idfa string `json:"imei2"`
|
||||
ChannelDeviceId string `json:"channel_device_id"`
|
||||
Uid int64 `json:"uid"`
|
||||
UserName string `json:"user_name"`
|
||||
} `json:"data"`
|
||||
}
|
||||
|
||||
func CreateRegDeviceRequest(users ...string) (req *RegDeviceRequest) {
|
||||
req = &RegDeviceRequest{
|
||||
RpcRequest: &requests.RpcRequest{},
|
||||
}
|
||||
|
||||
req.getSign()
|
||||
req.users = strings.Join(users, ",")
|
||||
req.do = "get_reg_device_by_username"
|
||||
req.act = "info"
|
||||
req.initRemoteLoginRequest()
|
||||
return
|
||||
}
|
||||
|
||||
func CreateRegDeviceResponse() (resp *RegDeviceResponse) {
|
||||
return &RegDeviceResponse{
|
||||
BaseResponse: &responses.BaseResponse{},
|
||||
}
|
||||
}
|
@ -1,11 +1,8 @@
|
||||
package sso
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"golib.gaore.com/GaoreGo/haiwai-common-sdk-go/sdk"
|
||||
"golib.gaore.com/GaoreGo/haiwai-common-sdk-go/sdk/requests"
|
||||
"net/url"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -14,11 +11,11 @@ const (
|
||||
|
||||
var HOST = requests.Host{
|
||||
Default: "sso",
|
||||
Func: func(s string) string {
|
||||
Func: func(s string, area string) string {
|
||||
host := map[string]string{
|
||||
requests.RELEASE: "sso.gaore.com.hk",
|
||||
requests.PRE: "sso.gaore.com",
|
||||
requests.TEST: "sso.gaore.com",
|
||||
requests.PRE: "sso.gaore.com.hk",
|
||||
requests.TEST: "sso.gaore.com.hk",
|
||||
}
|
||||
if s, ok := host[s]; ok {
|
||||
return s
|
||||
@ -57,34 +54,6 @@ func (c *Client) SearchUser(req *SearchUserRequest) (response *SearchUserRespons
|
||||
return
|
||||
}
|
||||
|
||||
func (c *Client) GetLoginUrl(redirectUrl string, env ...string) string {
|
||||
uri := fmt.Sprintf("/admin/main/login?ident=%s&redirectUrl=%s", c.ident, url.QueryEscape(redirectUrl))
|
||||
scheme, host := c.getSchemeAndHost(env...)
|
||||
return fmt.Sprintf("%s://%s%s", scheme, host, uri)
|
||||
}
|
||||
|
||||
func (c *Client) GetLogout(env ...string) string {
|
||||
uri := fmt.Sprintf("/admin/main/logout?ident=%s&redirectUrl=", c.ident)
|
||||
scheme, host := c.getSchemeAndHost(env...)
|
||||
return fmt.Sprintf("%s://%s%s", scheme, host, uri)
|
||||
}
|
||||
|
||||
func (c Client) getSchemeAndHost(env ...string) (scheme, host string) {
|
||||
rEnv := requests.RELEASE
|
||||
if len(env) >= 1 {
|
||||
rEnv = env[0]
|
||||
}
|
||||
host = HOST.Func(rEnv)
|
||||
|
||||
if rEnv == requests.RELEASE {
|
||||
scheme = requests.HTTPS
|
||||
} else {
|
||||
scheme = requests.HTTP
|
||||
}
|
||||
scheme = strings.ToLower(scheme)
|
||||
return
|
||||
}
|
||||
|
||||
func NewClientWithAccessKey(accesskey, secrect, source string) (client *Client, err error) {
|
||||
client = &Client{}
|
||||
client.ident = source
|
||||
|
@ -1,11 +1,12 @@
|
||||
package sso
|
||||
|
||||
import (
|
||||
"golib.gaore.com/GaoreGo/haiwai-common-sdk-go/sdk/requests"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestLoginUrl(t *testing.T) {
|
||||
c, _ := NewClientWithAccessKey("stat.gaore.com.hk", "", "stat_gaore_com_hk")
|
||||
t.Log(c.GetLoginUrl("http://stat.gaore.com.hk/web/user/login", requests.TEST))
|
||||
t.Log(GetLoginUrl("stat.gaore.com.hk", "http://stat.gaore.com.hk/web/user/login"))
|
||||
}
|
||||
|
||||
func TestClient_CodeAuth(t *testing.T) {
|
||||
}
|
||||
|
27
services/sso/url.go
Normal file
27
services/sso/url.go
Normal file
@ -0,0 +1,27 @@
|
||||
package sso
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"golib.gaore.com/GaoreGo/haiwai-common-sdk-go/sdk/requests"
|
||||
"net/url"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func GetLoginUrl(ident string, redirectUrl string, env ...string) string {
|
||||
uri := fmt.Sprintf("/admin/main/login?ident=%s&redirectUrl=%s", ident, url.QueryEscape(redirectUrl))
|
||||
scheme, host := getSchemeAndHost(env...)
|
||||
return fmt.Sprintf("%s://%s%s", scheme, host, uri)
|
||||
}
|
||||
|
||||
func GetLogoutUrl(ident string, redirectUrl string, env ...string) string {
|
||||
uri := fmt.Sprintf("/admin/main/loginOut?ident=%s&redirectUrl=%s", ident, url.QueryEscape(redirectUrl))
|
||||
scheme, host := getSchemeAndHost(env...)
|
||||
return fmt.Sprintf("%s://%s%s", scheme, host, uri)
|
||||
}
|
||||
|
||||
func getSchemeAndHost(env ...string) (scheme, host string) {
|
||||
env = append(env, requests.RELEASE)
|
||||
host = HOST.Func(env[0], "")
|
||||
scheme = strings.ToLower(requests.HTTPS)
|
||||
return
|
||||
}
|
@ -6,18 +6,18 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
VERSION = "2020-09-24"
|
||||
VERSION = "2023-03-16"
|
||||
KEY = "gaore!@#apisdk"
|
||||
)
|
||||
|
||||
var HOST requests.Host = requests.Host{
|
||||
Default: "apisdk.9ooo.cn",
|
||||
Func: func(s string) string {
|
||||
var a = map[string]string{
|
||||
requests.RELEASE: "apisdk.9ooo.cn",
|
||||
requests.PRE: "apisdk.9ooo.cn",
|
||||
requests.TEST: "apisdk.9ooo.cn",
|
||||
Default: "apisdk.gaore.com.hk",
|
||||
Func: func(s string, area string) string {
|
||||
defHost := "apisdk.gaore.com"
|
||||
if area != "" {
|
||||
return defHost + "." + area
|
||||
}
|
||||
return a[s]
|
||||
return ""
|
||||
},
|
||||
}
|
||||
|
||||
@ -42,3 +42,15 @@ func (c *Client) GetUserInfo(req *GetPwdRequest) (response *GetPwdResponse, err
|
||||
err = c.DoAction(req, response)
|
||||
return
|
||||
}
|
||||
|
||||
func (c *Client) UpdateAdjustId(req *UpdateAdjustIdRequest) (resp *UpdateAdjustIdResponse, err error) {
|
||||
resp = CreateUpdateAdjustIdResponse()
|
||||
err = c.DoAction(req, resp)
|
||||
return
|
||||
}
|
||||
|
||||
func NewClient(area string, env ...string) (client *Client, err error) {
|
||||
client = new(Client)
|
||||
err = client.InitWithArea(area, env...)
|
||||
return
|
||||
}
|
||||
|
@ -23,3 +23,23 @@ func TestClient_GetUserInfo(t *testing.T) {
|
||||
fmt.Println(resp.GetHttpContentString())
|
||||
fmt.Println(resp.GetHttpHeaders())
|
||||
}
|
||||
|
||||
func TestClient_UpdateAdjustId(t *testing.T) {
|
||||
req := CreateUpdateAdjustIdRequest()
|
||||
req.AdjustId = "8834ca659b22316354e9e9d6dd6b1904"
|
||||
req.Username = "xn94941370"
|
||||
req.GameId = 10002
|
||||
req.RegTime = 1678949413
|
||||
req.MakeSign()
|
||||
c, err := NewClient("hk", "")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
resp, err := c.UpdateAdjustId(req)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
t.Log(resp)
|
||||
}
|
||||
|
@ -1 +0,0 @@
|
||||
package www
|
52
services/www/update_adjustid.go
Normal file
52
services/www/update_adjustid.go
Normal file
@ -0,0 +1,52 @@
|
||||
package www
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
"fmt"
|
||||
"golib.gaore.com/GaoreGo/haiwai-common-sdk-go/sdk/requests"
|
||||
"golib.gaore.com/GaoreGo/haiwai-common-sdk-go/sdk/responses"
|
||||
"time"
|
||||
)
|
||||
|
||||
type UpdateAdjustIdRequest struct {
|
||||
*requests.RpcRequest
|
||||
LongId string `position:"Body" field:"long_id" default:""`
|
||||
GameId int `position:"Body" field:"game_id" default:"0"`
|
||||
Username string `position:"Body" field:"username" default:""`
|
||||
GameSign string `position:"Body" field:"game_sign" default:""`
|
||||
RegTime int64 `position:"Body" field:"reg_time" default:"0"`
|
||||
Os string `position:"Body" field:"os" default:""`
|
||||
AdjustId string `position:"Body" field:"adjust_id" default:""`
|
||||
ts int64 `position:"Body" field:"ts" default:"0"`
|
||||
sign string `position:"Body" field:"sign" default:""`
|
||||
}
|
||||
|
||||
func (u *UpdateAdjustIdRequest) MakeSign() {
|
||||
u.ts = time.Now().Unix()
|
||||
rawStr := fmt.Sprintf("%s%d%d%s", u.Username, u.GameId, u.ts, KEY)
|
||||
sign := md5.Sum([]byte(rawStr))
|
||||
u.sign = fmt.Sprintf("%x", sign)
|
||||
}
|
||||
|
||||
type UpdateAdjustIdResponse struct {
|
||||
*responses.BaseResponse
|
||||
Ret int `json:"ret"`
|
||||
Msg string `json:"msg"`
|
||||
}
|
||||
|
||||
func CreateUpdateAdjustIdRequest() (req *UpdateAdjustIdRequest) {
|
||||
req = &UpdateAdjustIdRequest{
|
||||
RpcRequest: &requests.RpcRequest{},
|
||||
}
|
||||
req.ts = time.Now().Unix()
|
||||
req.InitWithApiInfo(HOST, VERSION, "/user/updateAdjustId.php")
|
||||
req.Method = requests.POST
|
||||
return
|
||||
}
|
||||
|
||||
func CreateUpdateAdjustIdResponse() (resp *UpdateAdjustIdResponse) {
|
||||
resp = &UpdateAdjustIdResponse{
|
||||
BaseResponse: &responses.BaseResponse{},
|
||||
}
|
||||
return
|
||||
}
|
Loading…
Reference in New Issue
Block a user