根据名字查询京东upc

This commit is contained in:
苏尹岚
2019-12-13 18:36:32 +08:00
parent 8493aa4ee0
commit 1ec3724e34
2 changed files with 41 additions and 0 deletions

View File

@@ -264,6 +264,12 @@ type JdUserPostResult struct {
} `json:"status"`
}
type JdSkus struct {
Name string `json:name`
UpcCode string `json:upcCode`
ImgList []string `json:imgList`
}
var (
monthSaleNumReg = regexp.MustCompile(`(\d+)([千|万])`)
pageExceedLimitCodes = map[string]int{
@@ -752,3 +758,34 @@ func (a *API) GetJdStoreLevel(vendorOrgCode, vendorStoreID string) (level string
}
return level, err
}
// 根据商品名查找京东商品upc编码
// https://pms-store.jddj.com/product/searchProductStd
func (a *API) GetJdUpcCodeByName(name string, pageNo, pageSize int) (jdSkus []*JdSkus, totalCount int, err error) {
jdParams := map[string]interface{}{
"searchType": 1,
"firstCategoryId": 0,
"currentPage": pageNo,
"pageSize": pageSize,
"productName": name,
}
result, _ := a.AccessStorePage2("https://pms-store.jddj.com/product/searchProductStd", jdParams, true, "")
data := result.(map[string]interface{})
totalCount = int(utils.Interface2Int64WithDefault(data["total"], 0))
for _, v := range data["rows"].([]interface{}) {
var ImgList []string
ImgStr := v.(map[string]interface{})["productImageList"].([]interface{})
for _, vv := range ImgStr {
ImgList = append(ImgList, "http://img20.360buyimg.com/vc/"+vv.(string))
}
if v.(map[string]interface{})["upcCode"].(string) != "" {
jdSku := &JdSkus{
Name: v.(map[string]interface{})["name"].(string),
UpcCode: v.(map[string]interface{})["upcCode"].(string),
ImgList: ImgList,
}
jdSkus = append(jdSkus, jdSku)
}
}
return jdSkus, totalCount, err
}

View File

@@ -230,3 +230,7 @@ func TestIsJdManagerUser(t *testing.T) {
func TestGetJdStoreLevel(t *testing.T) {
api.GetJdStoreLevel("320406", "11732427")
}
func TestGetJdUpcCodeByName(t *testing.T) {
api.GetJdUpcCodeByName("大米", 1, 5)
}