Merge branch 'master' of e.coding.net:rosydev/baseapi

This commit is contained in:
苏尹岚
2019-12-13 16:39:45 +08:00
4 changed files with 49 additions and 8 deletions

View File

@@ -350,6 +350,9 @@ func (a *API) AccessStorePage2(subURL string, params map[string]interface{}, isP
return platformapi.ErrLevelRecoverableErr, fmt.Errorf("mapData is nil") return platformapi.ErrLevelRecoverableErr, fmt.Errorf("mapData is nil")
} }
retVal = jsonResult1 retVal = jsonResult1
if jsonResult1["errno"] == nil {
baseapi.SugarLogger.Warnf("ebai AccessStorePage2, jsonResult1:%s", utils.Format4Output(jsonResult1, true))
}
code := int(utils.MustInterface2Int64(jsonResult1["errno"])) code := int(utils.MustInterface2Int64(jsonResult1["errno"]))
if code == ResponseCodeSuccess { if code == ResponseCodeSuccess {
if subURL == swithShopURL { if subURL == swithShopURL {

View File

@@ -184,7 +184,7 @@ type OpSkuParam struct {
IsSale int `json:"-"` // 创建0,1可售-1不可售更新0忽略1可售-1不可售 IsSale int `json:"-"` // 创建0,1可售-1不可售更新0忽略1可售-1不可售
DontUseThisFieldDirectlyIsSale bool `json:"isSale"` // 门店商品可售状态(true/false)新建商品时如果为true门店商品可售状态初始为可售如果为false 门店商品可售状态初始为不可售。后续修改各个门店商品可售状态时,请使用根据京东到家商品编码批量修改门店商品可售状态接口。 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"` Images []string `json:"images,omitempty"`
ProductDesc string `json:"productDesc,omitempty"` ProductDesc string `json:"productDesc,omitempty"`
IfViewDesc int `json:"ifViewDesc"` IfViewDesc int `json:"ifViewDesc"`

View File

@@ -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) { func TestDelShopCategory(t *testing.T) {
err := api.DelShopCategory(4784689) err := api.DelShopCategory(4784689)
if err != nil { if err != nil {
@@ -156,6 +164,32 @@ func TestGetSpuSaleAttr(t *testing.T) {
t.Log(utils.Format4Output(result, false)) 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), &param)
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) { func TestBatchAddSku(t *testing.T) {
paramList := []*CreateByUpcParam{ paramList := []*CreateByUpcParam{
&CreateByUpcParam{ &CreateByUpcParam{

View File

@@ -4,7 +4,6 @@ import (
"bytes" "bytes"
"errors" "errors"
"fmt" "fmt"
"io"
"io/ioutil" "io/ioutil"
"math" "math"
"net" "net"
@@ -81,15 +80,14 @@ var (
ErrStrCallbackSignatureIsWrong = "wrong signature" 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 { if strings.Index(requestURL.String(), "uploadImg") >= 0 {
return "binary content" return "binary content"
} }
retVal := string(r.Bytes()) if len(data) > maxDataSizeDontOutput {
if len(retVal) > maxDataSizeDontOutput {
return "request data is too large" return "request data is too large"
} }
return retVal return string(data)
} }
func NewDefAPIConfig() (conf *APIConfig) { func NewDefAPIConfig() (conf *APIConfig) {
@@ -101,10 +99,16 @@ func AccessPlatformAPIWithRetry(client *http.Client, handleRequest func() *http.
exceedLimitRetryCount := 0 exceedLimitRetryCount := 0
recoverableErrorRetryCount := 0 recoverableErrorRetryCount := 0
for { for {
savedBuf := new(bytes.Buffer) var savedBuf []byte
request := handleRequest() request := handleRequest()
if request.Body != nil { 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() beginTime := time.Now()
trackInfo := request.Header.Get(KeyTrackInfo) trackInfo := request.Header.Get(KeyTrackInfo)