From 0531b16f62b6ab76fc5099d4bcdbc38a0bce862a Mon Sep 17 00:00:00 2001 From: gazebo Date: Wed, 11 Dec 2019 14:35:27 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E5=8E=BB=E9=99=A4io.TeeReader=E7=9A=84?= =?UTF-8?q?=E4=BD=BF=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- platformapi/platformapi.go | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/platformapi/platformapi.go b/platformapi/platformapi.go index aab9b2ed..e305d9d5 100644 --- a/platformapi/platformapi.go +++ b/platformapi/platformapi.go @@ -4,7 +4,6 @@ import ( "bytes" "errors" "fmt" - "io" "io/ioutil" "math" "net" @@ -81,15 +80,14 @@ var ( ErrStrCallbackSignatureIsWrong = "wrong signature" ) -func getClonedData(requestURL *url.URL, r *bytes.Buffer) string { +func getClonedData(requestURL *url.URL, data []byte) string { if strings.Index(requestURL.String(), "uploadImg") >= 0 { return "binary content" } - retVal := string(r.Bytes()) - if len(retVal) > maxDataSizeDontOutput { + if len(data) > maxDataSizeDontOutput { return "request data is too large" } - return retVal + return string(data) } func NewDefAPIConfig() (conf *APIConfig) { @@ -101,10 +99,16 @@ func AccessPlatformAPIWithRetry(client *http.Client, handleRequest func() *http. exceedLimitRetryCount := 0 recoverableErrorRetryCount := 0 for { - savedBuf := new(bytes.Buffer) + var savedBuf []byte request := handleRequest() if request.Body != nil { - request.Body = ioutil.NopCloser(io.TeeReader(request.Body, savedBuf)) + savedBuf2, err2 := ioutil.ReadAll(request.Body) + if err2 == nil { + savedBuf = savedBuf2 + request.Body = ioutil.NopCloser(bytes.NewReader(savedBuf)) + } else { + baseapi.SugarLogger.Warnf("AccessPlatformAPIWithRetry failed with err:%v", err2) + } } beginTime := time.Now() trackInfo := request.Header.Get(KeyTrackInfo) From fd42a483d96220ec1aa34c88e29b9e5176e1b5ae Mon Sep 17 00:00:00 2001 From: gazebo Date: Thu, 12 Dec 2019 09:55:35 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E8=B0=83=E8=AF=95=E9=A5=BF=E7=99=BE?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E6=B4=BB=E5=8A=A8API=EF=BC=8Cerrno=E4=B8=BAn?= =?UTF-8?q?il=E7=9A=84=E6=83=85=E5=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- platformapi/ebaiapi/store_page.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/platformapi/ebaiapi/store_page.go b/platformapi/ebaiapi/store_page.go index f989ee8e..5d47fd45 100644 --- a/platformapi/ebaiapi/store_page.go +++ b/platformapi/ebaiapi/store_page.go @@ -350,6 +350,9 @@ func (a *API) AccessStorePage2(subURL string, params map[string]interface{}, isP return platformapi.ErrLevelRecoverableErr, fmt.Errorf("mapData is nil") } retVal = jsonResult1 + if jsonResult1["errno"] == nil { + baseapi.SugarLogger.Warnf("ebai AccessStorePage2, jsonResult1:%s", utils.Format4Output(jsonResult1, true)) + } code := int(utils.MustInterface2Int64(jsonResult1["errno"])) if code == ResponseCodeSuccess { if subURL == swithShopURL { From 17c4265ea41b0dc9fded379a132c5dc972777943 Mon Sep 17 00:00:00 2001 From: gazebo Date: Fri, 13 Dec 2019 15:16:56 +0800 Subject: [PATCH 3/3] OpSkuParam.Upc json to upcCode --- platformapi/jdapi/sku.go | 2 +- platformapi/jdapi/sku_test.go | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/platformapi/jdapi/sku.go b/platformapi/jdapi/sku.go index 13c310e4..d9a346d8 100644 --- a/platformapi/jdapi/sku.go +++ b/platformapi/jdapi/sku.go @@ -184,7 +184,7 @@ type OpSkuParam struct { IsSale int `json:"-"` // 创建:0,1可售,-1不可售,更新:0忽略,1可售,-1不可售 DontUseThisFieldDirectlyIsSale bool `json:"isSale"` // 门店商品可售状态(true/false);新建商品时,如果为true,门店商品可售状态初始为可售,如果为false, 门店商品可售状态初始为不可售。后续修改各个门店商品可售状态时,请使用根据京东到家商品编码批量修改门店商品可售状态接口。 - Upc string `json:"upc,omitempty"` // UPC编码(商品条码),限1-35个字符,包装类的商品要求UPC编码必填,且要符合条码编写的校验,否则商品会不予通过,接口返回错误状态码code为10059。 + Upc string `json:"upcCode,omitempty"` // TODO 老版与新版接口参数不一致,UPC编码(商品条码),限1-35个字符,包装类的商品要求UPC编码必填,且要符合条码编写的校验,否则商品会不予通过,接口返回错误状态码code为10059。 Images []string `json:"images,omitempty"` ProductDesc string `json:"productDesc,omitempty"` IfViewDesc int `json:"ifViewDesc"` diff --git a/platformapi/jdapi/sku_test.go b/platformapi/jdapi/sku_test.go index b44cb514..1f6c5b40 100644 --- a/platformapi/jdapi/sku_test.go +++ b/platformapi/jdapi/sku_test.go @@ -133,6 +133,14 @@ func TestGetProductStatust(t *testing.T) { } } +func TestAddShopCategory(t *testing.T) { + result, err := api.AddShopCategory(0, "hello", 1, 0, "test") + if err != nil { + t.Fatal(err) + } + t.Log(result) +} + func TestDelShopCategory(t *testing.T) { err := api.DelShopCategory(4784689) if err != nil { @@ -156,6 +164,32 @@ func TestGetSpuSaleAttr(t *testing.T) { t.Log(utils.Format4Output(result, false)) } +func TestAddSku(t *testing.T) { + str := ` + {"brandId":35247, + "categoryId":20847, + "fixedStatus":1, + "ifViewDesc":0, + "images":["http://image.jxc4.com/e42be71501d0fbb841743bfb7a9ebbcf.jpg"], + "isSale":false, + "outSkuId":"29935", + "shopCategories":[4247719], + "skuName":"黑2龙江冰宝珍珠米10kg/袋", + "skuPrice":7245,"traceId":"4414AEAD1CCA11EAB689525400E86DC0,xujianhua","weight":1} + ` + var param *OpSkuParam + err := utils.UnmarshalUseNumber([]byte(str), ¶m) + if err != nil { + t.Fatal(err) + } + param.Upc = "6666000029935" + result, err := api.AddSku2(param) + if err != nil { + t.Fatal(err) + } + t.Log(utils.Format4Output(result, false)) +} + func TestBatchAddSku(t *testing.T) { paramList := []*CreateByUpcParam{ &CreateByUpcParam{