* | 参数 | 类型 | 说明 |
* | {@code offset} | int | 必填,分页偏移;本实现用字符串化的 offset 作游标。 |
- * | {@code length} | int | 必填,分页长度,上限 500,超过会被截断。 |
+ * | {@code length} | int | 必填,分页长度,下限 20、上限 500;
+ * 超出范围会被适配器收窄到边界值(<20 时领星返回 {@code code=102})。 |
* | {@code date_type} | string | 时间类型:{@code update_time}(默认)、
* {@code global_purchase_time}、{@code global_delivery_time}、
* {@code global_payment_time}、{@code delivery_time}(仅 Shopify)。 |
@@ -113,8 +114,11 @@ public class MultiPlatformOrderSource implements LingxingOrderSource {
from = to.minus(Duration.ofDays(LingxingConstants.MAX_QUERY_DAYS));
}
- // 领星 length 上限 500;pageSize 未设置时给 100,与 SalesOrderQuery 的默认值一致
- int length = Math.min(query.pageSize() <= 0 ? 100 : query.pageSize(), LingxingConstants.MAX_PAGE_SIZE);
+ // 领星 length 上限 500、下限 20(传小于 20 会返回 code=102 length最小值为20);
+ // pageSize 未设置时给 100,与 SalesOrderQuery 的默认值一致
+ int requested = query.pageSize() <= 0 ? 100 : query.pageSize();
+ int length = Math.max(LingxingConstants.MIN_PAGE_SIZE,
+ Math.min(requested, LingxingConstants.MAX_PAGE_SIZE));
// 游标就是字符串化的 offset:领星只有 offset 分页,没有不透明游标
int offset = query.cursor() == null ? 0 : Integer.parseInt(query.cursor());
diff --git a/lingxing/src/test/java/common/ecommerce/lingxing/adapter/LingxingLiveSmokeTest.java b/lingxing/src/test/java/common/ecommerce/lingxing/adapter/LingxingLiveSmokeTest.java
index 869af89..965e6d6 100644
--- a/lingxing/src/test/java/common/ecommerce/lingxing/adapter/LingxingLiveSmokeTest.java
+++ b/lingxing/src/test/java/common/ecommerce/lingxing/adapter/LingxingLiveSmokeTest.java
@@ -6,93 +6,102 @@ import common.ecommerce.http.HttpResponse;
import common.ecommerce.http.HttpTransport;
import common.ecommerce.http.JacksonJsonCodec;
import common.ecommerce.http.OkHttpTransport;
+import common.ecommerce.lingxing.LingxingApi;
import common.ecommerce.lingxing.LingxingConstants;
import common.ecommerce.lingxing.auth.LingxingTokenClient;
+import common.ecommerce.lingxing.http.LingxingEnvelope;
+import common.ecommerce.lingxing.http.LingxingRateLimiter;
+import common.ecommerce.lingxing.http.LingxingRequestFactory;
+import common.ecommerce.lingxing.platform.LingxingCall;
+import common.ecommerce.lingxing.platform.multiplatform.order.LingxingOrderFilters;
import common.ecommerce.model.ChannelProvider;
-import common.ecommerce.model.Capability;
import common.ecommerce.model.Platform;
import common.ecommerce.model.account.AccountKey;
import common.ecommerce.model.account.ChannelAccount;
-import common.ecommerce.model.fulfillment.LabelQuery;
-import common.ecommerce.model.fulfillment.OutboundOrder;
-import common.ecommerce.model.fulfillment.OutboundOrderLine;
-import common.ecommerce.model.fulfillment.OutboundOrderQuery;
-import common.ecommerce.model.fulfillment.ShippingLabel;
-import common.ecommerce.model.inbound.InboundReceipt;
-import common.ecommerce.model.inbound.InboundReceiptQuery;
-import common.ecommerce.model.inbound.InboundShipment;
-import common.ecommerce.model.inbound.InboundShipmentQuery;
import common.ecommerce.model.order.OrderLine;
import common.ecommerce.model.order.SalesOrder;
import common.ecommerce.model.order.SalesOrderQuery;
import common.ecommerce.model.order.SalesOrderRef;
-import common.ecommerce.model.product.ProductListing;
-import common.ecommerce.model.product.ProductQuery;
import common.ecommerce.model.settlement.SettlementQuery;
import common.ecommerce.model.settlement.SettlementTransaction;
import common.ecommerce.model.support.Page;
-import common.ecommerce.model.support.PlatformTime;
import common.ecommerce.sdk.ChannelConnection;
import common.ecommerce.sdk.ChannelContext;
import common.ecommerce.spi.AccessToken;
import common.ecommerce.spi.ChannelSecret;
import common.ecommerce.testkit.InMemoryLockProvider;
import common.ecommerce.testkit.InMemoryTokenStore;
+import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.EnabledIfSystemProperty;
import java.time.Clock;
import java.time.Duration;
import java.time.Instant;
import java.time.LocalDate;
import java.util.ArrayList;
+import java.util.Collections;
+import java.util.LinkedHashMap;
import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
/**
- * 领星真实环境冒烟测试。
+ * 领星真实环境冒烟测试:逐个只读查询接口打一页,打印请求与解析结果,人工核对字段映射。
+ *
+ * 覆盖范围:认证 / 店铺 / 订单(多平台、亚马逊 SC、FBM、VC)/ 结算。
+ * 面单与入库见 {@code FulfillmentProbeTest},商品 / 售后见 {@code probe} 包下各自的探针与契约测试。
+ *
+ * 默认跳过,用 {@code -Dlingxing.probe=true} 显式开启;凭据走系统属性,
+ * 与 {@code probe} 包下的探针一致,真实凭证不入库:
*
- * 填上 APP_KEY / APP_SECRET 即可跑(STORE_ID 可留空),然后 IDE 里右键 Run 或执行:
*
- * mvn -pl lingxing -am test -Dtest=LingxingLiveSmokeTest
+ * mvn -pl lingxing -am -DfailIfNoTests=false \
+ * -Dlingxing.probe=true \
+ * -Dlingxing.probe.appKey=你的appId -Dlingxing.probe.appSecret=你的appSecret \
+ * -Dtest=LingxingLiveSmokeTest test
*
*
+ * 可选系统属性(不填则走自动发现或跳过对应段落):
+ *
+ * - {@code -Dlingxing.probe.platformCode=10008}:多平台店铺 / 订单用哪个平台,
+ * 不填不带 {@code platform_code} 过滤,返回账号下全部店铺;
+ * - {@code -Dlingxing.probe.storeId=...}:指定某一家店(store_id / sid),覆盖自动发现的店铺;
+ * - {@code -Dlingxing.probe.vcStoreId=...}:亚马逊 VC 店铺,不填自动发现。
+ *
+ *
* 调用前确认出口 IP 已加入领星白名单,否则会直接 401/403。
*
- * 本类只用于联调,不要把真实凭证提交到仓库。
+ * 只做查询,不调用任何写接口。整轮冒烟共用一个 token(同一个 app 下多店铺共用),
+ * 不要给每个测试单独换 token,否则会频繁触发领星限流。
*/
+@EnabledIfSystemProperty(named = "lingxing.probe", matches = "true")
class LingxingLiveSmokeTest {
- // ==================== 填写这里 ====================
- /** 领星 ERP 开放接口的 AppID。 */
- private static final String APP_KEY = "在这里填 AppID";
- /** 领星 ERP 开放接口的 AppSecret。 */
- private static final String APP_SECRET = "在这里填 AppSecret";
- /** 领星后台的 store_id。 */
- private static final String STORE_ID = "在这里填 store_id";
- // ================================================
+ // ==================== 系统属性(不读环境变量,凭证不入库) ====================
+ private static final String APP_KEY = System.getProperty("lingxing.probe.appKey", "");
+ private static final String APP_SECRET = System.getProperty("lingxing.probe.appSecret", "");
- /**
- * 领星平台码:10008 = Walmart;TikTok 10011、eBay 10003、Amazon SC 10001,按需改。
- *
- * Target / BestBuy / AEPH / Michaels / ECHO / LOS-DLI-US 等平台在领星侧
- * 没有独立平台码。这类平台把本常量置为 {@code null} 或 {@code 0} 即可:
- * 请求体不带 {@code platform_code},店铺与订单都只按 {@code store_id} 过滤,
- * 业务平台由 {@link #smokePlatform()} 兜底成 {@link Platform#CUSTOM}。
- */
- private static final Integer PLATFORM_CODE = 0;
- private static final String BASE_URL = LingxingConstants.PRODUCTION_BASE_URL;
+ /** 多平台用的领星 platform_code;空 / 0 表示不带过滤,返回账号下全部店铺。 */
+ private static final Integer PLATFORM_CODE = optInt("lingxing.probe.platformCode");
- /**
- * 面单冒烟只取前几单,避免把大段 base64 刷到控制台。
- */
- private static final int LABEL_SMOKE_LIMIT = 5;
+ /** 指定某一家店(store_id / sid);空表示按店铺列表自动发现。 */
+ private static final String STORE_ID = opt("lingxing.probe.storeId");
+ /** 亚马逊 VC 的 vc_store_id;空表示自动发现。 */
+ private static final String VC_STORE_ID = opt("lingxing.probe.vcStoreId");
+ // =========================================================================
+
+ private static final String BASE_URL = LingxingConstants.PRODUCTION_BASE_URL;
private final JacksonJsonCodec json = new JacksonJsonCodec();
private final LoggingTransport transport = new LoggingTransport(new OkHttpTransport("common-ecommerce-smoke"));
private final InMemoryTokenStore tokenStore = new InMemoryTokenStore();
private final InMemoryLockProvider locks = new InMemoryLockProvider();
+ private final LingxingAdapter adapter = new LingxingAdapter(transport, json, tokenStore, locks, Clock.systemUTC());
/**
* 第 1 步:只验证认证。失败说明 AppID/AppSecret 不对,或 IP 不在白名单。
@@ -106,8 +115,10 @@ class LingxingLiveSmokeTest {
assertNotNull(token.value());
}
+ // ================================================================ 店铺
+
/**
- * 第 2 步(多平台):先按 {@code PLATFORM_CODE} 列一次店铺,再拉一页订单,
+ * 第 2 步(店铺):先按 {@code PLATFORM_CODE} 列一次店铺,再拉一页订单,
* 打印请求与解析结果,人工核对字段映射。
*
* 订单接口按店铺 id 过滤,而各子平台的 id 口径不同(亚马逊 SC 是数字 {@code sid},
@@ -115,16 +126,15 @@ class LingxingLiveSmokeTest {
* {@code STORE_ID} 填了则优先用它,仅作为「指定某一家店」的覆盖手段。
*
* 没有平台码的平台(Target / BestBuy / AEPH / Michaels / ECHO /
- * LOS-DLI-US 等):把 {@link #PLATFORM_CODE} 置为 {@code null} 或 {@code 0}。
+ * LOS-DLI-US 等):不传 {@code -Dlingxing.probe.platformCode} 即可。
* 此时店铺列表不带 {@code platform_code} 过滤,会返回该领星账号下所有平台的店铺,
* 每行都打印了真实的 {@code platform_code};订单查询只发 {@code store_id},
* 照样能拉到数据。想固定到某一家店时,从打印结果里挑一个 {@code store_id}
- * 填到 {@link #STORE_ID} 即可。
+ * 填到 {@code -Dlingxing.probe.storeId} 即可。
*/
@Test
void pullsOnePageOfOrders() {
requireCredentials();
- LingxingAdapter adapter = adapter();
List shops = listShops(adapter);
String storeId = resolveStoreId(shops);
if (storeId == null) {
@@ -151,22 +161,91 @@ class LingxingLiveSmokeTest {
+ " total=" + o.totalAmount()
+ " country=" + o.shipToCountryCode()
+ " lines=" + o.lines().size()
- + " utc=" + o.occurredAt().utc());
+ + " utc=" + (o.occurredAt() == null ? null : o.occurredAt().utc()));
}
assertFalse(page.size() > 20, "pageSize 未被平台遵守");
}
/**
- * 第 3 步(亚马逊 SC):先列店铺拿 sid,再拉订单列表,最后取一单详情核对金额。
+ * 第 2 步补充(店铺):多平台店铺列表在没有任何过滤时到底返回什么。
+ *
+ * {@link LingxingAdapter#listSubChannels} 内部按上游店铺接口的协议写死了
+ * {@code is_sync=1} + {@code status=1}(暂停同步 / 授权异常 / 删除的店看不到),
+ * 适配器没有对应的查询入口。这里用 {@link LingxingCall} 直接打同一个接口,
+ * 不过滤这三项,把未启用的店也打出来,用来判断「订单 / 入库里少的店铺」是不是被过滤掉了。
+ */
+ @Test
+ void listsShopsIncludingDisabledOnes() {
+ requireCredentials();
+ LingxingCall call = call(null);
+
+ Map body = new LinkedHashMap();
+ body.put("offset", 0);
+ body.put("length", LingxingConstants.MULTI_PLATFORM_MAX_PAGE_SIZE);
+ if (hasPlatformCode()) {
+ body.put("platform_code", Collections.singletonList(PLATFORM_CODE));
+ }
+
+ HttpRequest req = call.signed(LingxingApi.SHOP_LIST_MULTI_PLATFORM, body, "smoke.shops.all");
+ HttpResponse resp = call.execute(req);
+ LingxingEnvelope env = call.envelope(resp, "smoke.shops.all");
+ List