From 7ae766ce6bce16f1f17810451138d51dfc34458b Mon Sep 17 00:00:00 2001 From: gazebo Date: Thu, 16 May 2019 17:43:14 +0800 Subject: [PATCH] - ebai.SkuUploadRTF --- platformapi/ebaiapi/shop_sku.go | 22 ++++++++++++++++++++++ platformapi/ebaiapi/shop_sku_test.go | 24 +++++++++++++++++++++++- 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/platformapi/ebaiapi/shop_sku.go b/platformapi/ebaiapi/shop_sku.go index 5a5e2e59..37ed2de2 100644 --- a/platformapi/ebaiapi/shop_sku.go +++ b/platformapi/ebaiapi/shop_sku.go @@ -1,6 +1,7 @@ package ebaiapi import ( + "fmt" "regexp" "strings" @@ -223,6 +224,27 @@ func (a *API) SkuShopCategoryMap(shopID string, skuID int64, categoryIDsStr stri return err } +// 饿百的这个API有点怪,虽然有shopID参数,但返回的链接可以跨店使用 +func (a *API) SkuUploadRTF(shopID, rtfDetail string) (rtfURL string, err error) { + params := map[string]interface{}{ + KeyShopID: shopID, + "rtf_detail": rtfDetail, + } + result, err := a.AccessAPI("sku.uploadrtf", params) + if err == nil { + rtfURL = utils.Interface2String(result.Data.(map[string]interface{})["url"]) + } + return rtfURL, err +} + +func BuildRFTFromImgs(imgList ...string) string { + imgList2 := make([]string, len(imgList)) + for index, img := range imgList { + imgList2[index] = fmt.Sprintf(`%s`, img, img) + } + return strings.Join(imgList2, "\n") +} + // func interface2CatList(data interface{}, level int) (cats []*CategoryInfo) { maps, ok := data.([]interface{}) diff --git a/platformapi/ebaiapi/shop_sku_test.go b/platformapi/ebaiapi/shop_sku_test.go index a9631343..56030822 100644 --- a/platformapi/ebaiapi/shop_sku_test.go +++ b/platformapi/ebaiapi/shop_sku_test.go @@ -49,7 +49,7 @@ func TestSkuGetItemsByCategoryId(t *testing.T) { func TestSkuList(t *testing.T) { result, err := api.SkuList(testShopID, map[string]interface{}{ - // KeySkuID: 153879464137191, + KeySkuID: 15570439700710601, // "delete": 1, }) if err != nil { @@ -59,6 +59,16 @@ func TestSkuList(t *testing.T) { } } +func TestSkuUploadRTF(t *testing.T) { + rtfDetail := BuildRFTFromImgs("https://image.jxc4.com/sijidou.jpg") + t.Log(rtfDetail) + result, err := api.SkuUploadRTF("2", rtfDetail) + if err != nil { + t.Fatal(err) + } + t.Log(result) +} + func TestSkuCreate(t *testing.T) { result, err := api.SkuCreate(testShopID, 17, map[string]interface{}{ "name": "测试商品", @@ -83,6 +93,18 @@ func TestSkuCreate(t *testing.T) { } } +func TestSkuUpdate(t *testing.T) { + result, err := api.SkuUpdate("2", 15579787500720732, map[string]interface{}{ + // "name": "高级商品2015a333约1100g/份", + "rtf": "https://image-star.elemecdn.com/pb/488b65e430305e54acae89f64c24e6d01b", + }) + if err != nil { + t.Fatal(err) + } else { + t.Log(utils.Format4Output(result, false)) + } +} + func TestSkuDelete(t *testing.T) { err := api.SkuDelete(testShopID, "153922044227304") if err != nil {