京东商城增加图片等api

This commit is contained in:
苏尹岚
2020-05-18 18:14:56 +08:00
parent 92719d69bc
commit 6a48e3d9b1
8 changed files with 202 additions and 9 deletions

View File

@@ -32,6 +32,7 @@ const (
TransportID = 2158480
JxBrandId = 559853
JdShopMaxStock = 9999
JdsPromiseID = 13725637
)
var (

View File

@@ -15,5 +15,6 @@ func init() {
sugarLogger = logger.Sugar()
baseapi.Init(sugarLogger)
api = New("de8157b447584885910f429011e49cb93yjq", "E1D746D42474D5F1F1A10CECE75D99F6", "efa7e1d1a22640fa990e6cf164b28608")
api.SetCookie("thor", "80FAF09E9A09B6E618A68057BDFCFCB80B57C077668C68E68C659988D87CA3D30CE71D7C176A2F674F9EFC12F1390A96A0C8EDB82467985D69FCA31025221D54466C846BA08AB136D63402989D94C9A4F8DF795EB804208BDC9E3A34D1CF385C1C74D400531A9EAA20E8AD46FBF30ED86D87215D74AEDA38DFE58689AC995A44D179162CFB6B35D013B98B8CAFD2BB19")
api.SetCookieWithStr(`
shshshfpa=13b38d4a-8ba0-df12-0012-82d9a37fb835-1573795914; shshshfpb=abYp8Dq5JobRtp2pkZa7MbA%3D%3D; __jdu=1142616513; pinId=WMIzMhF5BfL6nJp9AcA2-A; pin=shop_jxcs; unick=shop_jxcs; _tp=7FBEvLyPe%2FKcgxsfY5lRgA%3D%3D; _pst=shop_jxcs; areaId=22; ipLoc-djd=22-1930-50948-57092; user-key=3ec204b4-f204-4320-98e3-b2569c757800; cn=0; shshshfp=5d23828ee6ea3a33e1a58588db1713f8; 3AB9D23F7A4B3C9B=AK36FFYF5J6WMPRH7YTXMEX4CATHR6NAA3IQEESU2I33FEJRQ3DRLU4SZJYD2XGFLCFW43DHYP5HQKOMR4EFQSLKLA; navigation=[%22shop_jxcs%22]; __jdv=122270672|baidu|-|organic|not set|1589514011252; language=zh_CN; TrackID=1qooSkvOHmdoU2EV8bHDA9AOSIRIAYzjSIWnUCct0h4Bux509sQEg9LAouFJa-AAMujfEjfJxaPfAJeICF42zGh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GW36EBPLZMZP2MQCAMJNO44FKT46B7VDVT7KQTELESOOF6E377AYC3NWKQF6ICIYBW4BA4JL5QG2NHGNOHOUJDNUW3N22UF32DLFLEIQGVO2W55J6AKPPBT227XA5NO4S3NFVIUUUADGOYH56T72MTNXCILWVMN4RMUNVFMGL4ISGXJS7YILE7A2ESPAU43MISAOZM2BR53MGRB5OZSQZPV5DBDCN2OVVT3XT5N2VMFELARQNTMAJCDBGXFURSN2Q7SYULLKZEZHTYWWOI65LS5OIHLUZQKWFGMNSQF2UBSYV7FG46CWJGMVHOGV3FY4RUEVJK6BQ223QK3H3VMTHXCZOZV4GKR5EWGIZZDVUAK4B36BPA5HPBO7PXKBOEXEBX77IYBNQLCGMK72J4VKNOUWNHKWDSFPN6KQIYW7LTTKIRM4LRSSSVOVUFIQPCMOEILTFRQNS2I37WSSK225CJE; __jda=65775340.1142616513.1573036516.1589782831.1589789767.45; __jdc=65775340; b-sec=S2JWP6CAFP7K4I6PXVBUVCO6YVXUX2JAPDHLX5RZUDE4YKCGOEXGOA5NYG3ULYGWMVWZPFAYGLWLG; thor=80FAF09E9A09B6E618A68057BDFCFCB80B57C077668C68E68C659988D87CA3D37FCC5A20A186C30C849E2E33858C98E41420F3A2BE2464FF8EAD3EEBB279280587D57E77A4999B7B49576359492C233C8D5D9B7DEA8F0E5E553447715087DB2CF1B329C4C356F7FE318C8126585214D64E92A0D7B60FB51193844DAEB12179234C3FB9479040C9499602D046EE2EFD15; __jdb=65775340.10.1142616513|45.1589789767; _BELONG_CLIENT_=WPSC4XJXWK5USS4JNZY2X7VRLR5MCBKRSVHEXABGTHDGISIQK5YOLZUXYE7IOIM7MOKO74H6CRN6WHAAR4TMDV3XZWMXZRCRT5XRNE3V356BTOB2Y7LPK66VWQK6HPTGWVXIDXDCPVE3W5WMHAIO6AT2LX2XXVNUCXR34ZWFK6HY45CORGIKOSYDYZBF27WOKTUX6BS4FZMIJWNUX6CB4JAA25ZLF7ZEKYOO4QV5HTSBXGNRM3E242MBI6V5D4C5VJDQ3EOYCOW5BMTUJZACIBHXQFAVLRF76VQY5PNJGGJNBEZHSFYYJA3YORRT7FB5AHCOIFQKF3W5RWNUX6CB4JAA26JNMO7AYWNUPZF5HTSBXGNRM3E242MBI6V5D4C5VJDQ3EOYCOW5BWZDKMOJ5BS6II53ERY6ALV3ZWPF42L4CPUHEGPYIII35KDC4FCNVCORCXFD6IVNLBEDPB2GGP4UHWNRUDOQBDIW7RZJXBA2WV5ANZOTEGUCDWYRVQS2YUTIZNZ276PRYG4N56V6YTII7MBKBC7LYHO7C555HTSBXGNRM3E466AYN67DHWVM5HQFJ4NFDO5BTWOHF2RM4GWR4IYPFK3LX4PQJCQ; _base_=YKH2KDFHMOZBLCUV7NSRBWQUJPBI7JIMU5R3EFJ5UDHJ5LCU7R2NILKK5UJ6GLA2RGYT464UKXAI4Z6HPCTN4UQM3WHVQ4ENFP57OC2DC7JQLRXRUO5PW6B77O6UXAZ4TCNE6YVKRXISVLBYGYO44RCDDPWDA4AEL7ZLXI2SG4SOQWCP5WPWO6EFS7HEHMRWVKBRVHB33TFD4SMNBHRJCTDFHU6SZXCZD6RFXX2OORYGL5H2GYF2IIH2KKD4T72IR4F577G2E5II2OMMXYF2GDYNTS7WGAUXFEWRJ3CTKDBDWMHUKJQF4ZFOTNBBYBIZRXZYERXXIG6ATYD3V7NVY3TOZIW2VFHXMQGAZGXCBNYDPXFCM2ZMCS474KZ44S5F; _lvtc_=65FOEDQPOB2BPOGZJRC2FRXKOY`)
}

View File

@@ -45,12 +45,12 @@ type CreateSkuParamWare struct {
WareStatus int `json:"wareStatus"` // 否 新增仅可以使用 1:从未上架 8:在售(上架) 商品状态1:从未上架 2:自主下架 4:系统下架 8:在售 513:从未上架 待审核 514:自主下架 待审核 516:系统下架 待审核 520:在售 待审核 1025:从未上架 审核不通过 暂时没用 1026:自主下架 审核不通过 暂时没用 1028:系统下架 审核不通过 1032:在售 审核不通过
OuterID string `json:"outerId"` // 否 无 商品外部ID,商家自行设置的ID便于关联京东商品
VenderID int `json:"venderId"`
Is7ToReturn int `json:"is7ToReturn"` // 0 不支持1 支持7天 2支持90天
// Is7ToReturn int `json:"is7ToReturn"` // 0 不支持1 支持7天 2支持90天
// ItemNum string `json:"itemNum"` // 否 无 商品货号
// BarCode string `json:"barCode"` // 否 无 商品的条形码.UPC码,SN码,PLU码统称为条形码
// WareLocation int `json:"wareLocation"` // 否 无 商品产出地区
// Delivery int `json:"delivery"` // 否 无 商品发货地
// PromiseID int `json:"promiseId"` // 否 无 配送时效
PromiseID int `json:"promiseId"` // 否 无 配送时效
// adWords // 否 无 商品广告词对象 (单品页显示的优先级低于促销广告词)
// Wrap string `json:"wrap"` //否 无 包装规格(已废弃)
// PackListing string `json:"packListing"` // 否 无 商品包装清单
@@ -142,12 +142,25 @@ type CreateSkuResult struct {
}
type UpdateWareParam struct {
WareID int64 `json:"wareId"`
Title string `json:"title"` //否 标题 商品名称 限制45个字符内
VenderID int64 `json:"venderId"`
WareID int64 `json:"wareId"`
Title string `json:"title"` //否 标题 商品名称 限制45个字符内
VenderID int64 `json:"venderId"`
PromiseID int `json:"promiseId"` // 否 无 配送时效
// Weight int `json:"weight"` //否 无 商品重量,单位kg
}
type QueryPictureReuslt struct {
PictureSize int `json:"picture_size"`
PictureWidth int `json:"picture_width"`
PictureURL string `json:"picture_url"`
PictureID string `json:"picture_id"`
PictureName string `json:"picture_name"`
PictureType string `json:"picture_type"`
Created int64 `json:"created"`
PictureCateID int `json:"picture_cate_id"`
PictureHeight int `json:"picture_height"`
}
//查询商家所有的店内分类
//https://open.jd.com/home/home#/doc/api?apiCateId=88&apiId=2801&apiName=jingdong.vender.shopcategory.findShopCategoriesByVenderId
func (a *API) FindShopCategories() (findShopCategoriesResult []*FindShopCategoriesResult, err error) {
@@ -226,14 +239,14 @@ func (a *API) UploadPicture(imageData []byte, pictureCateID int, pictureName str
//京东商城查询图片
//https://open.jd.com/home/home#/doc/api?apiCateId=61&apiId=230&apiName=jingdong.imgzone.picture.query
func (a *API) QueryPicture(pictureName string) (uploadPictureResult *UploadPictureResult, err error) {
func (a *API) QueryPicture(pictureName string) (queryPictureReuslt []*QueryPictureReuslt, err error) {
result, err := a.AccessAPI("jingdong.imgzone.picture.query", prodURL, map[string]interface{}{
"picture_name": pictureName,
})
if err == nil {
utils.Map2StructByJson(result["jingdong_imgzone_picture_upload_responce"], &uploadPictureResult, false)
utils.Map2StructByJson(result["jingdong_imgzone_picture_query_responce"].(map[string]interface{})["imgList"], &queryPictureReuslt, false)
}
return uploadPictureResult, err
return queryPictureReuslt, err
}
//查询运费模板

View File

@@ -160,6 +160,7 @@ func TestCreateSku(t *testing.T) {
MarketPrice: 10,
VenderID: 0,
BrandID: JxBrandId,
PromiseID: JdsPromiseID,
}
ware.Features = features
ware.MobileDesc = "aa"
@@ -288,3 +289,11 @@ func TestFindSkuStock(t *testing.T) {
}
// t.Log(utils.Format4Output(result, false))
}
func TestQueryPicture(t *testing.T) {
result, err := api.QueryPicture("[畅销]香蕉1")
if err != nil {
t.Fatal(err)
}
t.Log(utils.Format4Output(result, false))
}

View File

@@ -1,7 +1,9 @@
package jdshopapi
import (
"encoding/json"
"fmt"
"strings"
"git.rosy.net.cn/baseapi/utils"
)
@@ -41,6 +43,23 @@ type GetAddressCodeResult struct {
AreaID int `json:"areaId"`
}
type QueryEntityStoreResult struct {
VenderID int64 `json:"venderId"`
StoreID int64 `json:"storeId"`
StoreName string `json:"storeName"`
Address string `json:"address"`
FullAddress string `json:"fullAddress"`
Phone string `json:"phone"`
AddrCode int `json:"addrCode"`
Status int `json:"status"`
Coordinate string `json:"coordinate"`
ExtendValue string `json:"extendValue"`
ExStoreID string `json:"exStoreId"`
AuditStatus int `json:"auditStatus"`
StoreStatus string `json:"storeStatus"`
OperateStatus string `json:"operateStatus"`
}
//创建门店
//https://open.jd.com/home/home#/doc/api?apiCateId=351&apiId=2224&apiName=jingdong.createEntityStore
func (a *API) CreateEntityStore(createEntityStoreParam *CreateEntityStoreParam) (vendorStoreID string, err error) {
@@ -145,3 +164,19 @@ func (a *API) UpdateSkuSiteStock(skuId, stockNum, siteId int) (err error) {
})
return err
}
//获取门店信息
//https://open.jd.com/home/home#/doc/api?apiCateId=351&apiId=2223&apiName=jingdong.queryEntityStore
func (a *API) QueryEntityStore(storeId int64) (queryEntityStoreResult *QueryEntityStoreResult, err error) {
result, err := a.AccessAPI("jingdong.queryEntityStore", prodURL, map[string]interface{}{
"storeId": storeId,
})
if err == nil {
data := result["jingdong_queryEntityStore_responce"].(map[string]interface{})["queryentitystore_result"].(map[string]interface{})["jsonResult"].(string)
data = strings.ReplaceAll(data, "[", "")
data = strings.ReplaceAll(data, "]", "")
err = json.Unmarshal([]byte(data), &queryEntityStoreResult)
// utils.Map2StructByJson(data, &queryEntityStoreResult, false)
}
return queryEntityStoreResult, err
}

View File

@@ -51,6 +51,36 @@ func (a *API) AccessStorePage(fullURL string, bizParams map[string]interface{},
return retVal, err
}
func (a *API) AccessStorePage2(fullURL string, bizParams map[string]interface{}) (retVal map[string]interface{}, err error) {
if a.GetCookieCount() == 0 {
return nil, fmt.Errorf("需要设置Store Cookie才能使用此方法")
}
data, _ := json.Marshal(bizParams)
err = platformapi.AccessPlatformAPIWithRetry(a.client,
func() *http.Request {
request, _ := http.NewRequest(http.MethodPost, fullURL, strings.NewReader(string(data)))
request.Header.Set("Content-Type", "application/json;charset=UTF-8")
a.FillRequestCookies(request)
return request
},
a.config,
func(response *http.Response, bodyStr string, jsonResult1 map[string]interface{}) (errLevel string, err error) {
if jsonResult1 == nil {
return platformapi.ErrLevelRecoverableErr, fmt.Errorf("mapData is nil")
}
if err == nil {
if jsonResult1["error_response"] != nil {
errLevel = platformapi.ErrLevelGeneralFail
err = utils.NewErrorCode(jsonResult1["error_response"].(map[string]interface{})["zh_desc"].(string), jsonResult1["error_response"].(map[string]interface{})["code"].(string))
baseapi.SugarLogger.Debugf("jdeclp AccessAPI failed, jsonResult1:%s", utils.Format4Output(jsonResult1, true))
}
retVal = jsonResult1
}
return errLevel, err
})
return retVal, err
}
type CreateShopCategoryParam struct {
HomeShow string `json:"homeShow"`
ID string `json:"id"`
@@ -80,3 +110,89 @@ func (a *API) UpdateStoreStatus(storeID, storeStatus int) (err error) {
}, true)
return err
}
type NewInfoListResult struct {
ID int `json:"id"`
VenderID int `json:"venderId"`
CompanyID interface{} `json:"companyId"`
CompanyName interface{} `json:"companyName"`
StoreType interface{} `json:"storeType"`
Name string `json:"name"`
AddCode int `json:"addCode"`
AddCodeName interface{} `json:"addCodeName"`
AddName string `json:"addName"`
AddCode1 int `json:"addCode1"`
AddCode2 int `json:"addCode2"`
AddCode4 interface{} `json:"addCode4"`
BussinessBeginTime interface{} `json:"bussinessBeginTime"`
BussinessEndTime interface{} `json:"bussinessEndTime"`
AddNameExtend interface{} `json:"addNameExtend"`
Coordinate interface{} `json:"coordinate"`
CommodityNum int `json:"commodityNum"`
Status interface{} `json:"status"`
Created interface{} `json:"created"`
Modified interface{} `json:"modified"`
Phone interface{} `json:"phone"`
EncryptPhone interface{} `json:"encryptPhone"`
StoreGroupIds interface{} `json:"storeGroupIds"`
VirtualStoresIds interface{} `json:"virtualStoresIds"`
VirtualStoresInDB interface{} `json:"virtualStoresInDB"`
Address interface{} `json:"address"`
Account interface{} `json:"account"`
UserName interface{} `json:"userName"`
Pwd interface{} `json:"pwd"`
CrmPwd interface{} `json:"crmPwd"`
Type interface{} `json:"type"`
AccountIsAuth interface{} `json:"accountIsAuth"`
Slogan interface{} `json:"slogan"`
Mobilephone interface{} `json:"mobilephone"`
EncryptMobilephone interface{} `json:"encryptMobilephone"`
UnboundedBizType interface{} `json:"unboundedBizType"`
ExStoreID string `json:"exStoreId"`
ExStoreSource interface{} `json:"exStoreSource"`
MdImg interface{} `json:"mdImg"`
AccountName interface{} `json:"accountName"`
StoreStatus int `json:"storeStatus"`
BusinessTime interface{} `json:"businessTime"`
IsBindingPurse interface{} `json:"isBindingPurse"`
GroupName interface{} `json:"groupName"`
SplitID interface{} `json:"splitId"`
BusinessID interface{} `json:"businessId"`
BrandID interface{} `json:"brandId"`
ReturnType interface{} `json:"returnType"`
PhoneType interface{} `json:"phoneType"`
AfterPhone interface{} `json:"afterPhone"`
DeptID interface{} `json:"deptId"`
Remark interface{} `json:"remark"`
AuditStatus int `json:"auditStatus"`
CategoryID1 interface{} `json:"categoryId1"`
CategoryID2 interface{} `json:"categoryId2"`
CategoryName1 interface{} `json:"categoryName1"`
CategoryName2 interface{} `json:"categoryName2"`
ImgURL interface{} `json:"imgUrl"`
StoreStatusName string `json:"storeStatusName"`
AuditStatusName string `json:"auditStatusName"`
OperateStatus interface{} `json:"operateStatus"`
Pin interface{} `json:"pin"`
}
//京东商城查询门店营业状态
//https://stores.shop.jd.com/stores/newInfoList
func (a *API) NewInfoList(storeID int64) (newInfoListResult *NewInfoListResult, err error) {
var newInfoListResult2 []*NewInfoListResult
result, err := a.AccessStorePage2("https://stores.shop.jd.com/stores/newInfoList", map[string]interface{}{
"storeId": storeID,
"inCache": 0,
"index": 1,
"pageSize": 10,
"companyName": nil,
"exStoreId": nil,
"storeName": nil,
"storeStatus": nil,
})
if err == nil {
utils.Map2StructByJson(result["list"], &newInfoListResult2, false)
}
newInfoListResult = newInfoListResult2[0]
return newInfoListResult, err
}

View File

@@ -2,6 +2,8 @@ package jdshopapi
import (
"testing"
"git.rosy.net.cn/baseapi/utils"
)
func TestCreateShopCategory(t *testing.T) {
@@ -25,3 +27,11 @@ func TestUpdateStoreStatus(t *testing.T) {
t.Fatal(err)
}
}
func TestNewInfoList(t *testing.T) {
result, err := api.NewInfoList(24332466)
if err != nil {
t.Fatal(err)
}
t.Log(utils.Format4Output(result, false))
}

View File

@@ -77,3 +77,11 @@ func TestUpdateSkuSiteStock(t *testing.T) {
}
// t.Log(utils.Format4Output(result, false))
}
func TestQueryEntityStore(t *testing.T) {
result, err := api.QueryEntityStore(11)
if err != nil {
t.Fatal(err)
}
t.Log(utils.Format4Output(result, false))
}