- 整理饿百与京东PAGE API

This commit is contained in:
gazebo
2019-06-24 11:25:40 +08:00
parent e2bc700427
commit d2597c2673
4 changed files with 297 additions and 7 deletions

View File

@@ -159,6 +159,157 @@ type PageShopHealthInfo struct {
Week string `json:"week"`
}
type ActivityTagInfo struct {
Color struct {
BgColor string `json:"bg_color"`
FrameColor string `json:"frame_color"`
FrontColor string `json:"front_color"`
} `json:"color"`
Discount string `json:"discount"`
Msg string `json:"msg"`
Type string `json:"type"`
}
type PageListInnerShopInfo struct {
ActivityTag []*ActivityTagInfo `json:"activity_tag"`
BrandName string `json:"brand_name"`
BusinessStatus int `json:"business_status"`
BusinessTime []struct {
End string `json:"end"`
Start string `json:"start"`
} `json:"business_time"`
CanRefund int `json:"can_refund"`
CashGiftComment string `json:"cash_gift_comment"`
DeliveryTime int `json:"delivery_time"`
DisplayRefundLabel int `json:"display_refund_label"`
Distance float64 `json:"distance"`
EleID string `json:"ele_id"`
FlashsalesStyleShop int `json:"flashsales_style_shop"`
HasFoodEnsurance int `json:"has_food_ensurance"`
HasServiceCommitment int `json:"has_service_commitment"`
HitGod int `json:"hit_god"`
IsBrand int `json:"is_brand"`
IsDoubleTwelve int `json:"is_double_twelve"`
IsRank int `json:"is_rank"`
IsTransfer int `json:"is_transfer"`
LogoURL string `json:"logo_url"`
OverallRating float64 `json:"overall_rating"`
SaledMonth int `json:"saled_month"`
SameBrandFolding []struct {
DeliveryTime int `json:"delivery_time"`
Distance float64 `json:"distance"`
EleID string `json:"ele_id"`
IsTransfer int `json:"is_transfer"`
ShopName string `json:"shop_name"`
Wid string `json:"wid"`
} `json:"same_brand_folding"`
ShopLabels string `json:"shop_labels"`
ShopName string `json:"shop_name"`
TakeoutCost float64 `json:"takeout_cost"`
TakeoutPrice int `json:"takeout_price"`
Type interface{} `json:"type"`
WelfareInfo []struct {
IconColor struct {
BgColor string `json:"bg_color"`
FrameColor string `json:"frame_color"`
FrontColor string `json:"front_color"`
} `json:"icon_color"`
IconName string `json:"icon_name"`
IconNameOther string `json:"icon_name_other"`
Msg string `json:"msg"`
Type string `json:"type"`
} `json:"welfare_info"`
Wid string `json:"wid"`
}
type PageListShopInfo struct {
ActivityEntry interface{} `json:"activity_entry"`
AoiID string `json:"aoi_id"`
DisplayWindow []struct {
CategoryIds []string `json:"category_ids"`
CurrentPrice string `json:"current_price"`
Image string `json:"image"`
ItemID string `json:"item_id"`
LeftNum int `json:"left_num"`
Name string `json:"name"`
OriginPrice string `json:"origin_price"`
SkuID string `json:"sku_id"`
} `json:"display_window"`
ShopInfo *PageListInnerShopInfo `json:"shop_info"`
}
type PageListInfo struct {
ShopList []*PageListShopInfo `json:"shop_list"`
Total int `json:"total"`
UserType string `json:"user_type"`
}
type PageShopInfo struct {
Activities []struct {
IconColor struct {
BgColor string `json:"bg_color"`
FrameColor string `json:"frame_color"`
FrontColor string `json:"front_color"`
} `json:"icon_color"`
IconName string `json:"icon_name"`
IconNameOther string `json:"icon_name_other"`
Msg string `json:"msg"`
Type string `json:"type"`
} `json:"activities"`
ActivityTag []*ActivityTagInfo `json:"activity_tag"`
Address string `json:"address"`
Albums []interface{} `json:"albums"`
BdHeadBg string `json:"bd_head_bg"`
BdHeadColor string `json:"bd_head_color"`
Brand string `json:"brand"`
BusinessStatus int `json:"business_status"`
CanRefund int `json:"can_refund"`
Category string `json:"category"`
CityID string `json:"city_id"`
CurrentBusinessTime string `json:"current_business_time"`
DeliveryInfo []interface{} `json:"delivery_info"`
DeliveryMode struct {
Tag []interface{} `json:"tag"`
Text string `json:"text"`
} `json:"delivery_mode"`
Description string `json:"description"`
DisplayRefundLabel int `json:"display_refund_label"`
Distance int `json:"distance"`
EleBusinessState int `json:"ele_business_state"`
EleID string `json:"ele_id"`
FirstOpenTime struct {
End string `json:"end"`
Start string `json:"start"`
} `json:"first_open_time"`
HitGod int `json:"hit_god"`
ImagePath string `json:"image_path"`
IsColdChain int `json:"is_cold_chain"`
IsDoubleTwelve int `json:"is_double_twelve"`
IsMedicineShop int `json:"is_medicine_shop"`
IsOwnTheme int `json:"is_own_theme"`
Latitude float64 `json:"latitude"`
Longitude float64 `json:"longitude"`
MedicineQualification []interface{} `json:"medicine_qualification"`
Name string `json:"name"`
NewStyle bool `json:"new_style"`
OTakoutCost int `json:"o_takout_cost"`
OTakoutPrice int `json:"o_takout_price"`
OrderLeadTime interface{} `json:"order_lead_time"`
Phone string `json:"phone"`
PromotionInfo string `json:"promotion_info"`
Qualification string `json:"qualification"`
RecentOrderNum int `json:"recent_order_num"`
ShopID string `json:"shop_id"`
ShopScore int `json:"shop_score"`
ShopSourceFrom int `json:"shop_source_from"`
SkuCount int `json:"sku_count"`
TakeoutCost int `json:"takeout_cost"`
TakeoutInvoice int `json:"takeout_invoice"`
TakeoutInvoiceMinPrice string `json:"takeout_invoice_min_price"`
TakeoutOpenTime string `json:"takeout_open_time"`
TakeoutPrice int `json:"takeout_price"`
}
func (a *API) SetStoreCookie(key, value string) {
a.locker.Lock()
defer a.locker.Unlock()
@@ -406,6 +557,19 @@ func (a *API) PageGetCustomCatList(baiduShopID int64) (catList []map[string]inte
return nil, err
}
func (a *API) GetStoreList(lng string, lat string) (retVal map[string]interface{}, err error) {
retVal, err = a.AccessStorePageNoCookie(fmt.Sprintf("/newretail/main/shoplist?channel=kitchen&pn=1&rn=999&lng=%s&lat=%s", lng, lat))
return retVal, err
}
func (a *API) GetStoreList2(lng float64, lat float64) (shopListInfo *PageListInfo, err error) {
retVal, err := a.AccessStorePageNoCookie(fmt.Sprintf("/newretail/main/shoplist?channel=kitchen&pn=1&rn=999&lng=%f&lat=%f", lng, lat))
if err == nil {
err = utils.Map2StructByJson(retVal, &shopListInfo, true)
}
return shopListInfo, err
}
func (a *API) GetStoreInfo(storeId string) (storeInfo map[string]interface{}, err error) {
retVal, err := a.AccessStorePageNoCookie(fmt.Sprintf("newretail/shop/getshopinfo?&lat=0&lng=0&shop_id=%s", storeId))
if err != nil {
@@ -417,6 +581,17 @@ func (a *API) GetStoreInfo(storeId string) (storeInfo map[string]interface{}, er
return retVal, err
}
func (a *API) GetStoreInfo2(storeID string) (storeInfo *PageShopInfo, err error) {
retVal, err := a.AccessStorePageNoCookie(fmt.Sprintf("newretail/shop/getshopinfo?&lat=0&lng=0&shop_id=%s", storeID))
if err == nil {
if retVal != nil {
retVal["shop_id"] = storeID
err = utils.Map2StructByJson(retVal, &storeInfo, true)
}
}
return storeInfo, err
}
func (a *API) AccessStorePageNoCookie(subURL string) (retVal map[string]interface{}, err error) {
err = platformapi.AccessPlatformAPIWithRetry(a.client,
func() *http.Request {
@@ -442,11 +617,6 @@ func (a *API) AccessStorePageNoCookie(subURL string) (retVal map[string]interfac
return retVal, err
}
func (a *API) GetStoreList(lng string, lat string) (retVal map[string]interface{}, err error) {
retVal, err = a.AccessStorePageNoCookie(fmt.Sprintf("/newretail/main/shoplist?channel=kitchen&pn=1&rn=999&lng=%s&lat=%s", lng, lat))
return retVal, err
}
func (a *API) SwitchShop(baiduShopID int64) (switchShopCookie string, err error) {
result, err := a.AccessStorePage("crm/manager/switchshop", map[string]interface{}{
"switch_shop_id": baiduShopID,

View File

@@ -114,6 +114,14 @@ func TestGetStoreList(t *testing.T) {
t.Log(utils.Format4Output(result, false))
}
func TestGetStoreList2(t *testing.T) {
result, err := api.GetStoreList2(104.057218, 30.6949)
if err != nil {
t.Fatal(err)
}
t.Log(utils.Format4Output(result, false))
}
func TestGetStoreInfo(t *testing.T) {
result, err := api.GetStoreInfo("170879219")
if err != nil {
@@ -121,3 +129,11 @@ func TestGetStoreInfo(t *testing.T) {
}
t.Log(utils.Format4Output(result, false))
}
func TestGetStoreInfo2(t *testing.T) {
result, err := api.GetStoreInfo2("170879219")
if err != nil {
t.Fatal(err)
}
t.Log(utils.Format4Output(result, false))
}

View File

@@ -1,6 +1,7 @@
package jdapi
import (
"crypto/md5"
"fmt"
"net/http"
"net/url"
@@ -65,6 +66,76 @@ type CorporationInfo struct {
} `json:"employees"`
}
type PageShopInfo struct {
DisCatName string `json:"disCatName"`
DisplayType string `json:"displayType"`
FreightWords string `json:"freightWords"`
IsCart bool `json:"isCart"`
IsJb int `json:"isJb"`
IsWithHome bool `json:"isWithHome"`
LogoURL string `json:"logoUrl"`
StoreActPageList []interface{} `json:"storeActPageList"`
StoreCommentVO struct {
BuyerShowName string `json:"buyerShowName"`
CreateTime string `json:"createTime"`
IsOrgComment int `json:"isOrgComment"`
OrgCommentContent string `json:"orgCommentContent"`
Score4 int `json:"score4"`
Score4Content string `json:"score4Content"`
ScoreAvg float64 `json:"scoreAvg"`
ShowTotalCount bool `json:"showTotalCount"`
Skus []interface{} `json:"skus"`
StoreStar float64 `json:"storeStar"`
TagInfoItemList []string `json:"tagInfoItemList"`
TotalCount int `json:"totalCount"`
} `json:"storeCommentVO"`
StoreDesc string `json:"storeDesc"`
StoreInfo struct {
BackgroundType string `json:"backgroundType"`
CarrierNo int `json:"carrierNo"`
CloseStatus int `json:"closeStatus"`
DeliveryFirst string `json:"deliveryFirst"`
DeliverySecond string `json:"deliverySecond"`
ExpectArrivedTips []struct {
Msg string `json:"msg"`
Type int `json:"type"`
} `json:"expectArrivedTips"`
Flag bool `json:"flag"`
FollowNo string `json:"followNo"`
FreightTag struct {
BelongIndustry int `json:"belongIndustry"`
Type int `json:"type"`
Words string `json:"words"`
} `json:"freightTag"`
FreightWords string `json:"freightWords"`
InSaleNum string `json:"inSaleNum"`
Industry string `json:"industry"`
IsFollow bool `json:"isFollow"`
IsMembership bool `json:"isMembership"`
IsOverZone bool `json:"isOverZone"`
IsTimeFight int `json:"isTimeFight"`
LogoURL string `json:"logoUrl"`
MonthSaleNum string `json:"monthSaleNum"`
OrgCode string `json:"orgCode"`
Params string `json:"params"`
SearchLinkageFlag bool `json:"searchLinkageFlag"`
ServiceTimes []struct {
EndTime string `json:"endTime"`
StartTime string `json:"startTime"`
} `json:"serviceTimes"`
ShowType string `json:"showType"`
StationStatus int `json:"stationStatus"`
StoreAddress string `json:"storeAddress"`
StoreCertificateURL string `json:"storeCertificateUrl"`
StoreID string `json:"storeId"`
StoreName string `json:"storeName"`
StoreTel string `json:"storeTel"`
To string `json:"to"`
UpToSendprice int `json:"upToSendprice"`
} `json:"storeInfo"`
StoreShareURL string `json:"storeShareUrl"`
}
func (a *API) SetStoreCookie(storeCookie string) {
a.locker.Lock()
defer a.locker.Unlock()
@@ -192,12 +263,37 @@ func (a *API) GetSkuPageImageInfo(skuId int64) (imgList []*SkuPageImg, err error
}
func (a *API) GetStoreInfo(storeId string) (storeInfo map[string]interface{}, err error) {
retVal, err := a.AccessStorePage(fmt.Sprintf("https://daojia.jd.com/client?functionId=store/storeDetailV220&body={\"storeId\":\"%s\"}&appVersion=6.1.0", storeId), nil)
body := map[string]interface{}{
"storeId": storeId,
}
retVal, err := a.AccessStorePage(fmt.Sprintf("https://daojia.jd.com/client?functionId=store/storeDetailV220&body=%s&appVersion=6.1.0", utils.Format4Output(body, true)), nil)
return retVal, err
}
func (a *API) GetStoreInfo2(storeID string) (storeInfo *PageShopInfo, err error) {
retVal, err := a.GetStoreInfo(storeID)
if err == nil {
err = utils.Map2StructByJson(retVal, &storeInfo, false)
}
return storeInfo, err
}
func signGetStoreList(bodyStr string) (signResult string) {
wb := "923047ae3f8d11d8b19aeb9f3d1bc200"
return fmt.Sprintf("%X", md5.Sum([]byte(bodyStr+wb)))
}
func (a *API) GetStoreList(lng string, lat string) (retVal map[string]interface{}, err error) {
retVal, err = a.AccessStorePage(fmt.Sprintf("https://daojia.jd.com/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), nil)
body := map[string]interface{}{
"channelId": "3997",
"currentPage": 1,
"pageSize": 999,
"coordType": "2",
"platform": "1",
}
bodyStr := utils.Format4Output(body, true)
signResult := signGetStoreList(bodyStr)
retVal, err = a.AccessStorePage(fmt.Sprintf("https://daojia.jd.com/client?platCode=h5&appVersion=6.5.0&functionId=zone/recommendStoreList&body=%s&signKey=%s&lng=%s&lat=%s", bodyStr, signResult, lng, lat), nil)
return retVal, err
}

View File

@@ -78,3 +78,11 @@ func TestGetStoreInfo(t *testing.T) {
}
t.Log(utils.Format4Output(result, false))
}
func TestGetStoreInfo2(t *testing.T) {
result, err := api.GetStoreInfo2("11750116")
if err != nil {
t.Fatal(err)
}
t.Log(utils.Format4Output(result, false))
}