-
Notifications
You must be signed in to change notification settings - Fork 20
/
body.go
34 lines (28 loc) · 602 Bytes
/
body.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
package alidayu
import (
"crypto/md5"
"fmt"
"io"
"io/ioutil"
"net/url"
"sort"
"strings"
)
func getRequestBody(m map[string]string) (reader io.Reader, size int64) {
var keys []string
for k := range m {
keys = append(keys, k)
}
sort.Strings(keys)
v := url.Values{}
signString := AppSecret
for _, k := range keys {
v.Set(k, m[k])
signString += k + m[k]
}
signString += AppSecret
signByte := md5.Sum([]byte(signString))
sign := strings.ToUpper(fmt.Sprintf("%x", signByte))
v.Set("sign", sign)
return ioutil.NopCloser(strings.NewReader(v.Encode())), int64(len(v.Encode()))
}