根据名字查询京东upc
This commit is contained in:
@@ -264,6 +264,12 @@ type JdUserPostResult struct {
|
|||||||
} `json:"status"`
|
} `json:"status"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type JdSkus struct {
|
||||||
|
Name string `json:name`
|
||||||
|
UpcCode string `json:upcCode`
|
||||||
|
ImgList []string `json:imgList`
|
||||||
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
monthSaleNumReg = regexp.MustCompile(`(\d+)([千|万])`)
|
monthSaleNumReg = regexp.MustCompile(`(\d+)([千|万])`)
|
||||||
pageExceedLimitCodes = map[string]int{
|
pageExceedLimitCodes = map[string]int{
|
||||||
@@ -752,3 +758,34 @@ func (a *API) GetJdStoreLevel(vendorOrgCode, vendorStoreID string) (level string
|
|||||||
}
|
}
|
||||||
return level, err
|
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
|
||||||
|
}
|
||||||
|
|||||||
@@ -230,3 +230,7 @@ func TestIsJdManagerUser(t *testing.T) {
|
|||||||
func TestGetJdStoreLevel(t *testing.T) {
|
func TestGetJdStoreLevel(t *testing.T) {
|
||||||
api.GetJdStoreLevel("320406", "11732427")
|
api.GetJdStoreLevel("320406", "11732427")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGetJdUpcCodeByName(t *testing.T) {
|
||||||
|
api.GetJdUpcCodeByName("大米", 1, 5)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user