Compare commits
No commits in common. "master" and "v1.0.3" have entirely different histories.
@ -44,27 +44,6 @@ type Client struct {
|
|||||||
httpProxy string
|
httpProxy string
|
||||||
httpsProxy string
|
httpsProxy string
|
||||||
noProxy string
|
noProxy string
|
||||||
|
|
||||||
header *requests.RefererHeader
|
|
||||||
}
|
|
||||||
|
|
||||||
func (client *Client) SetRefererHeader(header *requests.RefererHeader) {
|
|
||||||
client.header = header
|
|
||||||
}
|
|
||||||
|
|
||||||
func (client *Client) getRefererHeader() map[string]string {
|
|
||||||
var header *requests.RefererHeader
|
|
||||||
if client.header == nil {
|
|
||||||
header = &requests.RefererHeader{
|
|
||||||
TraceId: utils.MakeTraceId(),
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
header = client.header
|
|
||||||
}
|
|
||||||
return map[string]string{
|
|
||||||
"Referer": header.Referer,
|
|
||||||
"Traceparent": header.TraceId,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (client *Client) GetNoProxy() string {
|
func (client *Client) GetNoProxy() string {
|
||||||
@ -237,7 +216,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())
|
|
||||||
httpRequest, err := client.buildRequestWithSigner(request, signer)
|
httpRequest, err := client.buildRequestWithSigner(request, signer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
@ -1,71 +0,0 @@
|
|||||||
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,7 +14,6 @@ import (
|
|||||||
const (
|
const (
|
||||||
RPC = "RPC"
|
RPC = "RPC"
|
||||||
ROA = "ROA"
|
ROA = "ROA"
|
||||||
STREAM = "STREAM"
|
|
||||||
|
|
||||||
HTTP = "HTTP"
|
HTTP = "HTTP"
|
||||||
HTTPS = "HTTPS"
|
HTTPS = "HTTPS"
|
||||||
@ -40,7 +39,6 @@ const (
|
|||||||
Header = "Header"
|
Header = "Header"
|
||||||
Query = "Query"
|
Query = "Query"
|
||||||
Body = "Body"
|
Body = "Body"
|
||||||
BodyJson = "Json"
|
|
||||||
Path = "Path"
|
Path = "Path"
|
||||||
|
|
||||||
TEST = "TEST"
|
TEST = "TEST"
|
||||||
@ -55,11 +53,6 @@ type Host struct {
|
|||||||
Func func(string, string) string
|
Func func(string, string) string
|
||||||
}
|
}
|
||||||
|
|
||||||
type RefererHeader struct {
|
|
||||||
Referer string
|
|
||||||
TraceId string
|
|
||||||
}
|
|
||||||
|
|
||||||
var debug utils.Debug
|
var debug utils.Debug
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -101,10 +94,8 @@ type AcsRequest interface {
|
|||||||
GetBodyReader() io.Reader
|
GetBodyReader() io.Reader
|
||||||
|
|
||||||
AddHeaderParam(key, value string)
|
AddHeaderParam(key, value string)
|
||||||
AddHeaders(headers map[string]string)
|
|
||||||
addQueryParam(key, value string)
|
addQueryParam(key, value string)
|
||||||
addFormParam(key, value string)
|
addFormParam(key, value string)
|
||||||
addJsonParam(string, interface{})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type baseRequest struct {
|
type baseRequest struct {
|
||||||
@ -128,7 +119,6 @@ type baseRequest struct {
|
|||||||
QueryParams map[string]string
|
QueryParams map[string]string
|
||||||
Headers map[string]string
|
Headers map[string]string
|
||||||
FormParams map[string]string
|
FormParams map[string]string
|
||||||
JsonParams map[string]interface{}
|
|
||||||
Content []byte
|
Content []byte
|
||||||
|
|
||||||
queries string
|
queries string
|
||||||
@ -242,12 +232,6 @@ func (request *baseRequest) AddHeaderParam(key, val string) {
|
|||||||
request.Headers[key] = val
|
request.Headers[key] = val
|
||||||
}
|
}
|
||||||
|
|
||||||
func (request *baseRequest) AddHeaders(headers map[string]string) {
|
|
||||||
for key, val := range headers {
|
|
||||||
request.Headers[key] = val
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (request *baseRequest) addQueryParam(key, val string) {
|
func (request *baseRequest) addQueryParam(key, val string) {
|
||||||
request.QueryParams[key] = val
|
request.QueryParams[key] = val
|
||||||
}
|
}
|
||||||
@ -256,10 +240,6 @@ func (request *baseRequest) addFormParam(key, val string) {
|
|||||||
request.FormParams[key] = val
|
request.FormParams[key] = val
|
||||||
}
|
}
|
||||||
|
|
||||||
func (request *baseRequest) addJsonParam(key string, val interface{}) {
|
|
||||||
request.JsonParams[key] = val
|
|
||||||
}
|
|
||||||
|
|
||||||
func defaultBaseRequest() (request *baseRequest) {
|
func defaultBaseRequest() (request *baseRequest) {
|
||||||
request = &baseRequest{
|
request = &baseRequest{
|
||||||
Scheme: HTTP,
|
Scheme: HTTP,
|
||||||
@ -272,7 +252,6 @@ func defaultBaseRequest() (request *baseRequest) {
|
|||||||
"Accept-Encoding": Json,
|
"Accept-Encoding": Json,
|
||||||
},
|
},
|
||||||
FormParams: make(map[string]string),
|
FormParams: make(map[string]string),
|
||||||
JsonParams: make(map[string]interface{}),
|
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -321,14 +300,14 @@ func flatRepeatedList(reflectValue reflect.Value, request AcsRequest, position s
|
|||||||
value = fieldDefault
|
value = fieldDefault
|
||||||
}
|
}
|
||||||
|
|
||||||
err = addParam(request, fieldPosition, name, value, reflectValue.Field(i).Interface())
|
err = addParam(request, fieldPosition, name, value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func addParam(request AcsRequest, position, key, value string, vAny interface{}) (err error) {
|
func addParam(request AcsRequest, position, key, value string) (err error) {
|
||||||
if len(value) > 0 {
|
if len(value) > 0 {
|
||||||
switch position {
|
switch position {
|
||||||
case Header:
|
case Header:
|
||||||
@ -337,8 +316,6 @@ func addParam(request AcsRequest, position, key, value string, vAny interface{})
|
|||||||
request.addQueryParam(key, value)
|
request.addQueryParam(key, value)
|
||||||
case Body:
|
case Body:
|
||||||
request.addFormParam(key, value)
|
request.addFormParam(key, value)
|
||||||
case BodyJson:
|
|
||||||
request.addJsonParam(key, vAny)
|
|
||||||
default:
|
default:
|
||||||
errmsg := fmt.Sprintf("unsupport positions add param `%s`", position)
|
errmsg := fmt.Sprintf("unsupport positions add param `%s`", position)
|
||||||
err = errors.New(errmsg)
|
err = errors.New(errmsg)
|
||||||
|
|||||||
@ -1,69 +0,0 @@
|
|||||||
package random
|
|
||||||
|
|
||||||
import (
|
|
||||||
"math/rand"
|
|
||||||
"time"
|
|
||||||
"unsafe"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Mode int // 随机数模式
|
|
||||||
|
|
||||||
const (
|
|
||||||
Letter Mode = iota
|
|
||||||
Number
|
|
||||||
LetterNumber
|
|
||||||
LetterHex
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
|
||||||
numbers = "0123456789"
|
|
||||||
lettersHex = "0123456789abcdef"
|
|
||||||
letterIdBit = 6
|
|
||||||
letterIdxMask = 1<<letterIdBit - 1
|
|
||||||
letterIdxMax = 63 / letterIdBit
|
|
||||||
)
|
|
||||||
|
|
||||||
func StrRandom(n int64) string {
|
|
||||||
return Random(n, Letter)
|
|
||||||
}
|
|
||||||
|
|
||||||
func NumRandom(n int64) string {
|
|
||||||
return Random(n, Number)
|
|
||||||
}
|
|
||||||
|
|
||||||
func Random(n int64, mode ...Mode) string {
|
|
||||||
var baseStr string
|
|
||||||
mode = append(mode, LetterNumber)
|
|
||||||
switch mode[0] {
|
|
||||||
case LetterHex:
|
|
||||||
baseStr = lettersHex
|
|
||||||
case Letter:
|
|
||||||
baseStr = letters
|
|
||||||
case Number:
|
|
||||||
baseStr = numbers
|
|
||||||
case LetterNumber:
|
|
||||||
fallthrough
|
|
||||||
default:
|
|
||||||
baseStr = letters + numbers
|
|
||||||
}
|
|
||||||
return random(n, baseStr)
|
|
||||||
}
|
|
||||||
|
|
||||||
func random(n int64, baseStr string) string {
|
|
||||||
|
|
||||||
var src = rand.NewSource(time.Now().UnixNano())
|
|
||||||
b := make([]byte, n)
|
|
||||||
for i, cache, remain := n-1, src.Int63(), letterIdxMax; i >= 0; {
|
|
||||||
if remain == 0 {
|
|
||||||
cache, remain = src.Int63(), letterIdxMax
|
|
||||||
}
|
|
||||||
if idx := int(cache & letterIdxMask); idx < len(baseStr) {
|
|
||||||
b[i] = baseStr[idx]
|
|
||||||
i--
|
|
||||||
}
|
|
||||||
cache >>= letterIdBit
|
|
||||||
remain--
|
|
||||||
}
|
|
||||||
return *(*string)(unsafe.Pointer(&b))
|
|
||||||
}
|
|
||||||
@ -5,8 +5,8 @@ import (
|
|||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
"golib.gaore.com/GaoreGo/haiwai-common-sdk-go/sdk/utils/random"
|
|
||||||
"hash"
|
"hash"
|
||||||
|
rand2 "math/rand"
|
||||||
"net/url"
|
"net/url"
|
||||||
"reflect"
|
"reflect"
|
||||||
"sort"
|
"sort"
|
||||||
@ -36,7 +36,11 @@ func NewUUID() UUID {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func RandStringBytes(n int) string {
|
func RandStringBytes(n int) string {
|
||||||
return random.StrRandom(int64(n))
|
b := make([]byte, n)
|
||||||
|
for i := range b {
|
||||||
|
b[i] = letterBytes[rand2.Intn(len(letterBytes))]
|
||||||
|
}
|
||||||
|
return string(b)
|
||||||
}
|
}
|
||||||
|
|
||||||
func newFromHash(h hash.Hash, ns UUID, name string) UUID {
|
func newFromHash(h hash.Hash, ns UUID, name string) UUID {
|
||||||
@ -105,12 +109,3 @@ func InitStructWithDefaultTag(bean interface{}) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func Md5(data string) string {
|
|
||||||
s := md5.Sum([]byte(data))
|
|
||||||
return hex.EncodeToString(s[:])
|
|
||||||
}
|
|
||||||
|
|
||||||
func MakeTraceId() string {
|
|
||||||
return fmt.Sprintf("00-%s-%s-01", random.Random(32, random.LetterHex), random.Random(16, random.LetterHex))
|
|
||||||
}
|
|
||||||
|
|||||||
@ -1,44 +0,0 @@
|
|||||||
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.hk",
|
|
||||||
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
|
|
||||||
}
|
|
||||||
@ -1,48 +0,0 @@
|
|||||||
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))
|
|
||||||
}
|
|
||||||
@ -1,100 +0,0 @@
|
|||||||
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
|
|
||||||
}
|
|
||||||
@ -17,15 +17,15 @@ type UpdateAdjustIdRequest struct {
|
|||||||
RegTime int64 `position:"Body" field:"reg_time" default:"0"`
|
RegTime int64 `position:"Body" field:"reg_time" default:"0"`
|
||||||
Os string `position:"Body" field:"os" default:""`
|
Os string `position:"Body" field:"os" default:""`
|
||||||
AdjustId string `position:"Body" field:"adjust_id" default:""`
|
AdjustId string `position:"Body" field:"adjust_id" default:""`
|
||||||
Ts int64 `position:"Body" field:"ts" default:"0"`
|
ts int64 `position:"Body" field:"ts" default:"0"`
|
||||||
Sign string `position:"Body" field:"sign" default:""`
|
sign string `position:"Body" field:"sign" default:""`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *UpdateAdjustIdRequest) MakeSign() {
|
func (u *UpdateAdjustIdRequest) MakeSign() {
|
||||||
u.Ts = time.Now().Unix()
|
u.ts = time.Now().Unix()
|
||||||
rawStr := fmt.Sprintf("%d%s%s%d%s", u.GameId, u.LongId, u.Username, u.Ts, KEY)
|
rawStr := fmt.Sprintf("%d%s%s%d%s", u.GameId, u.LongId, u.Username, u.ts, KEY)
|
||||||
sign := md5.Sum([]byte(rawStr))
|
sign := md5.Sum([]byte(rawStr))
|
||||||
u.Sign = fmt.Sprintf("%x", sign)
|
u.sign = fmt.Sprintf("%x", sign)
|
||||||
}
|
}
|
||||||
|
|
||||||
type UpdateAdjustIdResponse struct {
|
type UpdateAdjustIdResponse struct {
|
||||||
@ -38,7 +38,7 @@ func CreateUpdateAdjustIdRequest() (req *UpdateAdjustIdRequest) {
|
|||||||
req = &UpdateAdjustIdRequest{
|
req = &UpdateAdjustIdRequest{
|
||||||
RpcRequest: &requests.RpcRequest{},
|
RpcRequest: &requests.RpcRequest{},
|
||||||
}
|
}
|
||||||
req.Ts = time.Now().Unix()
|
req.ts = time.Now().Unix()
|
||||||
req.InitWithApiInfo(Host, VERSION, "/updateAdjustId.php")
|
req.InitWithApiInfo(Host, VERSION, "/updateAdjustId.php")
|
||||||
req.Method = requests.POST
|
req.Method = requests.POST
|
||||||
return
|
return
|
||||||
|
|||||||
@ -3,27 +3,26 @@ package passport
|
|||||||
import (
|
import (
|
||||||
"crypto/md5"
|
"crypto/md5"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"golib.gaore.com/GaoreGo/haiwai-common-sdk-go/sdk/requests"
|
"golib.gaore.com/GaoreGo/haiwai-common-sdk-go/sdk/requests"
|
||||||
"golib.gaore.com/GaoreGo/haiwai-common-sdk-go/sdk/responses"
|
"golib.gaore.com/GaoreGo/haiwai-common-sdk-go/sdk/responses"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type RegDeviceRequest struct {
|
type RegDeviceRequest struct {
|
||||||
*requests.RpcRequest
|
*requests.RpcRequest
|
||||||
Do string `position:"Body" field:"do" default:""`
|
do string `position:"Body" field:"do" default:""`
|
||||||
Act string `position:"Body" field:"act" default:""`
|
act string `position:"Body" field:"act" default:""`
|
||||||
Time int64 `position:"Body" field:"time" default:"0"`
|
time int64 `position:"Body" field:"time" default:"0"`
|
||||||
Sign string `position:"Body" field:"sign" default:""`
|
sign string `position:"Body" field:"sign" default:""`
|
||||||
Users string `position:"Body" field:"username" default:""`
|
users string `position:"Body" field:"username" default:""`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *RegDeviceRequest) getSign() {
|
func (b *RegDeviceRequest) getSign() {
|
||||||
b.Time = time.Now().Unix()
|
b.time = time.Now().Unix()
|
||||||
rawStr := fmt.Sprintf("%d%s", b.Time, KEY)
|
rawStr := fmt.Sprintf("%d%s", b.time, KEY)
|
||||||
sign := md5.Sum([]byte(rawStr))
|
sign := md5.Sum([]byte(rawStr))
|
||||||
b.Sign = fmt.Sprintf("%x", sign)
|
b.sign = fmt.Sprintf("%x", sign)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *RegDeviceRequest) initRemoteLoginRequest() {
|
func (b *RegDeviceRequest) initRemoteLoginRequest() {
|
||||||
@ -50,9 +49,9 @@ func CreateRegDeviceRequest(users ...string) (req *RegDeviceRequest) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
req.getSign()
|
req.getSign()
|
||||||
req.Users = strings.Join(users, ",")
|
req.users = strings.Join(users, ",")
|
||||||
req.Do = "get_reg_device_by_username"
|
req.do = "get_reg_device_by_username"
|
||||||
req.Act = "info"
|
req.act = "info"
|
||||||
req.initRemoteLoginRequest()
|
req.initRemoteLoginRequest()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,8 +1,11 @@
|
|||||||
package sso
|
package sso
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"golib.gaore.com/GaoreGo/haiwai-common-sdk-go/sdk"
|
"golib.gaore.com/GaoreGo/haiwai-common-sdk-go/sdk"
|
||||||
"golib.gaore.com/GaoreGo/haiwai-common-sdk-go/sdk/requests"
|
"golib.gaore.com/GaoreGo/haiwai-common-sdk-go/sdk/requests"
|
||||||
|
"net/url"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -14,8 +17,8 @@ var HOST = requests.Host{
|
|||||||
Func: func(s string, area string) string {
|
Func: func(s string, area string) string {
|
||||||
host := map[string]string{
|
host := map[string]string{
|
||||||
requests.RELEASE: "sso.gaore.com.hk",
|
requests.RELEASE: "sso.gaore.com.hk",
|
||||||
requests.PRE: "sso.gaore.com.hk",
|
requests.PRE: "sso.gaore.com",
|
||||||
requests.TEST: "sso.gaore.com.hk",
|
requests.TEST: "sso.gaore.com",
|
||||||
}
|
}
|
||||||
if s, ok := host[s]; ok {
|
if s, ok := host[s]; ok {
|
||||||
return s
|
return s
|
||||||
@ -54,6 +57,34 @@ func (c *Client) SearchUser(req *SearchUserRequest) (response *SearchUserRespons
|
|||||||
return
|
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) {
|
func NewClientWithAccessKey(accesskey, secrect, source string) (client *Client, err error) {
|
||||||
client = &Client{}
|
client = &Client{}
|
||||||
client.ident = source
|
client.ident = source
|
||||||
|
|||||||
@ -1,11 +1,13 @@
|
|||||||
package sso
|
package sso
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"golib.gaore.com/GaoreGo/haiwai-common-sdk-go/sdk/requests"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestLoginUrl(t *testing.T) {
|
func TestLoginUrl(t *testing.T) {
|
||||||
t.Log(GetLoginUrl("stat.gaore.com.hk", "http://stat.gaore.com.hk/web/user/login"))
|
c, _ := NewClientWithAccessKey("stat.gaore.com.hk", "", "stat_gaore_com_hk")
|
||||||
|
t.Log(c.GetLoginUrl("http://stat.gaore.com.hk/web/user/login", requests.TEST))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestClient_CodeAuth(t *testing.T) {
|
func TestClient_CodeAuth(t *testing.T) {
|
||||||
|
|||||||
@ -1,27 +0,0 @@
|
|||||||
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
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue
Block a user