Files
baseapi/platformapi/jdshopapi/store_page.go
2020-05-09 08:58:55 +08:00

62 lines
2.1 KiB
Go

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{}) (retVal map[string]interface{}, err error) {
if a.GetCookieCount() == 0 {
return nil, fmt.Errorf("需要设置Store Cookie才能使用此方法")
}
err = platformapi.AccessPlatformAPIWithRetry(a.client,
func() *http.Request {
request, _ := http.NewRequest(http.MethodPost, fullURL, strings.NewReader(utils.Map2URLValues(bizParams).Encode()))
request.Header.Set("Content-Type", "application/x-www-form-urlencoded")
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),
})
return err
}