41 lines
776 B
Go
41 lines
776 B
Go
package l_ai_brand
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"errors"
|
|
"fmt"
|
|
|
|
"gitea.cdlsxd.cn/self-tools/l_request"
|
|
"strings"
|
|
)
|
|
|
|
func GetBrand(ctx context.Context, goodsName string, brandList []string, address string) (brand string, err error) {
|
|
|
|
request := map[string]interface{}{
|
|
"goods": goodsName,
|
|
"brand_list": strings.Join(brandList, ","),
|
|
}
|
|
req := l_request.Request{
|
|
Method: "POST",
|
|
Url: address,
|
|
Json: request,
|
|
}
|
|
res, err := req.Send()
|
|
if err != nil {
|
|
return
|
|
}
|
|
var resMap BrandRes
|
|
err = json.Unmarshal(res.Content, &resMap)
|
|
brand = resMap.ExtractedBrand
|
|
if brand == "失败" {
|
|
err = errors.New("失败")
|
|
}
|
|
fmt.Printf("品牌名称:%s\n", brand)
|
|
return
|
|
}
|
|
|
|
type BrandRes struct {
|
|
ExtractedBrand string `json:"extracted_brand"`
|
|
}
|