You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
778 B

package tipdw
import (
"crypto/md5"
"encoding/hex"
"fmt"
"net/url"
"sort"
"strings"
)
type reqLBS struct {
SK string
Path string
Args map[string]string
}
func (r *reqLBS) Encode() string {
r.Signature()
req := url.Values{}
for k, v := range r.Args {
req.Set(k, v)
}
return req.Encode()
}
func (r *reqLBS) Signature() {
if r.Args == nil {
r.Args = make(map[string]string)
}
var keys []string
for k := range r.Args {
keys = append(keys, k)
}
sort.Strings(keys)
var keyValue []string
for i := 0; i < len(keys); i++ {
keyValue = append(keyValue, fmt.Sprintf("%s=%s", keys[i], r.Args[keys[i]]))
}
signStr := r.Path + "?" + strings.Join(keyValue, "&") + r.SK
signMd5 := md5.Sum([]byte(signStr))
r.Args["sig"] = hex.EncodeToString(signMd5[:])
}