京东api新增获取京东指导价

This commit is contained in:
苏尹岚
2020-01-21 11:55:12 +08:00
parent 1bc0db94bc
commit 404b9b9b38
2 changed files with 42 additions and 10 deletions

View File

@@ -21,6 +21,7 @@ const (
accessStorePageCookieName = "shop.o2o.jd.com1"
accessStorePageCookieName2 = "lsp-store1.jddj.com"
accessStorePageCookieName3 = "josl-privilege1.jddj.com"
accessStorePageCookieName4 = "o2o-stock1.jddj.com"
)
type SkuPageImg struct {
@@ -292,16 +293,17 @@ var (
pageExceedLimitCodes = map[string]int{
"403": 1,
}
pageCanRetryCodes = map[string]int{}
regexpTable = regexp.MustCompile(`<table class="check-container" data-container="list1">([\s\S]*?)</table>`)
regexpTd = regexp.MustCompile(`<td>([0-9].*)</td>`)
regexpJDUserPage = regexp.MustCompile(`共([\s\S].*)页/([\s\S].*)条记录`)
regexpJDTr = regexp.MustCompile(`<tr>([\s\S]*?)</tr>`)
regexpJDTdInfo = regexp.MustCompile(`<td>([\s\S]*?)</td>`)
regexpJDUserID = regexp.MustCompile(`value="(.*)"`)
regexpJDUserIsManager = regexp.MustCompile(`<div class="list-mask">`)
regexpJDStoreLevel = regexp.MustCompile(`门店分级 (.*)`)
htmlResponeURLs = []string{
pageCanRetryCodes = map[string]int{}
regexpTable = regexp.MustCompile(`<table class="check-container" data-container="list1">([\s\S]*?)</table>`)
regexpTd = regexp.MustCompile(`<td>([0-9].*)</td>`)
regexpJDUserPage = regexp.MustCompile(`共([\s\S].*)页/([\s\S].*)条记录`)
regexpJDTr = regexp.MustCompile(`<tr>([\s\S]*?)</tr>`)
regexpJDTdInfo = regexp.MustCompile(`<td>([\s\S]*?)</td>`)
regexpJDUserID = regexp.MustCompile(`value="(.*)"`)
regexpJDUserIsManager = regexp.MustCompile(`<div class="list-mask">`)
regexpJDStoreLevel = regexp.MustCompile(`门店分级 (.*)`)
regexpJDSkuDirectPrice = regexp.MustCompile(`<td style="max-width: 80px">([\s\S]*?)</td>`)
htmlResponeURLs = []string{
"login-o2o.jddj.com/jpuser/",
"sta-store.jddj.com/store/",
}
@@ -323,6 +325,7 @@ func (a *API) SetJdCookie(cookieValue string) {
a.SetCookie(accessStorePageCookieName, cookieValue)
a.SetCookie(accessStorePageCookieName2, cookieValue)
a.SetCookie(accessStorePageCookieName3, cookieValue)
a.SetCookie(accessStorePageCookieName4, cookieValue)
}
func (a *API) AccessStorePage2(fullURL string, params map[string]interface{}, isPost bool, resultKey string) (retVal interface{}, err error) {
@@ -812,3 +815,27 @@ func (a *API) GetJdUpcCodeByName(name, upcCode string, pageNo, pageSize int) (pr
}
return productInfos, err
}
//获取京东商品的指导价格
//https://stock-store.jddj.com/storeproduct/query
func (a *API) GetJdSkuDirectPrice(skuID int) (price int64, err error) {
jdParams := map[string]interface{}{
"outSkuId": skuID,
"fixedStatus": 1,
"stationNo": "allStation",
"numStatus": 0,
"currentPage": 1,
"pageSize": 1,
}
body, err := a.AccessStorePage2("https://stock-store.jddj.com/storeproduct/query", jdParams, true, "")
bodyStr := body.(map[string]interface{})["fakeData"].(string)
result := regexpJDSkuDirectPrice.FindAllStringSubmatch(bodyStr, -1)
if len(result) > 0 {
if result[3][1] != "" {
return utils.Float64TwoInt64(utils.Str2Float64(result[3][1]) * 100), err
} else {
return 0, err
}
}
return price, err
}

View File

@@ -234,3 +234,8 @@ func TestGetJdStoreLevel(t *testing.T) {
func TestGetJdUpcCodeByName(t *testing.T) {
api.GetJdUpcCodeByName("", "6952395700895", 2, 5)
}
func TestGetJdSkuDirectPrice(t *testing.T) {
result, err := api.GetJdSkuDirectPrice(31031)
fmt.Println("test1", result, err)
}