- GetSkuPageInfo

This commit is contained in:
gazebo
2019-04-28 17:18:38 +08:00
parent 590c95e4fc
commit ba0f084609
3 changed files with 53 additions and 16 deletions

View File

@@ -56,8 +56,6 @@ const (
AllPage = 0 AllPage = 0
DefaultPageSize = 50 DefaultPageSize = 50
storeURL = "http://store.jddj.com"
) )
type API struct { type API struct {

View File

@@ -14,6 +14,12 @@ const (
accessStorePageCookieName = "shop.o2o.jd.com1" accessStorePageCookieName = "shop.o2o.jd.com1"
) )
type SkuPageImg struct {
Big string `json:"big"`
Share string `json:"share"`
Small string `json:"small"`
}
func (a *API) SetStoreCookie(storeCookie string) { func (a *API) SetStoreCookie(storeCookie string) {
a.locker.Lock() a.locker.Lock()
defer a.locker.Unlock() defer a.locker.Unlock()
@@ -26,15 +32,13 @@ func (a *API) GetStoreCookie() string {
return a.storeCookie return a.storeCookie
} }
func (a *API) AccessStorePage(subURL string) (retVal map[string]interface{}, err error) { func (a *API) AccessStorePage(fullURL string) (retVal map[string]interface{}, err error) {
storeCookie := a.GetStoreCookie() storeCookie := a.GetStoreCookie()
if storeCookie == "" { if storeCookie == "" {
return nil, fmt.Errorf("需要设置Store Cookie才能使用此方法") return nil, fmt.Errorf("需要设置Store Cookie才能使用此方法")
} }
err = platformapi.AccessPlatformAPIWithRetry(a.client, err = platformapi.AccessPlatformAPIWithRetry(a.client,
func() *http.Request { func() *http.Request {
fullURL := utils.GenerateGetURL(storeURL, subURL, nil)
// baseapi.SugarLogger.Debug(fullURL)
request, _ := http.NewRequest(http.MethodGet, fullURL, nil) request, _ := http.NewRequest(http.MethodGet, fullURL, nil)
if err != nil { if err != nil {
return nil return nil
@@ -50,7 +54,7 @@ func (a *API) AccessStorePage(subURL string) (retVal map[string]interface{}, err
retVal = jsonResult1 retVal = jsonResult1
code := jsonResult1["code"].(string) code := jsonResult1["code"].(string)
if code == ResponseCodeSuccess { if code == ResponseCodeSuccess {
retVal = jsonResult1 retVal = jsonResult1["result"].(map[string]interface{})
return platformapi.ErrLevelSuccess, nil return platformapi.ErrLevelSuccess, nil
} }
newErr := utils.NewErrorCode(jsonResult1["msg"].(string), code) newErr := utils.NewErrorCode(jsonResult1["msg"].(string), code)
@@ -75,14 +79,14 @@ func (a *API) GetRealMobile4Order(orderId, stationNo string) (mobile string, err
} }
func (a *API) GetStoreOrderInfo(orderId, stationNo string) (storeOrderInfo map[string]interface{}, err error) { func (a *API) GetStoreOrderInfo(orderId, stationNo string) (storeOrderInfo map[string]interface{}, err error) {
urlStr := "order/newManager/search?pageNo=1&pageSize=1&orderBy=&desc=true&param=" + orderId urlStr := "http://store.jddj.com/order/newManager/search?pageNo=1&pageSize=1&orderBy=&desc=true&param=" + orderId
if stationNo != "" { if stationNo != "" {
urlStr += "&stationNo=" + stationNo urlStr += "&stationNo=" + stationNo
} }
retVal, err := a.AccessStorePage(urlStr) retVal, err := a.AccessStorePage(urlStr)
// baseapi.SugarLogger.Debug(utils.Format4Output(retVal, false)) // baseapi.SugarLogger.Debug(utils.Format4Output(retVal, false))
if err == nil { if err == nil {
newOrderinfoMains := retVal["result"].(map[string]interface{})["newOrderinfoMains"].(map[string]interface{}) newOrderinfoMains := retVal["newOrderinfoMains"].(map[string]interface{})
resultList := newOrderinfoMains["resultList"].([]interface{}) resultList := newOrderinfoMains["resultList"].([]interface{})
if len(resultList) > 0 { if len(resultList) > 0 {
return resultList[0].(map[string]interface{}), nil return resultList[0].(map[string]interface{}), nil
@@ -95,12 +99,12 @@ func (a *API) GetStoreOrderInfo(orderId, stationNo string) (storeOrderInfo map[s
func (a *API) GetStoreOrderInfoList(fromTime, toTime string) (storeOrderList []map[string]interface{}, err error) { func (a *API) GetStoreOrderInfoList(fromTime, toTime string) (storeOrderList []map[string]interface{}, err error) {
pageSize := 100 pageSize := 100
pageNo := 1 pageNo := 1
urlTemplate := "order/newManager/tabQuery/all?o2oOrderType=10000&pageNo=%d&pageSize=%d&orderBy=&desc=true&startTimeQuery=%s&endTimeQuery=%s&stationNo=" urlTemplate := "http://store.jddj.com/order/newManager/tabQuery/all?o2oOrderType=10000&pageNo=%d&pageSize=%d&orderBy=&desc=true&startTimeQuery=%s&endTimeQuery=%s&stationNo="
for { for {
retVal, err := a.AccessStorePage(fmt.Sprintf(urlTemplate, pageNo, pageSize, url.QueryEscape(fromTime), url.QueryEscape(toTime))) retVal, err := a.AccessStorePage(fmt.Sprintf(urlTemplate, pageNo, pageSize, url.QueryEscape(fromTime), url.QueryEscape(toTime)))
// baseapi.SugarLogger.Debug(utils.Format4Output(retVal, false)) // baseapi.SugarLogger.Debug(utils.Format4Output(retVal, false))
if err == nil { if err == nil {
newOrderinfoMains := retVal["result"].(map[string]interface{})["newOrderinfoMains"].(map[string]interface{}) newOrderinfoMains := retVal["newOrderinfoMains"].(map[string]interface{})
resultList := newOrderinfoMains["resultList"].([]interface{}) resultList := newOrderinfoMains["resultList"].([]interface{})
storeOrderList = append(storeOrderList, utils.Slice2MapSlice(resultList)...) storeOrderList = append(storeOrderList, utils.Slice2MapSlice(resultList)...)
if len(storeOrderList) >= int(utils.MustInterface2Int64(newOrderinfoMains["totalCount"])) { if len(storeOrderList) >= int(utils.MustInterface2Int64(newOrderinfoMains["totalCount"])) {
@@ -113,3 +117,23 @@ func (a *API) GetStoreOrderInfoList(fromTime, toTime string) (storeOrderList []m
} }
return nil, err return nil, err
} }
func (a *API) GetSkuPageInfo(skuId int64) (skuPageInfo map[string]interface{}, err error) {
skuIDMap := map[string]interface{}{
"skuId": utils.Int64ToStr(skuId),
"storeId": "0",
}
skuPageInfo, err = a.AccessStorePage(fmt.Sprintf("https://daojia.jd.com/client?platCode=H5&functionId=product/detailV6_0&body=%s", utils.Format4Output(skuIDMap, true)))
if err == nil {
baseapi.SugarLogger.Debug(utils.Format4Output(skuPageInfo, false))
}
return skuPageInfo, err
}
func (a *API) GetSkuPageImageInfo(skuId int64) (imgList []*SkuPageImg, err error) {
skuPageInfo, err := a.GetSkuPageInfo(skuId)
if err == nil {
err = utils.Map2StructByJson(skuPageInfo["image"], &imgList, false)
}
return imgList, err
}

View File

@@ -8,9 +8,9 @@ import (
) )
func TestGetRealMobileNumber4Order(t *testing.T) { func TestGetRealMobileNumber4Order(t *testing.T) {
orderId := "900658736000042" orderId := "910170516000941"
desiredMobile := "18569035610" desiredMobile := "13398196274"
mobile, err := api.GetRealMobile4Order(orderId, "11738115") mobile, err := api.GetRealMobile4Order(orderId, "")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@@ -21,9 +21,8 @@ func TestGetRealMobileNumber4Order(t *testing.T) {
} }
func TestGetStoreOrderInfo(t *testing.T) { func TestGetStoreOrderInfo(t *testing.T) {
orderId := "826309564000021" orderId := "910170516000941"
// desiredMobile := "18569035610" orderInfo, err := api.GetStoreOrderInfo(orderId, "")
orderInfo, err := api.GetStoreOrderInfo(orderId, "11738115")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@@ -39,3 +38,19 @@ func TestGetStoreOrderInfoList(t *testing.T) {
baseapi.SugarLogger.Debug(utils.Format4Output(orderInfoList, false)) baseapi.SugarLogger.Debug(utils.Format4Output(orderInfoList, false))
} }
} }
func TestGetSkuPageInfo(t *testing.T) {
skuInfo, err := api.GetSkuPageInfo(2023524346)
if err != nil {
t.Fatal(err)
}
baseapi.SugarLogger.Debug(utils.Format4Output(skuInfo, false))
}
func TestGetSkuPageImageInfo(t *testing.T) {
imgList, err := api.GetSkuPageImageInfo(2023524346)
if err != nil {
t.Fatal(err)
}
baseapi.SugarLogger.Debug(utils.Format4Output(imgList, false))
}