Compare commits
No commits in common. "ade7ca2d03c21ad30ad374b36b75685bc4cfcda9" and "51e0eaec3342615e28ffe1c6ee8992270c6b9d81" have entirely different histories.
ade7ca2d03
...
51e0eaec33
@ -46,27 +46,6 @@ type Client struct {
|
|||||||
httpProxy string
|
httpProxy string
|
||||||
httpsProxy string
|
httpsProxy string
|
||||||
noProxy string
|
noProxy string
|
||||||
|
|
||||||
header *requests.RefererHeader
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Client) SetRefererHeader(header *requests.RefererHeader) {
|
|
||||||
c.header = header
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Client) GetRefererHeader() map[string]string {
|
|
||||||
var header *requests.RefererHeader
|
|
||||||
if c.header == nil {
|
|
||||||
header = &requests.RefererHeader{
|
|
||||||
TraceId: utils.MakeTraceId(),
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
header = c.header
|
|
||||||
}
|
|
||||||
return map[string]string{
|
|
||||||
"Referer": header.Referer,
|
|
||||||
"Traceparent": header.TraceId,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (client *Client) GetNoProxy() string {
|
func (client *Client) GetNoProxy() string {
|
||||||
@ -239,7 +218,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
|
||||||
|
@ -56,11 +56,6 @@ type Host struct {
|
|||||||
Func func(string) string
|
Func func(string) string
|
||||||
}
|
}
|
||||||
|
|
||||||
type RefererHeader struct {
|
|
||||||
Referer string
|
|
||||||
TraceId string
|
|
||||||
}
|
|
||||||
|
|
||||||
var debug utils.Debug
|
var debug utils.Debug
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -100,7 +95,6 @@ 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, any)
|
addJsonParam(string, any)
|
||||||
@ -232,12 +226,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
|
||||||
}
|
}
|
||||||
|
@ -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/gaore-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 {
|
||||||
@ -110,7 +114,3 @@ func Md5(data string) string {
|
|||||||
s := md5.Sum([]byte(data))
|
s := md5.Sum([]byte(data))
|
||||||
return hex.EncodeToString(s[:])
|
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,8 +1,6 @@
|
|||||||
package msdk
|
package msdk
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/requests"
|
|
||||||
"golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/utils"
|
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -22,17 +20,11 @@ func TestClient_GetUserAttr(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestGetIdfa(t *testing.T) {
|
func TestGetIdfa(t *testing.T) {
|
||||||
header := &requests.RefererHeader{
|
|
||||||
Referer: "https://www.gaore.com",
|
|
||||||
TraceId: utils.MakeTraceId(),
|
|
||||||
}
|
|
||||||
_ = header
|
|
||||||
client, err := NewClient()
|
client, err := NewClient()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
client.SetRefererHeader(header)
|
|
||||||
req := CreateGetIdfaReq()
|
req := CreateGetIdfaReq()
|
||||||
req.ChannelId = 1
|
req.ChannelId = 1
|
||||||
req.GameId = 3706
|
req.GameId = 3706
|
||||||
|
@ -63,7 +63,7 @@ func CreateGetIdfaReq() *GetIdfaReq {
|
|||||||
req := &GetIdfaReq{
|
req := &GetIdfaReq{
|
||||||
RpcRequest: &requests.RpcRequest{},
|
RpcRequest: &requests.RpcRequest{},
|
||||||
}
|
}
|
||||||
req.InitWithApiInfo(HOST, VERSION, "/getidfa.php")
|
req.InitWithApiInfo(HOST, VERSION, "/getIdfa.php")
|
||||||
req.Method = requests.GET
|
req.Method = requests.GET
|
||||||
return req
|
return req
|
||||||
}
|
}
|
||||||
@ -173,7 +173,7 @@ func CreateGetImeiReq() *GetImeiReq {
|
|||||||
req := &GetImeiReq{
|
req := &GetImeiReq{
|
||||||
RpcRequest: &requests.RpcRequest{},
|
RpcRequest: &requests.RpcRequest{},
|
||||||
}
|
}
|
||||||
req.InitWithApiInfo(HOST, VERSION, "/getimei.php")
|
req.InitWithApiInfo(HOST, VERSION, "/getImei.php")
|
||||||
req.Method = requests.GET
|
req.Method = requests.GET
|
||||||
return req
|
return req
|
||||||
}
|
}
|
||||||
@ -212,7 +212,7 @@ func CreateSetImeiReq() *SetImeiReq {
|
|||||||
req := &SetImeiReq{
|
req := &SetImeiReq{
|
||||||
RpcRequest: &requests.RpcRequest{},
|
RpcRequest: &requests.RpcRequest{},
|
||||||
}
|
}
|
||||||
req.InitWithApiInfo(HOST, VERSION, "/setimei.php")
|
req.InitWithApiInfo(HOST, VERSION, "/setImei.php")
|
||||||
req.Method = requests.GET
|
req.Method = requests.GET
|
||||||
return req
|
return req
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user