From 1f32f08835bddcc59b8b41f7abceff4bdcf7fd33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Tue, 10 Oct 2023 17:02:25 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=8A=96=E9=9F=B3=E5=88=86?= =?UTF-8?q?=E7=B1=BBid=E8=8E=B7=E5=8F=96=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- platformapi/tiktok_shop/tiktok_api/sku.go | 54 +++++++++++++++++++ .../tiktok_shop/tiktok_api/sku_delete_test.go | 13 ++--- 2 files changed, 61 insertions(+), 6 deletions(-) diff --git a/platformapi/tiktok_shop/tiktok_api/sku.go b/platformapi/tiktok_shop/tiktok_api/sku.go index bc9f745b..8df3607b 100644 --- a/platformapi/tiktok_shop/tiktok_api/sku.go +++ b/platformapi/tiktok_shop/tiktok_api/sku.go @@ -571,6 +571,60 @@ func (a *API) GetProductAuditList(page, pageSize, status int64) ([]product_audit return result.Data.Records, result.Data.Total, nil } +// GetRecommendCategoryByName 根据名称预测商品类目,优先四级>三级>二级>1级 +func (a *API) GetRecommendCategoryByName(name string) (int64, error) { + if name == "" { + return 0, errors.New("抖音根据名称预测分类,名称不能为空") + } + request := product_GetRecommendCategory_request.New() + request.Param.Scene = "category_infer" + request.Param.Name = name + + result, err := request.Execute(a.accessTokenObj) + if err != nil { + return 0, err + } + if result.Code != RequestSuccessCode { + return 0, errors.New(result.SubMsg + ":" + result.LogId) + } + + if len(result.Data.CategoryDetails) == 0 { + return 0, errors.New("抖音根据图片获取分类,返回值为0") + } + + var firstCid int64 + var secondCid int64 + var thirdCid int64 + var fourthCid int64 + + index := len(result.Data.CategoryDetails) - 1 + if result.Data.CategoryDetails[index].CategoryDetail.FirstCid != 0 { + firstCid = result.Data.CategoryDetails[index].CategoryDetail.FirstCid + } + if result.Data.CategoryDetails[index].CategoryDetail.SecondCid != 0 { + secondCid = result.Data.CategoryDetails[index].CategoryDetail.SecondCid + } + if result.Data.CategoryDetails[index].CategoryDetail.ThirdCid != 0 { + thirdCid = result.Data.CategoryDetails[index].CategoryDetail.ThirdCid + } + if result.Data.CategoryDetails[index].CategoryDetail.FourthCid != 0 { + fourthCid = result.Data.CategoryDetails[index].CategoryDetail.FourthCid + } + if fourthCid != 0 { + return fourthCid, nil + } + if thirdCid != 0 { + return thirdCid, nil + } + if secondCid != 0 { + return secondCid, nil + } + if firstCid != 0 { + return firstCid, nil + } + return 0, errors.New("抖音获取推荐分类异常") +} + // GetRecommendCategory 根据图片预测商品类目,优先四级>三级>二级>1级 func (a *API) GetRecommendCategory(picParams []string) (int64, error) { if len(picParams) == 0 { diff --git a/platformapi/tiktok_shop/tiktok_api/sku_delete_test.go b/platformapi/tiktok_shop/tiktok_api/sku_delete_test.go index d7db4aea..6359c7d7 100644 --- a/platformapi/tiktok_shop/tiktok_api/sku_delete_test.go +++ b/platformapi/tiktok_shop/tiktok_api/sku_delete_test.go @@ -20,15 +20,16 @@ func TestN2ame(t *testing.T) { func TestGetRecommendCategory(t *testing.T) { //img, _, err := GetTiktokImgListTest(a, "668707", "", "", "http://img20.360buyimg.com/vc/jfs/t1/8979/39/8591/236012/5c0e45f3E1537c120/a66aafc95cf66977.jpg", "http://img20.360buyimg.com/vc/jfs/t1/23027/3/955/82830/5c0e45f3E0855eeae/ae65ee9555a29579.jpg") //fmt.Println(err) - img := []string{ - //"https://p3-aio.ecombdimg.com/obj/ecom-shop-material/VqGYBUaL_m_f229ad3ce7a93d906a2412709e363825_sx_762890_www750-3527", - "https://p3-aio.ecombdimg.com/obj/ecom-shop-material/VqGYBUaL_m_7457cda4c101d05bcd2a1258b61d2ba1_sx_223234_www800-800", - //"https://p3-aio.ecombdimg.com/obj/ecom-shop-material/v1_GhxlaZ_70852585116381186630419_c55b8401b00e96e4114431a1dbd7c99c_sx_582346_www1000-1000", - } + //img := []string{ + // //"https://p3-aio.ecombdimg.com/obj/ecom-shop-material/VqGYBUaL_m_f229ad3ce7a93d906a2412709e363825_sx_762890_www750-3527", + // "https://p3-aio.ecombdimg.com/obj/ecom-shop-material/VqGYBUaL_m_7457cda4c101d05bcd2a1258b61d2ba1_sx_223234_www800-800", + // //"https://p3-aio.ecombdimg.com/obj/ecom-shop-material/v1_GhxlaZ_70852585116381186630419_c55b8401b00e96e4114431a1dbd7c99c_sx_582346_www1000-1000", + //} var token = `{"access_token":"90283046-8f2b-46cf-90f1-e522b229e784","expires_in":1697080460,"scope":"SCOPE","shop_id":57939570,"shop_name":"京西菜市速食","refresh_token":"ae493f0f-97d8-43ca-9b0e-727480add1fa","authority_id":""}` var a = New("7267745202649957900", "51998fcf-d521-4553-8c0c-fa662c8dbd6e", token) - data, err := a.GetRecommendCategory(img) + name := "广茄 " + data, err := a.GetRecommendCategoryByName(name) fmt.Println(data) fmt.Println(err) }