- 优化jdapi.signParams
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package jdapi
|
package jdapi
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"crypto/md5"
|
"crypto/md5"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
@@ -117,13 +118,14 @@ func (a *API) signParams(jdParams map[string]interface{}) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sort.Strings(keys)
|
sort.Strings(keys)
|
||||||
allStr := a.appSecret
|
buf := &bytes.Buffer{}
|
||||||
|
buf.WriteString(a.appSecret)
|
||||||
for _, k := range keys {
|
for _, k := range keys {
|
||||||
allStr += k + fmt.Sprint(jdParams[k])
|
buf.WriteString(k)
|
||||||
|
buf.WriteString(fmt.Sprint(jdParams[k]))
|
||||||
}
|
}
|
||||||
allStr = allStr + a.appSecret
|
buf.WriteString(a.appSecret)
|
||||||
|
return fmt.Sprintf("%X", md5.Sum(buf.Bytes()))
|
||||||
return fmt.Sprintf("%X", md5.Sum([]byte(allStr)))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(token, appKey, appSecret string, config ...*platformapi.APIConfig) *API {
|
func New(token, appKey, appSecret string, config ...*platformapi.APIConfig) *API {
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ func TestUpdateStoreInfo4Open(t *testing.T) {
|
|||||||
Operator: "test",
|
Operator: "test",
|
||||||
StationAddress: oldAddress + "T",
|
StationAddress: oldAddress + "T",
|
||||||
}
|
}
|
||||||
err = api.UpdateStoreInfo4Open2(params)
|
err = api.UpdateStoreInfo4Open2(params, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@@ -75,7 +75,7 @@ func TestUpdateStoreInfo4Open(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
params.StationAddress = oldAddress
|
params.StationAddress = oldAddress
|
||||||
api.UpdateStoreInfo4Open2(params)
|
api.UpdateStoreInfo4Open2(params, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user