- fixed dada callback sign error.
This commit is contained in:
@@ -56,6 +56,11 @@ type DadaCity struct {
|
||||
CityCode string `json:"cityCode"`
|
||||
}
|
||||
|
||||
type CancelReason struct {
|
||||
Id int `json:"id"`
|
||||
Reason string `json:"reason"`
|
||||
}
|
||||
|
||||
func NewDadaAPI(appKey, appSecret, sourceId, callbackURL string, isProd bool) *DadaAPI {
|
||||
api := &DadaAPI{
|
||||
appKey: appKey,
|
||||
@@ -75,15 +80,15 @@ func NewDadaAPI(appKey, appSecret, sourceId, callbackURL string, isProd bool) *D
|
||||
func (d *DadaAPI) signParams(mapData map[string]interface{}) string {
|
||||
keys := make([]string, 0)
|
||||
for k := range mapData {
|
||||
keys = append(keys, k)
|
||||
if k != signKey {
|
||||
keys = append(keys, k)
|
||||
}
|
||||
}
|
||||
sort.Strings(keys)
|
||||
|
||||
finalStr := d.appSecret
|
||||
for _, k := range keys {
|
||||
if k != signKey {
|
||||
finalStr += k + fmt.Sprint(mapData[k])
|
||||
}
|
||||
finalStr += k + fmt.Sprint(mapData[k])
|
||||
}
|
||||
|
||||
finalStr += d.appSecret
|
||||
@@ -162,3 +167,21 @@ func (d *DadaAPI) GetCities() (retVal []DadaCity, err error) {
|
||||
}
|
||||
return retVal, nil
|
||||
}
|
||||
|
||||
func (d *DadaAPI) GetCancelReasons() (retVal []CancelReason, err error) {
|
||||
result, err := d.AccessDada("api/order/cancel/reasons", nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
cites := result.Result.([]interface{})
|
||||
for _, v := range cites {
|
||||
v2 := v.(map[string]interface{})
|
||||
reason := CancelReason{
|
||||
Id: int(utils.MustInterface2Int64(v2["id"])),
|
||||
Reason: v2["reason"].(string),
|
||||
}
|
||||
retVal = append(retVal, reason)
|
||||
}
|
||||
return retVal, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user