This commit is contained in:
苏尹岚
2020-12-03 11:16:14 +08:00
parent 7108c05fb4
commit dc59cbd232
6 changed files with 75 additions and 7 deletions

View File

@@ -2,6 +2,7 @@ package ejyapi
import (
"crypto/md5"
"encoding/json"
"fmt"
"net/http"
"sort"
@@ -64,11 +65,18 @@ func (a *API) signParam(params map[string]interface{}) (sig string) {
return sig
}
func (a *API) AccessAPI(action string, url string, bizParams map[string]interface{}) (retVal map[string]interface{}, err error) {
func (a *API) AccessAPI(action string, url string, bizParams map[string]interface{}, isPost bool) (retVal map[string]interface{}, err error) {
data, _ := json.Marshal(bizParams)
fullURL := utils.GenerateGetURL(url, action, nil)
err = platformapi.AccessPlatformAPIWithRetry(a.client,
func() *http.Request {
request, _ := http.NewRequest(http.MethodGet, utils.GenerateGetURL(url, action, nil), nil)
var request *http.Request
if isPost {
request, _ = http.NewRequest(http.MethodPost, fullURL, strings.NewReader(string(data)))
request.Header.Set("Content-Type", "application/json")
} else {
request, _ = http.NewRequest(http.MethodGet, utils.GenerateGetURL(url, action, bizParams), nil)
}
return request
},
a.config,
@@ -118,11 +126,12 @@ type GetStationListResult struct {
Longitude string `json:"longitude"`
}
//获取油站列表
func (a *API) GetStationList() (getStationListResult []*GetStationListResult, err error) {
params := make(map[string]interface{})
// params["platformName"] = a.platformName
sign := a.signParam(params)
result, err := a.AccessAPI("oreo/ejiayou_open_api/stations/v2/"+a.platformName+"/"+sign+"/"+utils.Int64ToStr(a.timeStamp), Url, nil)
result, err := a.AccessAPI("oreo/ejiayou_open_api/stations/v2/"+a.platformName+"/"+sign+"/"+utils.Int64ToStr(a.timeStamp), Url, nil, false)
if err == nil {
utils.Map2StructByJson(result["data"], &getStationListResult, false)
}