拉取门店

This commit is contained in:
renyutian
2019-04-30 18:23:46 +08:00
parent ba0f084609
commit 7999d11d8d
3 changed files with 105 additions and 3 deletions

View File

@@ -22,8 +22,9 @@ const (
)
const (
ResponseCodeSuccess = 0
ResponseCodeCallElmFailed = 2101 // 这个可以尝试重试
ResponseCodeSuccess = 0
GetStoreSuccessButUnderfind = 4001 // 拉取网页饿百门店信息,但是显示门店不存在
ResponseCodeCallElmFailed = 2101 // 这个可以尝试重试
)
type ResponseResult struct {

View File

@@ -11,7 +11,8 @@ import (
)
const (
storeURL = "https://be.ele.me"
storeURL = "https://be.ele.me"
getStoreURL = "https://newretail.ele.me"
)
const (
@@ -254,3 +255,69 @@ func (a *API) PageGetCustomCatList(baiduShopID int64) (catList []map[string]inte
}
return nil, err
}
func (a *API) GetStoreInfo(storeId string) (storeInfo map[string]interface{}, err error) {
retVal, err := a.AccessStorePage2(storeId)
if err != nil {
return nil, err
}
return retVal, err
}
func (a *API) AccessStorePage2(storeId string) (retVal map[string]interface{}, err error) {
subURL := fmt.Sprintf("newretail/shop/getshopinfo?&lat=0&lng=0&shop_id=%s", storeId)
err = platformapi.AccessPlatformAPIWithRetry(a.client,
func() *http.Request {
fullURL := utils.GenerateGetURL(getStoreURL, subURL, nil)
request, _ := http.NewRequest(http.MethodGet, fullURL, nil)
if err != nil {
return nil
}
return request
},
a.config,
func(jsonResult1 map[string]interface{}) (errLevel string, err error) {
code := int(utils.MustInterface2Int64(jsonResult1["error_no"]))
if code == ResponseCodeSuccess {
retVal = jsonResult1["result"].(map[string]interface{})
retVal["shop_id"] = storeId
return platformapi.ErrLevelSuccess, nil
} else if code == GetStoreSuccessButUnderfind {
retVal = make(map[string]interface{})
retVal["shop_id"] = storeId
retVal["storeIsUnderfind"] = 1
return platformapi.ErrLevelSuccess, nil
}
newErr := utils.NewErrorIntCode(jsonResult1["error_msg"].(string), code)
return platformapi.ErrLevelCodeIsNotOK, newErr
})
return retVal, err
}
func (a *API) GetStoreList(lng string, lat string) (retVal map[string]interface{}, err error) {
retVal, err = a.AccessStorePage3(fmt.Sprintf("/newretail/main/shoplist?channel=kitchen&pn=1&rn=999&lng=%s&lat=%s", lng, lat))
return retVal, err
}
func (a *API) AccessStorePage3(subURL string) (retVal map[string]interface{}, err error) {
err = platformapi.AccessPlatformAPIWithRetry(a.client,
func() *http.Request {
fullURL := utils.GenerateGetURL(getStoreURL, subURL, nil)
request, _ := http.NewRequest(http.MethodGet, fullURL, nil)
if err != nil {
return nil
}
return request
},
a.config,
func(jsonResult1 map[string]interface{}) (errLevel string, err error) {
code := int(utils.MustInterface2Int64(jsonResult1["error_no"]))
if code == ResponseCodeSuccess {
retVal = jsonResult1["result"].(map[string]interface{})
return platformapi.ErrLevelSuccess, nil
}
newErr := utils.NewErrorIntCode(jsonResult1["error_msg"].(string), code)
return platformapi.ErrLevelCodeIsNotOK, newErr
})
return retVal, err
}

View File

@@ -12,6 +12,7 @@ import (
const (
accessStorePageCookieName = "shop.o2o.jd.com1"
getStoreURL = "https://daojia.jd.com"
)
type SkuPageImg struct {
@@ -137,3 +138,36 @@ func (a *API) GetSkuPageImageInfo(skuId int64) (imgList []*SkuPageImg, err error
}
return imgList, err
}
func (a *API) GetStoreInfo(storeId string) (storeInfo map[string]interface{}, err error) {
retVal, err := a.AccessStorePage2(fmt.Sprintf("client?functionId=store/storeDetailV220&body={\"storeId\":\"%s\"}&appVersion=6.1.0", storeId))
return retVal, err
}
func (a *API) AccessStorePage2(subURL string) (retVal map[string]interface{}, err error) {
err = platformapi.AccessPlatformAPIWithRetry(a.client,
func() *http.Request {
fullURL := utils.GenerateGetURL(getStoreURL, subURL, nil)
request, _ := http.NewRequest(http.MethodGet, fullURL, nil)
if err != nil {
return nil
}
return request
},
a.config,
func(jsonResult1 map[string]interface{}) (errLevel string, err error) {
code := jsonResult1["code"].(string)
if code == ResponseCodeSuccess && jsonResult1["result"] != nil {
retVal = jsonResult1["result"].(map[string]interface{})
return platformapi.ErrLevelSuccess, nil
}
newErr := utils.NewErrorCode(jsonResult1["msg"].(string), code)
return platformapi.ErrLevelCodeIsNotOK, newErr
})
return retVal, err
}
func (a *API) GetStoreList(lng string, lat string) (retVal map[string]interface{}, err error) {
retVal, err = a.AccessStorePage2(fmt.Sprintf("client?platCode=h5&appVersion=6.5.0&functionId=zone/recommendStoreList&body={\"channelId\":\"3997\",\"currentPage\":1,\"pageSize\":999,\"coordType\":\"2\",\"platform\":\"1\"}&signKey=b63f63fa9e27123b84a0c80ef5cd210d&lng=%s&lat=%s", lng, lat))
return retVal, err
}