添加抖音分类id获取方式

This commit is contained in:
邹宗楠
2023-10-10 17:02:25 +08:00
parent fae696dd91
commit 1f32f08835
2 changed files with 61 additions and 6 deletions

View File

@@ -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 {

View File

@@ -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)
}