jiayou
This commit is contained in:
@@ -26,14 +26,17 @@ type API struct {
|
||||
config *platformapi.APIConfig
|
||||
}
|
||||
|
||||
func New(platformName string, timeStamp int64, beforeKey, afterKey string, config ...*platformapi.APIConfig) *API {
|
||||
func (a *API) SetTimestamp(time int64) {
|
||||
a.timeStamp = time
|
||||
}
|
||||
|
||||
func New(platformName string, beforeKey, afterKey string, config ...*platformapi.APIConfig) *API {
|
||||
curConfig := platformapi.DefAPIConfig
|
||||
if len(config) > 0 {
|
||||
curConfig = *config[0]
|
||||
}
|
||||
return &API{
|
||||
platformName: platformName,
|
||||
timeStamp: timeStamp,
|
||||
beforeKey: beforeKey,
|
||||
afterKey: afterKey,
|
||||
client: &http.Client{Timeout: curConfig.ClientTimeout},
|
||||
@@ -55,7 +58,6 @@ func (a *API) signParam(params map[string]interface{}) (sig string) {
|
||||
valueList = append(valueList, fmt.Sprintf("beforeKey=%s", a.beforeKey))
|
||||
valueList = append(valueList, fmt.Sprintf("afterKey=%s", a.afterKey))
|
||||
sig = strings.Join(valueList, "&")
|
||||
fmt.Println(sig)
|
||||
binSig := md5.Sum([]byte(sig))
|
||||
sig = fmt.Sprintf("%X", binSig)
|
||||
return sig
|
||||
@@ -74,10 +76,10 @@ func (a *API) AccessAPI(action string, url string, bizParams map[string]interfac
|
||||
return platformapi.ErrLevelRecoverableErr, fmt.Errorf("mapData is nil")
|
||||
}
|
||||
if err == nil {
|
||||
if jsonResult1["error_response"] != nil {
|
||||
if utils.MustInterface2Int64(jsonResult1["code"]) != 200 {
|
||||
errLevel = platformapi.ErrLevelGeneralFail
|
||||
err = utils.NewErrorCode(jsonResult1["error_response"].(map[string]interface{})["zh_desc"].(string), jsonResult1["error_response"].(map[string]interface{})["code"].(string))
|
||||
baseapi.SugarLogger.Debugf("jdeclp AccessAPI failed, jsonResult1:%s", utils.Format4Output(jsonResult1, true))
|
||||
err = utils.NewErrorCode(jsonResult1["msg"].(string), utils.Int64ToStr(utils.MustInterface2Int64(jsonResult1["code"])))
|
||||
baseapi.SugarLogger.Debugf("ejiay AccessAPI failed, jsonResult1:%s", utils.Format4Output(jsonResult1, true))
|
||||
}
|
||||
retVal = jsonResult1
|
||||
}
|
||||
@@ -86,10 +88,42 @@ func (a *API) AccessAPI(action string, url string, bizParams map[string]interfac
|
||||
return retVal, err
|
||||
}
|
||||
|
||||
func (a *API) GetStationList() (err error) {
|
||||
type GetStationListResult struct {
|
||||
StationType int `json:"stationType"`
|
||||
Latitude string `json:"latitude"`
|
||||
StationBannerPic string `json:"stationBannerPic"`
|
||||
CityID int `json:"cityId"`
|
||||
ProvinceID int `json:"provinceId"`
|
||||
Adverts []interface{} `json:"adverts"`
|
||||
CityName string `json:"cityName"`
|
||||
Phone string `json:"phone"`
|
||||
StationPic string `json:"stationPic"`
|
||||
District string `json:"district"`
|
||||
InvoiceType int `json:"invoiceType"`
|
||||
StationName string `json:"stationName"`
|
||||
Location string `json:"location"`
|
||||
ProvinceName string `json:"provinceName"`
|
||||
Prices []struct {
|
||||
OilID string `json:"oilId"`
|
||||
StationPrice string `json:"stationPrice"`
|
||||
OilType string `json:"oilType"`
|
||||
DiscountPrice string `json:"discountPrice"`
|
||||
CountryPrice string `json:"countryPrice"`
|
||||
OilgunCodes []string `json:"oilgunCodes"`
|
||||
OilCode string `json:"oilCode"`
|
||||
} `json:"prices"`
|
||||
StarNum string `json:"starNum"`
|
||||
StationID string `json:"stationId"`
|
||||
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)
|
||||
_, err = a.AccessAPI("oreo/ejiayou_open_api/stations/v2/"+a.platformName+"/"+sign+"/"+utils.Int64ToStr(a.timeStamp), TestUrl, nil)
|
||||
return err
|
||||
result, err := a.AccessAPI("oreo/ejiayou_open_api/stations/v2/"+a.platformName+"/"+sign+"/"+utils.Int64ToStr(a.timeStamp), TestUrl, nil)
|
||||
if err == nil {
|
||||
utils.Map2StructByJson(result["data"], &getStationListResult, false)
|
||||
}
|
||||
return getStationListResult, err
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/baseapi"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
@@ -17,9 +18,14 @@ func init() {
|
||||
logger, _ := zap.NewDevelopment()
|
||||
sugarLogger = logger.Sugar()
|
||||
baseapi.Init(sugarLogger)
|
||||
api = New("1Zbve", time.Now().Unix(), "ymsrrxlZXlmglK6Q", "MYsFZGgwwprIahzQ")
|
||||
api = New("1Zbve", "ymsrrxlZXlmglK6Q", "MYsFZGgwwprIahzQ")
|
||||
api.SetTimestamp(time.Now().Unix())
|
||||
}
|
||||
|
||||
func TestGetStationList(t *testing.T) {
|
||||
api.GetStationList()
|
||||
result, err := api.GetStationList()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Log(utils.Format4Output(result, false))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user