/
params.go
49 lines (44 loc) · 1.1 KB
/
params.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package pinduoduo
import (
"go.dtapp.net/gorequest"
"go.dtapp.net/gostring"
"sort"
"strconv"
"time"
)
func NewParamsWithType(_type string, params ...gorequest.Params) gorequest.Params {
p := gorequest.NewParamsWith(params...)
p.Set("type", _type)
p.Set("timestamp", strconv.FormatInt(time.Now().Unix(), 10))
for _, v := range params {
p.SetParams(v)
}
return p
}
func (c *Client) Sign(p gorequest.Params) {
p.Set("client_id", c.GetClientId())
// 排序所有的 key
var keys []string
for key := range p {
keys = append(keys, key)
}
sort.Strings(keys)
signStr := c.GetClientSecret()
for _, key := range keys {
signStr += key + gostring.GetString(p.Get(key))
}
signStr += c.GetClientSecret()
p.Set("sign", createSign(signStr))
}
func SetCustomParameters(p gorequest.Params, uid string, sid string) gorequest.Params {
p.Set("custom_parameters", map[string]interface{}{
"uid": uid,
"sid": sid,
})
return p
}
// SetGoodsSignList 设置商品goodsSign列表
func SetGoodsSignList(p gorequest.Params, goodsSign string) gorequest.Params {
p.Set("goods_sign_list", []string{goodsSign})
return p
}