diff --git a/platformapi/ebaiapi/ebaiapi.go b/platformapi/ebaiapi/ebaiapi.go index 65f9249f..85a63280 100644 --- a/platformapi/ebaiapi/ebaiapi.go +++ b/platformapi/ebaiapi/ebaiapi.go @@ -22,8 +22,9 @@ const ( ) const ( - ResponseCodeSuccess = 0 - ResponseCodeCallElmFailed = 2101 // 这个可以尝试重试 + ResponseCodeSuccess = 0 + GetStoreSuccessButUnderfind = 4001 // 拉取网页饿百门店信息,但是显示门店不存在 + ResponseCodeCallElmFailed = 2101 // 这个可以尝试重试 ) type ResponseResult struct { diff --git a/platformapi/ebaiapi/store_page.go b/platformapi/ebaiapi/store_page.go index 69b4a98c..2dfc445c 100644 --- a/platformapi/ebaiapi/store_page.go +++ b/platformapi/ebaiapi/store_page.go @@ -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 +} diff --git a/platformapi/jdapi/store_page.go b/platformapi/jdapi/store_page.go index 53026468..6865b3e4 100644 --- a/platformapi/jdapi/store_page.go +++ b/platformapi/jdapi/store_page.go @@ -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 +}