- 优化jdapi.signParams
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -63,7 +63,7 @@ func TestUpdateStoreInfo4Open(t *testing.T) {
|
||||
Operator: "test",
|
||||
StationAddress: oldAddress + "T",
|
||||
}
|
||||
err = api.UpdateStoreInfo4Open2(params)
|
||||
err = api.UpdateStoreInfo4Open2(params, false)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -75,7 +75,7 @@ func TestUpdateStoreInfo4Open(t *testing.T) {
|
||||
}
|
||||
|
||||
params.StationAddress = oldAddress
|
||||
api.UpdateStoreInfo4Open2(params)
|
||||
api.UpdateStoreInfo4Open2(params, false)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user