From 2e08ddebebaddee88338ec9b82b4c4082d2aa713 Mon Sep 17 00:00:00 2001 From: gazebo Date: Fri, 11 Oct 2019 16:09:57 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BE=8E=E5=9B=A2=E9=85=8D=E9=80=81=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E9=99=90=E6=B5=81=E9=94=99=E8=AF=AF=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- platformapi/mtpsapi/mtpsapi.go | 10 ++++ platformapi/mtpsapi/mtpsapi_test.go | 83 ---------------------------- platformapi/mtpsapi/shop_test.go | 85 +++++++++++++++++++++++++++++ 3 files changed, 95 insertions(+), 83 deletions(-) diff --git a/platformapi/mtpsapi/mtpsapi.go b/platformapi/mtpsapi/mtpsapi.go index 0ab16c99..650ec71e 100644 --- a/platformapi/mtpsapi/mtpsapi.go +++ b/platformapi/mtpsapi/mtpsapi.go @@ -82,6 +82,7 @@ const ( const ( ResponseCodeSuccess = 0 ResponseCodeInvalidParam = 4 // 参数格式错误 + ResponseCodeFlowControl = 11 // 接口流控 ResponseCodeShopNotExist = 112 // 门店不存在 ) @@ -165,6 +166,12 @@ type API struct { config *platformapi.APIConfig } +var ( + exceedLimitCodes = map[int]int{ + ResponseCodeFlowControl: 1, + } +) + func New(appKey, secret string, config ...*platformapi.APIConfig) *API { curConfig := platformapi.DefAPIConfig if len(config) > 0 { @@ -246,6 +253,9 @@ func (a *API) AccessAPI2(baseURL, action string, params map[string]interface{}) } retVal.Message, _ = jsonResult1[msgKey].(string) newErr := utils.NewErrorIntCode(retVal.Message, code) + if _, ok := exceedLimitCodes[code]; ok { + return platformapi.ErrLevelExceedLimit, newErr + } return platformapi.ErrLevelCodeIsNotOK, newErr }) return retVal, err diff --git a/platformapi/mtpsapi/mtpsapi_test.go b/platformapi/mtpsapi/mtpsapi_test.go index c8731a7f..69ba5463 100644 --- a/platformapi/mtpsapi/mtpsapi_test.go +++ b/platformapi/mtpsapi/mtpsapi_test.go @@ -57,89 +57,6 @@ func TestAccessAPI(t *testing.T) { } } -func TestCreateOrderByShop(t *testing.T) { - basicParams := &CreateOrderByShopParam{ - DeliveryID: 123456789, - OrderID: "order_123456789", - // 设置测试门店 id,测试门店的坐标地址为 97235456,31065079(高德坐标),配送范围3km - ShopID: "test_0001", - DeliveryServiceCode: DeliveryServiceCodeIntime, - ReceiverName: "xjh", - ReceiverAddress: "九里堤", - ReceiverPhone: "18112345678", - ReceiverLng: 97235456, - ReceiverLat: 31065079, - CoordinateType: CoordinateTypeMars, - GoodsValue: 12.34, - GoodsWeight: 3.4, - OrderType: OrderTypeASAP, - } - - order, err := api.CreateOrderByShop(basicParams, nil) - handleError(t, err) - if order != nil { - sugarLogger.Debugf("order:%v", order) - } -} - -func TestShopQuery(t *testing.T) { - shopInfo, err := api.ShopQuery("not exist") - if err == nil { - t.Fatal("应该报错找不到门店") - } - shopInfo, err = api.ShopQuery("11726346") - if err != nil { - t.Fatal(err) - } - t.Log(utils.Format4Output(shopInfo, false)) -} - -func TestShopCreate(t *testing.T) { - shopInfo := &ShopInfo{ - ShopID: "11726346", - ShopName: "测试门店", - Category: ShopCategoryFruit, - SecondCategory: ShopCategoryFruitFruit, - ContactName: "徐", - ContactPhone: "18180948107", - ShopAddress: "北京市通州区五所南路与玉桥西路南延交叉口北100米梨园农副产品交易中心 水果区", - ShopLng: 116672496, - ShopLat: 39879491, - CoordinateType: CoordinateTypeMars, - DeliveryServiceCodes: utils.Int2Str(DeliveryServiceCodeRapid), - BusinessHours: "[{\"beginTime\":\"09:00\",\"endTime\":\"18:00\"}]", - } - _, err := api.ShopCreate(shopInfo) - if err != nil { - t.Fatal(err) - } -} - -func TestSimulateArrange(t *testing.T) { - err := api.SimulateArrange(123456789, "1529387562097059") - handleError(t, err) -} - -func TestSimulatePickup(t *testing.T) { - err := api.SimulatePickup(123456789, "1529387562097059") - handleError(t, err) -} - -func TestSimulateRearrange(t *testing.T) { - err := api.SimulateRearrange(123456789, "1529387562097059") - handleError(t, err) -} - -func TestSimulateDeliver(t *testing.T) { - err := api.SimulateDeliver(123456789, "1529387562097059") - handleError(t, err) -} - -func TestSimulateReportException(t *testing.T) { - err := api.SimulateReportException(123456789, "1529387562097059") - handleError(t, err) -} - func TestCancelOrder(t *testing.T) { result, err := api.CancelOrder(123456789, "1529387562097059", CancelReasonMerchantOther, "just a test") handleError(t, err) diff --git a/platformapi/mtpsapi/shop_test.go b/platformapi/mtpsapi/shop_test.go index 3737f384..5638cdc1 100644 --- a/platformapi/mtpsapi/shop_test.go +++ b/platformapi/mtpsapi/shop_test.go @@ -2,6 +2,8 @@ package mtpsapi import ( "testing" + + "git.rosy.net.cn/baseapi/utils" ) func TestSimulateShopStatus(t *testing.T) { @@ -10,3 +12,86 @@ func TestSimulateShopStatus(t *testing.T) { t.Fatal(err) } } + +func TestCreateOrderByShop(t *testing.T) { + basicParams := &CreateOrderByShopParam{ + DeliveryID: 123456789, + OrderID: "order_123456789", + // 设置测试门店 id,测试门店的坐标地址为 97235456,31065079(高德坐标),配送范围3km + ShopID: "test_0001", + DeliveryServiceCode: DeliveryServiceCodeIntime, + ReceiverName: "xjh", + ReceiverAddress: "九里堤", + ReceiverPhone: "18112345678", + ReceiverLng: 97235456, + ReceiverLat: 31065079, + CoordinateType: CoordinateTypeMars, + GoodsValue: 12.34, + GoodsWeight: 3.4, + OrderType: OrderTypeASAP, + } + + order, err := api.CreateOrderByShop(basicParams, nil) + handleError(t, err) + if order != nil { + sugarLogger.Debugf("order:%v", order) + } +} + +func TestShopQuery(t *testing.T) { + shopInfo, err := api.ShopQuery("not exist") + if err == nil { + t.Fatal("应该报错找不到门店") + } + shopInfo, err = api.ShopQuery("11733028") + if err != nil { + t.Fatal(err) + } + t.Log(utils.Format4Output(shopInfo, false)) +} + +func TestShopCreate(t *testing.T) { + shopInfo := &ShopInfo{ + ShopID: "11726346", + ShopName: "测试门店", + Category: ShopCategoryFruit, + SecondCategory: ShopCategoryFruitFruit, + ContactName: "徐", + ContactPhone: "18180948107", + ShopAddress: "北京市通州区五所南路与玉桥西路南延交叉口北100米梨园农副产品交易中心 水果区", + ShopLng: 116672496, + ShopLat: 39879491, + CoordinateType: CoordinateTypeMars, + DeliveryServiceCodes: utils.Int2Str(DeliveryServiceCodeRapid), + BusinessHours: "[{\"beginTime\":\"09:00\",\"endTime\":\"18:00\"}]", + } + _, err := api.ShopCreate(shopInfo) + if err != nil { + t.Fatal(err) + } +} + +func TestSimulateArrange(t *testing.T) { + err := api.SimulateArrange(123456789, "1529387562097059") + handleError(t, err) +} + +func TestSimulatePickup(t *testing.T) { + err := api.SimulatePickup(123456789, "1529387562097059") + handleError(t, err) +} + +func TestSimulateRearrange(t *testing.T) { + err := api.SimulateRearrange(123456789, "1529387562097059") + handleError(t, err) +} + +func TestSimulateDeliver(t *testing.T) { + err := api.SimulateDeliver(123456789, "1529387562097059") + handleError(t, err) +} + +func TestSimulateReportException(t *testing.T) { + err := api.SimulateReportException(123456789, "1529387562097059") + handleError(t, err) +}