jd fake api
This commit is contained in:
92
platformapi/jdapi/fake_jdapi.go
Normal file
92
platformapi/jdapi/fake_jdapi.go
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
package jdapi
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
|
||||||
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (a *API) FakeOrderQuery(jdParams map[string]interface{}) (retVal []interface{}, totalCount int, err error) {
|
||||||
|
retVal, totalCount, err = a.AccessAPIHavePage("order/orderQuery", jdParams, nil, nil, nil)
|
||||||
|
return retVal, totalCount, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *API) FakeQuerySingleOrder(orderId, deliveryStationNo string) (map[string]interface{}, error) {
|
||||||
|
jdParams := make(map[string]interface{})
|
||||||
|
jdParams["orderId"] = orderId
|
||||||
|
jdParams["deliveryStationNo "] = deliveryStationNo
|
||||||
|
result, _, err := a.FakeOrderQuery(jdParams)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if len(result) == 0 {
|
||||||
|
return nil, ErrCanNotFindOrder
|
||||||
|
}
|
||||||
|
return result[0].(map[string]interface{}), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *API) FakeBatchUpdateCurrentQtys(trackInfo, outStationNo, stationNo string, skuStockList []*SkuStock, userPin string) (responseList []*StoreSkuBatchUpdateResponse, err error) {
|
||||||
|
if (outStationNo == "" && stationNo == "") || (outStationNo != "" && stationNo != "") {
|
||||||
|
return nil, errors.New("outStationNo and stationNo can not all be empty or have value")
|
||||||
|
}
|
||||||
|
jdParams := map[string]interface{}{
|
||||||
|
"skuStockList": skuStockList,
|
||||||
|
"userPin": utils.GetAPIOperator(userPin),
|
||||||
|
}
|
||||||
|
if outStationNo != "" {
|
||||||
|
jdParams["outStationNo"] = outStationNo
|
||||||
|
} else {
|
||||||
|
jdParams["stationNo"] = stationNo
|
||||||
|
}
|
||||||
|
result, err := a.AccessAPINoPage2("stock/batchUpdateCurrentQtys", jdParams, nil, nil, genNoPageResultParser("retCode", "retMsg", "data", "0"), trackInfo)
|
||||||
|
if result != nil {
|
||||||
|
var err2 error
|
||||||
|
if responseList, err2 = a.handleBatchOpResult(outStationNo, stationNo, len(skuStockList), err, result, ""); err2 != nil && err == nil {
|
||||||
|
err = err2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return responseList, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *API) FakeBatchUpdateVendibility(trackInfo, outStationNo, stationNo string, stockVendibilityList []*StockVendibility, userPin string) (responseList []*StoreSkuBatchUpdateResponse, err error) {
|
||||||
|
if (outStationNo == "" && stationNo == "") || (outStationNo != "" && stationNo != "") {
|
||||||
|
return nil, errors.New("outStationNo and stationNo can not all be empty or have value")
|
||||||
|
}
|
||||||
|
jdParams := map[string]interface{}{
|
||||||
|
"stockVendibilityList": stockVendibilityList,
|
||||||
|
"userPin": utils.GetAPIOperator(userPin),
|
||||||
|
}
|
||||||
|
if outStationNo != "" {
|
||||||
|
jdParams["outStationNo"] = outStationNo
|
||||||
|
} else {
|
||||||
|
jdParams["stationNo"] = stationNo
|
||||||
|
}
|
||||||
|
// 此函数在全部失败时,err仍然返回成功
|
||||||
|
result, err := a.AccessAPINoPage2("stock/batchUpdateVendibility", jdParams, nil, nil, genNoPageResultParser("retCode", "retMsg", "data", "0"), trackInfo)
|
||||||
|
if result != nil {
|
||||||
|
var err2 error
|
||||||
|
if responseList, err2 = a.handleBatchOpResult(outStationNo, stationNo, len(stockVendibilityList), err, result, ""); err2 != nil && err == nil {
|
||||||
|
err = err2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return responseList, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *API) FakeUpdateVendorStationPrice(trackInfo string, outStationNo, stationNo string, skuPriceInfoList []*SkuPriceInfo) (responseList []*StoreSkuBatchUpdateResponse, err error) {
|
||||||
|
jdParams := map[string]interface{}{
|
||||||
|
"skuPriceInfoList": skuPriceInfoList,
|
||||||
|
}
|
||||||
|
if outStationNo != "" {
|
||||||
|
jdParams["outStationNo"] = outStationNo
|
||||||
|
} else {
|
||||||
|
jdParams["stationNo"] = stationNo
|
||||||
|
}
|
||||||
|
result, err := a.AccessAPINoPage2("price/batchUpdateStationPrice", jdParams, nil, nil, genNoPageResultParser("code", "msg", "result", "0"), trackInfo)
|
||||||
|
if result != nil {
|
||||||
|
var err2 error
|
||||||
|
if responseList, err2 = a.handleBatchOpResult(outStationNo, stationNo, len(skuPriceInfoList), err, result, "json2"); err2 != nil && err == nil {
|
||||||
|
err = err2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return responseList, err
|
||||||
|
}
|
||||||
105
platformapi/jdapi/fake_jdapi_test.go
Normal file
105
platformapi/jdapi/fake_jdapi_test.go
Normal file
@@ -0,0 +1,105 @@
|
|||||||
|
package jdapi
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestFakeOrderQuery(t *testing.T) {
|
||||||
|
api := NewFakeJD("ndslkv9asl@djf_n7askdjfk$", "http://test.jxc4.com/qqqq")
|
||||||
|
|
||||||
|
retVal, err := api.FakeQuerySingleOrder("2000483691000741", "11866256")
|
||||||
|
t.Log(utils.Format4Output(retVal, false))
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
if false {
|
||||||
|
t.Log(utils.Format4Output(retVal, false))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFakeBatchUpdateCurrentQtys(t *testing.T) {
|
||||||
|
api := NewFakeJD("ndslkv9asl@djf_n7askdjfk$", "http://test.jxc4.com/qqqq")
|
||||||
|
|
||||||
|
retVal, err := api.FakeBatchUpdateCurrentQtys("", "", "11943257", []*SkuStock{
|
||||||
|
&SkuStock{
|
||||||
|
OutSkuId: "2029937911",
|
||||||
|
StockQty: 88,
|
||||||
|
},
|
||||||
|
}, "test")
|
||||||
|
t.Log(utils.Format4Output(retVal, false))
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
if false {
|
||||||
|
t.Log(utils.Format4Output(retVal, false))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFakeBatchUpdateVendibility(t *testing.T) {
|
||||||
|
api := NewFakeJD("ndslkv9asl@djf_n7askdjfk$", "http://test.jxc4.com/qqqq")
|
||||||
|
|
||||||
|
retVal, err := api.FakeBatchUpdateVendibility("", "", "11943257", []*StockVendibility{
|
||||||
|
&StockVendibility{
|
||||||
|
OutSkuId: "2029937911",
|
||||||
|
DoSale: true,
|
||||||
|
},
|
||||||
|
}, "test")
|
||||||
|
t.Log(utils.Format4Output(retVal, false))
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
if false {
|
||||||
|
t.Log(utils.Format4Output(retVal, false))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFakeUpdateVendorStationPrice(t *testing.T) {
|
||||||
|
api := NewFakeJD("ndslkv9asl@djf_n7askdjfk$", "http://test.jxc4.com/qqqq")
|
||||||
|
|
||||||
|
retVal, err := api.FakeUpdateVendorStationPrice("", "", "11943257", []*SkuPriceInfo{
|
||||||
|
&SkuPriceInfo{
|
||||||
|
OutSkuId: "2029937911",
|
||||||
|
Price: 4567,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
t.Log(utils.Format4Output(retVal, false))
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
if false {
|
||||||
|
t.Log(utils.Format4Output(retVal, false))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFakeCreatePromotionSingle(t *testing.T) {
|
||||||
|
api := NewFakeJD("ndslkv9asl@djf_n7askdjfk$", "http://test.jxc4.com/qqqq")
|
||||||
|
|
||||||
|
infoId, err := api.CreatePromotionInfosSingle("测试1", time.Now(), time.Now().Add(24*time.Hour), "", "", "")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
t.Log(infoId)
|
||||||
|
err = api.CreatePromotionRulesSingle(infoId, "", 1, 1, 1, 1, "")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
skuInfos, err := api.CreatePromotionSkuSingle(infoId, "", []*PromotionSku{
|
||||||
|
&PromotionSku{
|
||||||
|
OutSkuID: "2216",
|
||||||
|
StationNo: 11943257,
|
||||||
|
PromotionPrice: 500,
|
||||||
|
LimitSkuCount: 2,
|
||||||
|
},
|
||||||
|
}, "")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
t.Log(skuInfos)
|
||||||
|
err = api.ConfirmPromotionSingle(infoId, "", "")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -61,6 +61,7 @@ const (
|
|||||||
type API struct {
|
type API struct {
|
||||||
platformapi.APICookie
|
platformapi.APICookie
|
||||||
|
|
||||||
|
baseURL string
|
||||||
token string
|
token string
|
||||||
appKey string
|
appKey string
|
||||||
appSecret string
|
appSecret string
|
||||||
@@ -134,6 +135,7 @@ func New(token, appKey, appSecret string, config ...*platformapi.APIConfig) *API
|
|||||||
curConfig = *config[0]
|
curConfig = *config[0]
|
||||||
}
|
}
|
||||||
return &API{
|
return &API{
|
||||||
|
baseURL: prodURL,
|
||||||
token: token,
|
token: token,
|
||||||
appKey: appKey,
|
appKey: appKey,
|
||||||
appSecret: appSecret,
|
appSecret: appSecret,
|
||||||
@@ -142,6 +144,12 @@ func New(token, appKey, appSecret string, config ...*platformapi.APIConfig) *API
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func NewFakeJD(token, baseURL string, config ...*platformapi.APIConfig) *API {
|
||||||
|
a := New(token, "", "", config...)
|
||||||
|
a.baseURL = baseURL
|
||||||
|
return a
|
||||||
|
}
|
||||||
|
|
||||||
func NewPageOnly(cookie string, config ...*platformapi.APIConfig) *API {
|
func NewPageOnly(cookie string, config ...*platformapi.APIConfig) *API {
|
||||||
api := New("", "", "", config...)
|
api := New("", "", "", config...)
|
||||||
api.SetCookie(accessStorePageCookieName, cookie)
|
api.SetCookie(accessStorePageCookieName, cookie)
|
||||||
@@ -186,11 +194,11 @@ func (a *API) AccessAPI2(apiStr string, jdParams map[string]interface{}, traceIn
|
|||||||
params[signKey] = sign
|
params[signKey] = sign
|
||||||
var request *http.Request
|
var request *http.Request
|
||||||
if userGet {
|
if userGet {
|
||||||
fullURL := utils.GenerateGetURL(prodURL, apiStr, params)
|
fullURL := utils.GenerateGetURL(a.baseURL, apiStr, params)
|
||||||
// baseapi.SugarLogger.Debug(fullURL)
|
// baseapi.SugarLogger.Debug(fullURL)
|
||||||
request, _ = http.NewRequest(http.MethodGet, fullURL, nil)
|
request, _ = http.NewRequest(http.MethodGet, fullURL, nil)
|
||||||
} else {
|
} else {
|
||||||
fullURL := prodURL + "/" + apiStr
|
fullURL := utils.GenerateGetURL(a.baseURL, apiStr, nil)
|
||||||
// baseapi.SugarLogger.Debug(utils.Map2URLValues(params).Encode())
|
// baseapi.SugarLogger.Debug(utils.Map2URLValues(params).Encode())
|
||||||
request, _ = http.NewRequest(http.MethodPost, fullURL, strings.NewReader(utils.Map2URLValues(params).Encode()))
|
request, _ = http.NewRequest(http.MethodPost, fullURL, strings.NewReader(utils.Map2URLValues(params).Encode()))
|
||||||
request.Header.Set("charset", "UTF-8")
|
request.Header.Set("charset", "UTF-8")
|
||||||
|
|||||||
Reference in New Issue
Block a user