package jdshopapi import ( "encoding/json" "fmt" "net/http" "strings" "git.rosy.net.cn/baseapi" "git.rosy.net.cn/baseapi/platformapi" "git.rosy.net.cn/baseapi/utils" ) func (a *API) AccessStorePage(fullURL string, bizParams map[string]interface{}, isPost bool) (retVal map[string]interface{}, err error) { if a.GetCookieCount() == 0 { return nil, fmt.Errorf("需要设置Store Cookie才能使用此方法") } err = platformapi.AccessPlatformAPIWithRetry(a.client, func() *http.Request { var request *http.Request if isPost { request, _ = http.NewRequest(http.MethodPost, fullURL, strings.NewReader(utils.Map2URLValues(bizParams).Encode())) request.Header.Set("Content-Type", "application/x-www-form-urlencoded") } else { request, _ = http.NewRequest(http.MethodGet, utils.GenerateGetURL(fullURL, "", bizParams), nil) } 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 } 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"` Open string `json:"open"` OrderNo string `json:"orderNo"` ParentID string `json:"parentId"` Title string `json:"title"` Type string `json:"type"` } //京东商城创建或修改店内分类 //https://seller.shop.jd.com/vendershop/vendershop_shopCategory.action# func (a *API) CreateShopCategory(createShopCategoryParam []*CreateShopCategoryParam) (err error) { result, _ := json.MarshalIndent(createShopCategoryParam, "", "") _, err = a.AccessStorePage("https://seller.shop.jd.com/vendershop/vendershop_doShopCategory.action", map[string]interface{}{ "categoryJson": string(result), }, true) return err } //京东商城设置门店营业状态 //https://stores.shop.jd.com/stores/updateStoreStatus?storeId=24330156&storeStatus=6 func (a *API) UpdateStoreStatus(storeID, storeStatus int) (err error) { _, err = a.AccessStorePage("http://stores.shop.jd.com/stores/updateStoreStatus", map[string]interface{}{ "storeId": storeID, "storeStatus": storeStatus, }, false) 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 }