- 优化jdapi.signParams

This commit is contained in:
gazebo
2019-09-25 09:17:06 +08:00
parent afeb66b2d3
commit 0b44ea74e1
2 changed files with 9 additions and 7 deletions

View File

@@ -1,6 +1,7 @@
package jdapi
import (
"bytes"
"crypto/md5"
"encoding/json"
"fmt"
@@ -117,13 +118,14 @@ func (a *API) signParams(jdParams map[string]interface{}) string {
}
sort.Strings(keys)
allStr := a.appSecret
buf := &bytes.Buffer{}
buf.WriteString(a.appSecret)
for _, k := range keys {
allStr += k + fmt.Sprint(jdParams[k])
buf.WriteString(k)
buf.WriteString(fmt.Sprint(jdParams[k]))
}
allStr = allStr + a.appSecret
return fmt.Sprintf("%X", md5.Sum([]byte(allStr)))
buf.WriteString(a.appSecret)
return fmt.Sprintf("%X", md5.Sum(buf.Bytes()))
}
func New(token, appKey, appSecret string, config ...*platformapi.APIConfig) *API {