京东商城
This commit is contained in:
@@ -394,7 +394,7 @@ func (a *API) UpdateSkuStock(skuId, stockNum int) (err error) {
|
||||
//https://open.jd.com/home/home#/doc/api?apiCateId=48&apiId=1253&apiName=jingdong.price.write.updateSkuJdPrice
|
||||
//单位为元
|
||||
func (a *API) UpdateSkuJdPrice(skuId int, jdPrice float64) (err error) {
|
||||
_, err = a.AccessAPI("jingdong.price.write.updateSkuJdPrice", prodURL, map[string]interface{}{
|
||||
_, err = a.AccessAPI2("jingdong.price.write.updateSkuJdPrice", prodURL, map[string]interface{}{
|
||||
"skuId": skuId,
|
||||
"jdPrice": jdPrice,
|
||||
})
|
||||
@@ -452,10 +452,12 @@ type SearchWare4ValidResult struct {
|
||||
//搜索有效商品
|
||||
//https://open.jd.com/home/home#/doc/api?apiCateId=48&apiId=1587&apiName=jingdong.ware.read.searchWare4Valid
|
||||
func (a *API) SearchWare4Valid(searchKey string) (searchWare4ValidResult *SearchWare4ValidResult, err error) {
|
||||
result, err := a.AccessAPI("jingdong.ware.read.searchWare4Valid", prodURL, map[string]interface{}{
|
||||
"searchKey": searchKey,
|
||||
"searchField": "title",
|
||||
})
|
||||
param := make(map[string]interface{})
|
||||
if searchKey != "" {
|
||||
param["searchKey"] = searchKey
|
||||
param["searchField"] = "title"
|
||||
}
|
||||
result, err := a.AccessAPI("jingdong.ware.read.searchWare4Valid", prodURL, param)
|
||||
if err == nil {
|
||||
utils.Map2StructByJson(result["jingdong_ware_read_searchWare4Valid_responce"].(map[string]interface{})["page"], &searchWare4ValidResult, false)
|
||||
}
|
||||
@@ -516,3 +518,22 @@ func (a *API) FindSkuById(skuId int64) (findSkuByIdParam *FindSkuByIdParam, err
|
||||
}
|
||||
return findSkuByIdParam, err
|
||||
}
|
||||
|
||||
//获取单个商品
|
||||
//https://open.jd.com/home/home#/doc/api?apiCateId=48&apiId=1244&apiName=jingdong.ware.read.findWareById
|
||||
func (a *API) FindWareById(wareId int64) (err error) {
|
||||
_, err = a.AccessAPI2("jingdong.ware.read.findWareById", prodURL, map[string]interface{}{
|
||||
"wareId": wareId,
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
//更新商品市场价
|
||||
//https://open.jd.com/home/home#/doc/api?apiCateId=48&apiId=1248&apiName=jingdong.price.write.updateWareMarketPrice
|
||||
func (a *API) UpdateWareMarketPrice(wareId int64, marketPrice float64) (err error) {
|
||||
_, err = a.AccessAPI2("jingdong.price.write.updateWareMarketPrice", prodURL, map[string]interface{}{
|
||||
"wareId": wareId,
|
||||
"marketPrice": marketPrice,
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -307,7 +307,7 @@ func TestImageUpdate(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestSearchWare4Valid(t *testing.T) {
|
||||
result, err := api.SearchWare4Valid("红薯")
|
||||
result, err := api.SearchWare4Valid("")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -368,3 +368,18 @@ func TestFindSkuById(t *testing.T) {
|
||||
}
|
||||
t.Log(utils.Format4Output(result, false))
|
||||
}
|
||||
|
||||
func TestUpdateWareMarketPrice(t *testing.T) {
|
||||
err := api.UpdateWareMarketPrice(14539778638, 500)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// t.Log(utils.Format4Output(result, false))
|
||||
}
|
||||
|
||||
func TestBB(t *testing.T) {
|
||||
result, _ := api.SearchWare4Valid("")
|
||||
for _, v := range result.Data {
|
||||
api.UpdateWareMarketPrice(v.WareID, 500)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,19 +23,6 @@ func (a *API) AccessStorePage(fullURL string, bizParams map[string]interface{},
|
||||
request.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
||||
} else {
|
||||
request, _ = http.NewRequest(http.MethodGet, utils.GenerateGetURL(fullURL, "", bizParams), nil)
|
||||
request.Header.Set("accept", "application/json, text/plain, */*")
|
||||
request.Header.Set("accept-encoding", "gzip, deflate, br")
|
||||
request.Header.Set("accept-language", "zh-CN,zh;q=0.9")
|
||||
request.Header.Set("referer", "https://stores.shop.jd.com/")
|
||||
request.Header.Set("user-agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36")
|
||||
request.Header.Set("sec-fetch-mode", "cors")
|
||||
request.Header.Set("sec-fetch-site", "same-origin")
|
||||
request.Header.Set("x-requested-with", " XMLHttpRequest")
|
||||
request.Header.Set(":authority", "stores.shop.jd.com")
|
||||
request.Header.Set(":method", "GET")
|
||||
request.Header.Set(":path", "/stores/updateStoreStatus?storeId=24332466&storeStatus=6")
|
||||
request.Header.Set(":scheme", "https")
|
||||
|
||||
}
|
||||
a.FillRequestCookies(request)
|
||||
return request
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package jdshopapi
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
@@ -35,3 +38,18 @@ func TestNewInfoList(t *testing.T) {
|
||||
}
|
||||
t.Log(utils.Format4Output(result, false))
|
||||
}
|
||||
|
||||
func Test11(t *testing.T) {
|
||||
request, _ := http.NewRequest(http.MethodGet, "https://stores.shop.jd.com/stores/updateStoreStatus?storeId=24332466&storeStatus=1", nil)
|
||||
c := &http.Cookie{
|
||||
Name: "thor",
|
||||
Value: "80FAF09E9A09B6E618A68057BDFCFCB8C86E8252DC9F7D3B34572625904FBA0AB6BF053A5325612EC0407791BB05F5301356E71E8B282C40C06D0B5DF3439DEECB102A78FAFF7AC0FC4E2D1FA8DD8BBAE1A011E50B5C74F1870AD982D7BF453F470F31F2241B73AC4C25485025C2ABEBC8A538AF7257824D2FAEE300A1435175B0B451FB5C19B78D729FC83152CA3BAF",
|
||||
}
|
||||
request.AddCookie(c)
|
||||
client := &http.Client{}
|
||||
fmt.Println("test1", request.URL)
|
||||
response, _ := client.Do(request)
|
||||
defer response.Body.Close()
|
||||
bodyData, _ := ioutil.ReadAll(response.Body)
|
||||
fmt.Println("test1", string(bodyData))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user