京东商城依稀下列
This commit is contained in:
@@ -125,10 +125,12 @@ func (a *API) AccessAPI2(action string, url string, bizParams map[string]interfa
|
|||||||
signStr := a.signParam(params)
|
signStr := a.signParam(params)
|
||||||
params["sign"] = signStr
|
params["sign"] = signStr
|
||||||
fullURL := utils.GenerateGetURL(url, "", nil)
|
fullURL := utils.GenerateGetURL(url, "", nil)
|
||||||
|
// rParam, _ := json.Marshal(bizParams)
|
||||||
// delete(params, "ware")
|
// delete(params, "ware")
|
||||||
// delete(params, "skus")
|
// delete(params, "skus")
|
||||||
// ware := bizParams["ware"].(string)
|
// ware := bizParams["ware"].(string)
|
||||||
// skus := bizParams["skus"].(string)
|
// skus := bizParams["skus"].(string)
|
||||||
|
// str := strings.ReplaceAll(string(rParam), "\\", "")
|
||||||
err = platformapi.AccessPlatformAPIWithRetry(a.client,
|
err = platformapi.AccessPlatformAPIWithRetry(a.client,
|
||||||
func() *http.Request {
|
func() *http.Request {
|
||||||
request, _ := http.NewRequest(http.MethodPost, fullURL, strings.NewReader(utils.URLQueryEscape(utils.Map2URLValues(params).Encode())))
|
request, _ := http.NewRequest(http.MethodPost, fullURL, strings.NewReader(utils.URLQueryEscape(utils.Map2URLValues(params).Encode())))
|
||||||
|
|||||||
@@ -120,16 +120,22 @@ type CreateSkuParamAttrs struct {
|
|||||||
AttrValues []string `json:"attrValues"` //是 无 下沉到sku属性值 单选或者多选 通过接口jingdong.category.read.findValuesByAttrIdUnlimit获取 输入类型请手动输入
|
AttrValues []string `json:"attrValues"` //是 无 下沉到sku属性值 单选或者多选 通过接口jingdong.category.read.findValuesByAttrIdUnlimit获取 输入类型请手动输入
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type CreateSkuParam struct {
|
||||||
|
Ware *CreateSkuParamWare `json:"ware"`
|
||||||
|
Skus []*CreateSkuParamSkus `json:"skus"`
|
||||||
|
}
|
||||||
|
|
||||||
type CreateSkuResult struct {
|
type CreateSkuResult struct {
|
||||||
WareID int `json:"wareId"`
|
WareID int64 `json:"wareId"`
|
||||||
skus []struct {
|
Skus []struct {
|
||||||
SkuID int `json:"skuId"`
|
WareID int64 `json:"wareId"`
|
||||||
saleAttrs []struct {
|
SkuID int64 `json:"skuId"`
|
||||||
AttrValueAlias []string `json:"attrValueAlias"`
|
SaleAttrs []struct {
|
||||||
AttrID string `json:"attrId"`
|
// AttrValueAlias []string `json:"attrValueAlias"`
|
||||||
AttrValues []string `json:"attrValues"`
|
AttrID string `json:"attrId"`
|
||||||
}
|
AttrValues []string `json:"attrValues"`
|
||||||
}
|
} `json:"saleAttrs"`
|
||||||
|
} `json:"skus"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type UpdateWareParam struct {
|
type UpdateWareParam struct {
|
||||||
@@ -176,11 +182,13 @@ func (a *API) FindVendorCategories() (findVendorCategoriesResult []*FindVendorCa
|
|||||||
//京东商城发布商品(创建商品)
|
//京东商城发布商品(创建商品)
|
||||||
//https://open.jd.com/home/home#/doc/api?apiCateId=48&apiId=1379&apiName=jingdong.ware.write.add
|
//https://open.jd.com/home/home#/doc/api?apiCateId=48&apiId=1379&apiName=jingdong.ware.write.add
|
||||||
func (a *API) CreateWare(createSkuParamWare *CreateSkuParamWare, createSkuParamSkus []*CreateSkuParamSkus) (createSkuResult *CreateSkuResult, err error) {
|
func (a *API) CreateWare(createSkuParamWare *CreateSkuParamWare, createSkuParamSkus []*CreateSkuParamSkus) (createSkuResult *CreateSkuResult, err error) {
|
||||||
wares, _ := json.Marshal(createSkuParamWare)
|
c := &CreateSkuParam{
|
||||||
skus, _ := json.Marshal(createSkuParamSkus)
|
Ware: createSkuParamWare,
|
||||||
|
Skus: createSkuParamSkus,
|
||||||
|
}
|
||||||
|
cc, _ := json.Marshal(c)
|
||||||
result, err := a.AccessAPI2("jingdong.ware.write.add", prodURL, map[string]interface{}{
|
result, err := a.AccessAPI2("jingdong.ware.write.add", prodURL, map[string]interface{}{
|
||||||
"ware": string(wares),
|
"360buy_param_json": string(cc),
|
||||||
"skus": string(skus),
|
|
||||||
})
|
})
|
||||||
if err == nil {
|
if err == nil {
|
||||||
utils.Map2StructByJson(result["jingdong_ware_write_add_responce"].(map[string]interface{})["ware"], &createSkuResult, false)
|
utils.Map2StructByJson(result["jingdong_ware_write_add_responce"].(map[string]interface{})["ware"], &createSkuResult, false)
|
||||||
@@ -249,34 +257,69 @@ func (a *API) DeleteWare(wareId int) (err error) {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type FindAttrsResult struct {
|
||||||
|
ID int `json:"id"`
|
||||||
|
OrderSort int `json:"orderSort"`
|
||||||
|
InputType int `json:"inputType"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Features []struct {
|
||||||
|
Fvalue string `json:"fvalue"`
|
||||||
|
Key string `json:"key"`
|
||||||
|
} `json:"features"`
|
||||||
|
CatID int `json:"catId"`
|
||||||
|
AttributeType int `json:"attributeType"`
|
||||||
|
IsRequired bool `json:"isRequired"`
|
||||||
|
}
|
||||||
|
|
||||||
//获取类目属性ID
|
//获取类目属性ID
|
||||||
//https://open.jd.com/home/home#/doc/api?apiCateId=62&apiId=2809&apiName=jingdong.category.read.findAttrsByCategoryIdUnlimitCate
|
//https://open.jd.com/home/home#/doc/api?apiCateId=62&apiId=2809&apiName=jingdong.category.read.findAttrsByCategoryIdUnlimitCate
|
||||||
func (a *API) FindAttrs(cid int) (err error) {
|
func (a *API) FindAttrs(cid int) (findAttrsResult []*FindAttrsResult, err error) {
|
||||||
_, err = a.AccessAPI("jingdong.category.read.findAttrsByCategoryIdUnlimitCate", prodURL, map[string]interface{}{
|
result, err := a.AccessAPI("jingdong.category.read.findAttrsByCategoryIdUnlimitCate", prodURL, map[string]interface{}{
|
||||||
"cid": cid,
|
"cid": cid,
|
||||||
|
// "attributeType": 4,
|
||||||
})
|
})
|
||||||
return err
|
if err == nil {
|
||||||
|
utils.Map2StructByJson(result["jingdong_category_read_findAttrsByCategoryIdUnlimitCate_responce"].(map[string]interface{})["findattrsbycategoryidunlimitcate_result"], &findAttrsResult, false)
|
||||||
|
}
|
||||||
|
return findAttrsResult, err
|
||||||
|
}
|
||||||
|
|
||||||
|
type FindValuesByAttrIdResult struct {
|
||||||
|
ID int64 `json:"id"`
|
||||||
|
OrderSort int `json:"orderSort"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
CatID int `json:"catId"`
|
||||||
|
AttID int `json:"attId"`
|
||||||
}
|
}
|
||||||
|
|
||||||
//获取类目属性值
|
//获取类目属性值
|
||||||
//https://open.jd.com/home/home#/doc/api?apiCateId=62&apiId=2821&apiName=jingdong.category.read.findValuesByAttrIdUnlimit
|
//https://open.jd.com/home/home#/doc/api?apiCateId=62&apiId=2821&apiName=jingdong.category.read.findValuesByAttrIdUnlimit
|
||||||
func (a *API) FindValuesByAttrId(categoryAttrId int) (err error) {
|
func (a *API) FindValuesByAttrId(categoryAttrId int) (findValuesByAttrIdResult []*FindValuesByAttrIdResult, maxOrder int, err error) {
|
||||||
_, err = a.AccessAPI("jingdong.category.read.findValuesByAttrIdUnlimit", prodURL, map[string]interface{}{
|
result, err := a.AccessAPI("jingdong.category.read.findValuesByAttrIdUnlimit", prodURL, map[string]interface{}{
|
||||||
"categoryAttrId": categoryAttrId,
|
"categoryAttrId": categoryAttrId,
|
||||||
})
|
})
|
||||||
return err
|
if err == nil {
|
||||||
|
utils.Map2StructByJson(result["jingdong_category_read_findValuesByAttrIdUnlimit_responce"].(map[string]interface{})["findvaluesbyattridunlimit_result"], &findValuesByAttrIdResult, false)
|
||||||
|
}
|
||||||
|
return findValuesByAttrIdResult, findValuesByAttrIdResult[len(findValuesByAttrIdResult)-1].OrderSort, err
|
||||||
}
|
}
|
||||||
|
|
||||||
//新增类目属性值
|
//新增类目属性值
|
||||||
//https://open.jd.com/home/home#/doc/api?apiCateId=62&apiId=1262&apiName=jingdong.category.write.saveVenderAttrValue
|
//https://open.jd.com/home/home#/doc/api?apiCateId=62&apiId=1262&apiName=jingdong.category.write.saveVenderAttrValue
|
||||||
func (a *API) SaveVenderAttrValue(attValue string, attributeId, categoryId, indexId int) (err error) {
|
func (a *API) SaveVenderAttrValue(attValue string, attributeId, categoryId, indexId int) (categoryAttrId int64, err error) {
|
||||||
_, err = a.AccessAPI("jingdong.category.write.saveVenderAttrValue", prodURL, map[string]interface{}{
|
_, err = a.AccessAPI("jingdong.category.write.saveVenderAttrValue", prodURL, map[string]interface{}{
|
||||||
"attValue": attValue,
|
"attValue": attValue,
|
||||||
"attributeId": attributeId,
|
"attributeId": attributeId,
|
||||||
"categoryId": categoryId,
|
"categoryId": categoryId,
|
||||||
"indexId": indexId,
|
"indexId": indexId,
|
||||||
})
|
})
|
||||||
return err
|
result, _, err := a.FindValuesByAttrId(attributeId)
|
||||||
|
for _, v := range result {
|
||||||
|
if v.OrderSort == indexId {
|
||||||
|
categoryAttrId = v.ID
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return categoryAttrId, err
|
||||||
}
|
}
|
||||||
|
|
||||||
//设置sku库存
|
//设置sku库存
|
||||||
|
|||||||
@@ -134,23 +134,23 @@ func TestCreateSku(t *testing.T) {
|
|||||||
var attrs2 []*CreateSkuParamAttrs
|
var attrs2 []*CreateSkuParamAttrs
|
||||||
var attrs3 []*CreateSkuParamAttrs
|
var attrs3 []*CreateSkuParamAttrs
|
||||||
ware := &CreateSkuParamWare{
|
ware := &CreateSkuParamWare{
|
||||||
Title: "测试商品1",
|
Title: "测试商品1",
|
||||||
ShopCategorys: []int{11},
|
// ShopCategorys: []int{11},
|
||||||
CategoryID: 13577,
|
CategoryID: 13577,
|
||||||
TransportID: TransportID,
|
TransportID: TransportID,
|
||||||
MobileDesc: "测试",
|
MobileDesc: "测试",
|
||||||
Introduction: "测试",
|
Introduction: "测试",
|
||||||
WareStatus: 8,
|
WareStatus: 8,
|
||||||
OuterID: "1",
|
OuterID: "1",
|
||||||
Weight: 2300,
|
Weight: 2300,
|
||||||
Height: 100,
|
Height: 100,
|
||||||
Length: 100,
|
Length: 100,
|
||||||
Width: 100,
|
Width: 100,
|
||||||
JdPrice: 20,
|
JdPrice: 20,
|
||||||
MarketPrice: 10,
|
MarketPrice: 10,
|
||||||
VenderID: 0,
|
VenderID: 0,
|
||||||
BrandID: JxBrandId,
|
BrandID: JxBrandId,
|
||||||
Is7ToReturn: 0,
|
Is7ToReturn: 0,
|
||||||
}
|
}
|
||||||
image := &CreateSkuParamImages{
|
image := &CreateSkuParamImages{
|
||||||
ColorID: "0000000000",
|
ColorID: "0000000000",
|
||||||
@@ -164,12 +164,14 @@ func TestCreateSku(t *testing.T) {
|
|||||||
StockNum: 1,
|
StockNum: 1,
|
||||||
Type: "com.jd.pop.ware.ic.api.domain.sku",
|
Type: "com.jd.pop.ware.ic.api.domain.sku",
|
||||||
Type2: "com.jd.pop.ware.ic.api.domain.Sku",
|
Type2: "com.jd.pop.ware.ic.api.domain.Sku",
|
||||||
|
OuterID: "1",
|
||||||
}
|
}
|
||||||
sku2 := &CreateSkuParamSkus{
|
sku2 := &CreateSkuParamSkus{
|
||||||
JdPrice: 10,
|
JdPrice: 10,
|
||||||
StockNum: 1,
|
StockNum: 1,
|
||||||
Type: "com.jd.pop.ware.ic.api.domain.sku",
|
Type: "com.jd.pop.ware.ic.api.domain.sku",
|
||||||
Type2: "com.jd.pop.ware.ic.api.domain.Sku",
|
Type2: "com.jd.pop.ware.ic.api.domain.Sku",
|
||||||
|
OuterID: "2",
|
||||||
}
|
}
|
||||||
attr1 := &CreateSkuParamAttrs{
|
attr1 := &CreateSkuParamAttrs{
|
||||||
AttrID: "109692",
|
AttrID: "109692",
|
||||||
@@ -206,6 +208,7 @@ func TestCreateSku(t *testing.T) {
|
|||||||
sku.SaleAttrs = attrs2
|
sku.SaleAttrs = attrs2
|
||||||
skus = append(skus, sku)
|
skus = append(skus, sku)
|
||||||
skus = append(skus, sku2)
|
skus = append(skus, sku2)
|
||||||
|
// ware.Skus = skus
|
||||||
result, err := api.CreateWare(ware, skus)
|
result, err := api.CreateWare(ware, skus)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
@@ -214,23 +217,24 @@ func TestCreateSku(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestFindAttrs(t *testing.T) {
|
func TestFindAttrs(t *testing.T) {
|
||||||
err := api.FindAttrs(13577)
|
result, err := api.FindAttrs(13577)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
// t.Log(utils.Format4Output(result, false))
|
t.Log(utils.Format4Output(result, false))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFindValuesByAttrId(t *testing.T) {
|
func TestFindValuesByAttrId(t *testing.T) {
|
||||||
err := api.FindValuesByAttrId(109692)
|
result, no, err := api.FindValuesByAttrId(109692)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
// t.Log(utils.Format4Output(result, false))
|
t.Log(utils.Format4Output(result, false))
|
||||||
|
fmt.Println(no)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSaveVenderAttrValue(t *testing.T) {
|
func TestSaveVenderAttrValue(t *testing.T) {
|
||||||
err := api.SaveVenderAttrValue("0.5", 160806, 13571, 1)
|
err := api.SaveVenderAttrValue("100g", 1001027606, 13577, 2)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user