Browse Source
POST /webApi/carrier/v1/listCarrierByWarehouse → List<WarehouseCarrier> 返回两层:承运商(carrierId / 名称中英文)→ 物流服务(logisticId / 名称)。 自提单下单时 carrierName 可以填承运商名,也可以用某个物流服务的名字。 统一模型新增 WarehouseCarrier;能力挂在 WarehouseDirectoryCapable.carrierDirectory(门面 carrierDirectory())。 原有的 carriers()(List<String>,只有码)保留不动——carrierDirectory 的 默认实现会把码包装成无名条目,能给出结构的仓覆盖它。 ownLogisticList 文档写成对象、真机返回数组,DTO 按 List 收。 真机(2026-11-16):仓 2 返回 11 个承运商(FedEx 下 12 个物流服务); 不传仓 22 个;countryCode=US 10 个。 顺带:易达云没有仓库列表接口,warehouses() 显式抛不支持, 不返回空列表——空列表和「没有仓」调用方分不清。DIRECTORY 能力位 目前只覆盖承运商这一半。 Co-Authored-By: Claude <noreply@anthropic.com>master
11 changed files with 680 additions and 2 deletions
@ -0,0 +1,116 @@ |
|||||||
|
package common.ecommerce.warehouse.model; |
||||||
|
|
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.Collections; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* 客户自有的承运商(物流服务商)及其下属物流服务。 |
||||||
|
* |
||||||
|
* <p>用于「客户自有物流 + 客户上传面单」的自提单场景:下单时 |
||||||
|
* {@code carrierName} 填 {@link #nameEn()} 或某个 {@link OwnLogistic#name()}。</p> |
||||||
|
* |
||||||
|
* <p>这是<b>主数据</b>,不是状态:同一仓的承运商清单很少变,适合宿主缓存。</p> |
||||||
|
*/ |
||||||
|
public final class WarehouseCarrier { |
||||||
|
|
||||||
|
/** 承运商 id(仓方码)。 */ |
||||||
|
private final String carrierId; |
||||||
|
/** 承运商英文名,如 {@code FedEx}。 */ |
||||||
|
private final String nameEn; |
||||||
|
/** 承运商中文名。 */ |
||||||
|
private final String nameCn; |
||||||
|
/** 该承运商下的物流服务;仓方未给时为空列表。 */ |
||||||
|
private final List<OwnLogistic> logists; |
||||||
|
|
||||||
|
private WarehouseCarrier(Builder b) { |
||||||
|
this.carrierId = require(b.carrierId, "carrierId"); |
||||||
|
this.nameEn = b.nameEn; |
||||||
|
this.nameCn = b.nameCn; |
||||||
|
this.logists = Collections.unmodifiableList(new ArrayList<OwnLogistic>(b.logists)); |
||||||
|
} |
||||||
|
|
||||||
|
public static Builder builder() { |
||||||
|
return new Builder(); |
||||||
|
} |
||||||
|
|
||||||
|
public String carrierId() { |
||||||
|
return carrierId; |
||||||
|
} |
||||||
|
|
||||||
|
public String nameEn() { |
||||||
|
return nameEn; |
||||||
|
} |
||||||
|
|
||||||
|
public String nameCn() { |
||||||
|
return nameCn; |
||||||
|
} |
||||||
|
|
||||||
|
/** 下属物流服务;可能为空。 */ |
||||||
|
public List<OwnLogistic> logists() { |
||||||
|
return logists; |
||||||
|
} |
||||||
|
|
||||||
|
/** 展示名:优先中文名,没有再用英文名。 */ |
||||||
|
public String displayName() { |
||||||
|
return nameCn != null && !nameCn.trim().isEmpty() ? nameCn : nameEn; |
||||||
|
} |
||||||
|
|
||||||
|
private static String require(String v, String name) { |
||||||
|
if (v == null || v.trim().isEmpty()) { |
||||||
|
throw new IllegalArgumentException(name + " must not be blank"); |
||||||
|
} |
||||||
|
return v.trim(); |
||||||
|
} |
||||||
|
|
||||||
|
/** 承运商下的一个物流服务。 */ |
||||||
|
public static final class OwnLogistic { |
||||||
|
|
||||||
|
private final String logisticId; |
||||||
|
private final String name; |
||||||
|
|
||||||
|
public OwnLogistic(String logisticId, String name) { |
||||||
|
this.logisticId = require(logisticId, "logisticId"); |
||||||
|
this.name = name; |
||||||
|
} |
||||||
|
|
||||||
|
public String logisticId() { |
||||||
|
return logisticId; |
||||||
|
} |
||||||
|
|
||||||
|
public String name() { |
||||||
|
return name; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public static final class Builder { |
||||||
|
private String carrierId; |
||||||
|
private String nameEn; |
||||||
|
private String nameCn; |
||||||
|
private final List<OwnLogistic> logists = new ArrayList<OwnLogistic>(); |
||||||
|
|
||||||
|
public Builder carrierId(String v) { |
||||||
|
this.carrierId = v; |
||||||
|
return this; |
||||||
|
} |
||||||
|
|
||||||
|
public Builder nameEn(String v) { |
||||||
|
this.nameEn = v; |
||||||
|
return this; |
||||||
|
} |
||||||
|
|
||||||
|
public Builder nameCn(String v) { |
||||||
|
this.nameCn = v; |
||||||
|
return this; |
||||||
|
} |
||||||
|
|
||||||
|
public Builder logistic(OwnLogistic v) { |
||||||
|
this.logists.add(v); |
||||||
|
return this; |
||||||
|
} |
||||||
|
|
||||||
|
public WarehouseCarrier build() { |
||||||
|
return new WarehouseCarrier(this); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,83 @@ |
|||||||
|
package common.ecommerce.edayun.adapter; |
||||||
|
|
||||||
|
import common.ecommerce.edayun.dto.EdayunCarrierDtos; |
||||||
|
import common.ecommerce.warehouse.model.WarehouseCarrier; |
||||||
|
|
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.Collections; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* 易达云承运商映射({@code POST /webApi/carrier/v1/listCarrierByWarehouse})。 |
||||||
|
* |
||||||
|
* <p>响应 {@code ownLogisticList} 文档写成对象、真机返回数组,DTO 按 List 收。</p> |
||||||
|
*/ |
||||||
|
public final class EdayunCarrierMapper { |
||||||
|
|
||||||
|
private EdayunCarrierMapper() { |
||||||
|
} |
||||||
|
|
||||||
|
/** 查询请求。 */ |
||||||
|
public static EdayunCarrierDtos.ListCarrierRequest toRequest(String providerWarehouseId, |
||||||
|
String countryCode) { |
||||||
|
EdayunCarrierDtos.ListCarrierRequest req = new EdayunCarrierDtos.ListCarrierRequest(); |
||||||
|
req.warehouseId = warehouseIdOf(providerWarehouseId); |
||||||
|
req.countryCode = hasText(countryCode) ? countryCode.trim() : null; |
||||||
|
return req; |
||||||
|
} |
||||||
|
|
||||||
|
/** 响应 → 统一模型;{@code carrierId} 缺失的行跳过(模型要求非空)。 */ |
||||||
|
public static List<WarehouseCarrier> toCarriers( |
||||||
|
List<EdayunCarrierDtos.Carrier> rows) { |
||||||
|
if (rows == null || rows.isEmpty()) { |
||||||
|
return Collections.emptyList(); |
||||||
|
} |
||||||
|
List<WarehouseCarrier> out = new ArrayList<WarehouseCarrier>(rows.size()); |
||||||
|
for (EdayunCarrierDtos.Carrier row : rows) { |
||||||
|
WarehouseCarrier carrier = toCarrier(row); |
||||||
|
if (carrier != null) { |
||||||
|
out.add(carrier); |
||||||
|
} |
||||||
|
} |
||||||
|
return out; |
||||||
|
} |
||||||
|
|
||||||
|
static WarehouseCarrier toCarrier(EdayunCarrierDtos.Carrier row) { |
||||||
|
if (row == null || !hasText(row.carrierId)) { |
||||||
|
return null; |
||||||
|
} |
||||||
|
WarehouseCarrier.Builder b = WarehouseCarrier.builder() |
||||||
|
.carrierId(row.carrierId.trim()) |
||||||
|
.nameEn(trimToNull(row.carrierNameEn)) |
||||||
|
.nameCn(trimToNull(row.carrierNameCn)); |
||||||
|
if (row.ownLogisticList != null) { |
||||||
|
for (EdayunCarrierDtos.OwnLogistic l : row.ownLogisticList) { |
||||||
|
if (l != null && hasText(l.logisticId)) { |
||||||
|
b.logistic(new WarehouseCarrier.OwnLogistic(l.logisticId.trim(), |
||||||
|
trimToNull(l.logisticName))); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
return b.build(); |
||||||
|
} |
||||||
|
|
||||||
|
/** 仓方仓 id 是数字;非数字/为空返回 null(不传 = 查所有服务商)。 */ |
||||||
|
static Long warehouseIdOf(String providerWarehouseId) { |
||||||
|
if (!hasText(providerWarehouseId)) { |
||||||
|
return null; |
||||||
|
} |
||||||
|
try { |
||||||
|
return Long.valueOf(providerWarehouseId.trim()); |
||||||
|
} catch (NumberFormatException e) { |
||||||
|
return null; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private static String trimToNull(String v) { |
||||||
|
return hasText(v) ? v.trim() : null; |
||||||
|
} |
||||||
|
|
||||||
|
private static boolean hasText(String v) { |
||||||
|
return v != null && !v.trim().isEmpty(); |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,60 @@ |
|||||||
|
package common.ecommerce.edayun.dto; |
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonInclude; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* 易达云报文结构:查询客户自有物流服务(承运商) |
||||||
|
* ({@code POST /webApi/carrier/v1/listCarrierByWarehouse})。 |
||||||
|
* |
||||||
|
* <p>一个文件对应一个接口。响应是「承运商 → 物流服务」两层: |
||||||
|
* {@code carrierId / carrierNameEn / carrierNameCn} + 下属 {@code ownLogisticList}。</p> |
||||||
|
*/ |
||||||
|
public final class EdayunCarrierDtos { |
||||||
|
|
||||||
|
private EdayunCarrierDtos() { |
||||||
|
} |
||||||
|
|
||||||
|
/** 查询请求。 */ |
||||||
|
@JsonInclude(JsonInclude.Include.NON_NULL) |
||||||
|
public static final class ListCarrierRequest { |
||||||
|
/** 仓库 id;不传则查所有服务商。 */ |
||||||
|
public Long warehouseId; |
||||||
|
/** 国家编码,如 {@code US}。 */ |
||||||
|
public String countryCode; |
||||||
|
} |
||||||
|
|
||||||
|
/** 查询响应。 */ |
||||||
|
@JsonInclude(JsonInclude.Include.NON_NULL) |
||||||
|
public static final class ListCarrierResponse { |
||||||
|
public Integer code; |
||||||
|
public String msg; |
||||||
|
public List<Carrier> data; |
||||||
|
public String traceId; |
||||||
|
} |
||||||
|
|
||||||
|
/** 一个承运商。 */ |
||||||
|
@JsonInclude(JsonInclude.Include.NON_NULL) |
||||||
|
public static final class Carrier { |
||||||
|
/** 承运商 id。 */ |
||||||
|
public String carrierId; |
||||||
|
/** 英文名,如 {@code FedEx}。 */ |
||||||
|
public String carrierNameEn; |
||||||
|
/** 中文名。 */ |
||||||
|
public String carrierNameCn; |
||||||
|
/** |
||||||
|
* 下属物流服务。 |
||||||
|
* |
||||||
|
* <p><b>文档写成对象,真机返回数组</b>——按 List 收,避免解析失败。</p> |
||||||
|
*/ |
||||||
|
public List<OwnLogistic> ownLogisticList; |
||||||
|
} |
||||||
|
|
||||||
|
/** 承运商下的一个物流服务。 */ |
||||||
|
@JsonInclude(JsonInclude.Include.NON_NULL) |
||||||
|
public static final class OwnLogistic { |
||||||
|
public String logisticId; |
||||||
|
public String logisticName; |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,160 @@ |
|||||||
|
package common.ecommerce.edayun.adapter; |
||||||
|
|
||||||
|
import common.ecommerce.edayun.dto.EdayunCarrierDtos; |
||||||
|
import common.ecommerce.http.JacksonJsonCodec; |
||||||
|
import common.ecommerce.shared.spi.ChannelSecret; |
||||||
|
import common.ecommerce.shared.testkit.RecordingTransport; |
||||||
|
import common.ecommerce.shared.testkit.Responses; |
||||||
|
import common.ecommerce.warehouse.enums.WarehouseProvider; |
||||||
|
import common.ecommerce.warehouse.model.WarehouseCarrier; |
||||||
|
import common.ecommerce.warehouse.sdk.WarehouseConnection; |
||||||
|
import common.ecommerce.warehouse.sdk.WarehouseContext; |
||||||
|
import org.junit.jupiter.api.Test; |
||||||
|
|
||||||
|
import java.time.Clock; |
||||||
|
import java.time.Instant; |
||||||
|
import java.time.ZoneOffset; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals; |
||||||
|
import static org.junit.jupiter.api.Assertions.assertNull; |
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows; |
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue; |
||||||
|
|
||||||
|
/** |
||||||
|
* 承运商清单({@code /webApi/carrier/v1/listCarrierByWarehouse})。 |
||||||
|
* |
||||||
|
* <p>重点:ownLogisticList 文档写成对象、真机是数组;carrierId 缺失的行跳过。</p> |
||||||
|
*/ |
||||||
|
class EdayunCarrierTest { |
||||||
|
|
||||||
|
private static final Clock CLOCK = Clock.fixed(Instant.parse("2026-11-16T00:00:00Z"), ZoneOffset.UTC); |
||||||
|
|
||||||
|
private static WarehouseContext ctx(String providerWarehouseId) { |
||||||
|
return WarehouseContext.of("EDY-WH", WarehouseProvider.EDAYUN, providerWarehouseId, |
||||||
|
WarehouseConnection.of("https://test.example/openapi", |
||||||
|
ChannelSecret.builder().appKey("k").appSecret("s") |
||||||
|
.clientId("c").clientSecret("cs").build()), |
||||||
|
"req-carrier", CLOCK); |
||||||
|
} |
||||||
|
|
||||||
|
private static RecordingTransport stub(String body) { |
||||||
|
return RecordingTransport.create() |
||||||
|
.route(common.ecommerce.edayun.EdayunConstants.PATH_TOKEN, req -> Responses.ok( |
||||||
|
"{\"access_token\":\"T1\",\"token_type\":\"bearer\"}")) |
||||||
|
.route(common.ecommerce.edayun.EdayunConstants.PATH_CARRIERS, |
||||||
|
req -> Responses.ok(body)); |
||||||
|
} |
||||||
|
|
||||||
|
// ------------------------------------------------------------ 请求
|
||||||
|
|
||||||
|
@Test |
||||||
|
void numericWarehouseIdIsSent() { |
||||||
|
EdayunCarrierDtos.ListCarrierRequest req = |
||||||
|
EdayunCarrierMapper.toRequest("2", null); |
||||||
|
|
||||||
|
assertEquals(Long.valueOf(2L), req.warehouseId); |
||||||
|
assertNull(req.countryCode); |
||||||
|
} |
||||||
|
|
||||||
|
/** 非数字仓 id 不下发——仓方会返回所有服务商。 */ |
||||||
|
@Test |
||||||
|
void nonNumericWarehouseIdIsOmitted() { |
||||||
|
assertNull(EdayunCarrierMapper.toRequest("USLA", null).warehouseId); |
||||||
|
assertNull(EdayunCarrierMapper.toRequest(null, null).warehouseId); |
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
void countryCodeIsTrimmed() { |
||||||
|
assertEquals("US", EdayunCarrierMapper.toRequest("2", " US ").countryCode); |
||||||
|
assertNull(EdayunCarrierMapper.toRequest("2", " ").countryCode); |
||||||
|
} |
||||||
|
|
||||||
|
// ------------------------------------------------------------ 响应
|
||||||
|
|
||||||
|
private static EdayunCarrierDtos.Carrier carrier() { |
||||||
|
EdayunCarrierDtos.OwnLogistic l1 = new EdayunCarrierDtos.OwnLogistic(); |
||||||
|
l1.logisticId = "583"; |
||||||
|
l1.logisticName = "Collections by Tiktok - FedEx"; |
||||||
|
|
||||||
|
EdayunCarrierDtos.OwnLogistic l2 = new EdayunCarrierDtos.OwnLogistic(); |
||||||
|
l2.logisticId = "250"; |
||||||
|
l2.logisticName = "FedEx-express"; |
||||||
|
|
||||||
|
EdayunCarrierDtos.Carrier c = new EdayunCarrierDtos.Carrier(); |
||||||
|
c.carrierId = "1"; |
||||||
|
c.carrierNameEn = "FedEx"; |
||||||
|
c.carrierNameCn = "联邦快递"; |
||||||
|
c.ownLogisticList = java.util.Arrays.asList(l1, l2); |
||||||
|
return c; |
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
void mapsCarrierWithLogistics() { |
||||||
|
WarehouseCarrier c = EdayunCarrierMapper.toCarrier(carrier()); |
||||||
|
|
||||||
|
assertEquals("1", c.carrierId()); |
||||||
|
assertEquals("FedEx", c.nameEn()); |
||||||
|
assertEquals("联邦快递", c.nameCn()); |
||||||
|
assertEquals("联邦快递", c.displayName()); |
||||||
|
assertEquals(2, c.logists().size()); |
||||||
|
assertEquals("583", c.logists().get(0).logisticId()); |
||||||
|
assertEquals("FedEx-express", c.logists().get(1).name()); |
||||||
|
} |
||||||
|
|
||||||
|
/** 没有中文名时 displayName 退回英文名。 */ |
||||||
|
@Test |
||||||
|
void displayNameFallsBackToEnglish() { |
||||||
|
EdayunCarrierDtos.Carrier c = carrier(); |
||||||
|
c.carrierNameCn = null; |
||||||
|
|
||||||
|
assertEquals("FedEx", EdayunCarrierMapper.toCarrier(c).displayName()); |
||||||
|
} |
||||||
|
|
||||||
|
/** carrierId 缺失的行跳过——模型要求非空。 */ |
||||||
|
@Test |
||||||
|
void carrierWithoutIdIsSkipped() { |
||||||
|
EdayunCarrierDtos.Carrier bad = carrier(); |
||||||
|
bad.carrierId = " "; |
||||||
|
|
||||||
|
List<WarehouseCarrier> list = EdayunCarrierMapper.toCarriers( |
||||||
|
java.util.Arrays.asList(bad, carrier())); |
||||||
|
|
||||||
|
assertEquals(1, list.size()); |
||||||
|
} |
||||||
|
|
||||||
|
/** ownLogisticList 缺失或为空不抛异常。 */ |
||||||
|
@Test |
||||||
|
void missingLogisticListYieldsEmpty() { |
||||||
|
EdayunCarrierDtos.Carrier c = carrier(); |
||||||
|
c.ownLogisticList = null; |
||||||
|
|
||||||
|
assertTrue(EdayunCarrierMapper.toCarrier(c).logists().isEmpty()); |
||||||
|
assertTrue(EdayunCarrierMapper.toCarriers(null).isEmpty()); |
||||||
|
assertTrue(EdayunCarrierMapper.toCarriers( |
||||||
|
java.util.Collections.<EdayunCarrierDtos.Carrier>emptyList()).isEmpty()); |
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
void adapterQueriesCarriers() { |
||||||
|
RecordingTransport transport = stub("{\"code\":200,\"msg\":\"操作成功\",\"data\":[{" |
||||||
|
+ "\"carrierId\":\"1\",\"carrierNameEn\":\"FedEx\",\"carrierNameCn\":\"FedEx\"," |
||||||
|
+ "\"ownLogisticList\":[{\"logisticId\":\"250\",\"logisticName\":\"FedEx-express\"}]}]}"); |
||||||
|
|
||||||
|
List<WarehouseCarrier> list = new EdayunAdapter(transport, new JacksonJsonCodec()) |
||||||
|
.carrierDirectory(ctx("2")); |
||||||
|
|
||||||
|
assertEquals(1, list.size()); |
||||||
|
assertEquals("FedEx", list.get(0).nameEn()); |
||||||
|
assertEquals(1, list.get(0).logists().size()); |
||||||
|
assertTrue(transport.lastDataRequest().body().contains("\"warehouseId\":2")); |
||||||
|
} |
||||||
|
|
||||||
|
/** 仓库列表接口易达云没有,显式拒绝而不是空列表。 */ |
||||||
|
@Test |
||||||
|
void warehousesAreUnsupported() { |
||||||
|
assertThrows(RuntimeException.class, |
||||||
|
() -> new EdayunAdapter(stub("{}"), new JacksonJsonCodec()) |
||||||
|
.warehouses(ctx("2"))); |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,117 @@ |
|||||||
|
package common.ecommerce.edayun.probe; |
||||||
|
|
||||||
|
import common.ecommerce.edayun.EdayunConstants; |
||||||
|
import common.ecommerce.edayun.adapter.EdayunAdapter; |
||||||
|
import common.ecommerce.edayun.adapter.EdayunCarrierMapper; |
||||||
|
import common.ecommerce.edayun.dto.EdayunCarrierDtos; |
||||||
|
import common.ecommerce.http.JacksonJsonCodec; |
||||||
|
import common.ecommerce.http.OkHttpTransport; |
||||||
|
import common.ecommerce.shared.error.ChannelException; |
||||||
|
import common.ecommerce.shared.spi.ChannelSecret; |
||||||
|
import common.ecommerce.warehouse.enums.WarehouseProvider; |
||||||
|
import common.ecommerce.warehouse.model.WarehouseCarrier; |
||||||
|
import common.ecommerce.warehouse.sdk.WarehouseConnection; |
||||||
|
import common.ecommerce.warehouse.sdk.WarehouseContext; |
||||||
|
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.util.List; |
||||||
|
import java.util.UUID; |
||||||
|
|
||||||
|
/** |
||||||
|
* 承运商清单联调探针:<b>只读</b>。 |
||||||
|
* |
||||||
|
* <pre> |
||||||
|
* # 只看报文(不联网) |
||||||
|
* mvn -pl warehouse-sdk-edayun -DfailIfNoTests=false \ |
||||||
|
* -Dedayun.probe.carrier=true -Dtest=EdayunCarrierProbeTest test |
||||||
|
* |
||||||
|
* # 真查(只读) |
||||||
|
* ... -Dedayun.probe.carrier=true -Dedayun.probe.call=true \ |
||||||
|
* -Dedayun.probe.clientId=... -Dedayun.probe.clientSecret=... \ |
||||||
|
* -Dedayun.probe.appKey=... -Dedayun.probe.appSecret=... \ |
||||||
|
* [-Dedayun.probe.warehouseId=2] [-Dedayun.probe.country=US] |
||||||
|
* </pre> |
||||||
|
*/ |
||||||
|
@EnabledIfSystemProperty(named = "edayun.probe.carrier", matches = "true") |
||||||
|
class EdayunCarrierProbeTest { |
||||||
|
|
||||||
|
private static final String BASE_URL = opt("edayun.probe.baseUrl", EdayunConstants.PR_BASE_URL); |
||||||
|
private static final String CLIENT_ID = System.getProperty("edayun.probe.clientId", ""); |
||||||
|
private static final String CLIENT_SECRET = System.getProperty("edayun.probe.clientSecret", ""); |
||||||
|
private static final String APP_KEY = System.getProperty("edayun.probe.appKey", ""); |
||||||
|
private static final String APP_SECRET = System.getProperty("edayun.probe.appSecret", ""); |
||||||
|
private static final String WAREHOUSE_ID = System.getProperty("edayun.probe.warehouseId", ""); |
||||||
|
private static final String COUNTRY = System.getProperty("edayun.probe.country", ""); |
||||||
|
private static final boolean CALL = Boolean.getBoolean("edayun.probe.call"); |
||||||
|
|
||||||
|
@Test |
||||||
|
void probeCarriers() { |
||||||
|
EdayunCarrierDtos.ListCarrierRequest req = EdayunCarrierMapper.toRequest( |
||||||
|
emptyToNull(WAREHOUSE_ID), emptyToNull(COUNTRY)); |
||||||
|
|
||||||
|
System.out.println("\n================ edayun / POST " |
||||||
|
+ EdayunConstants.PATH_CARRIERS + " ================"); |
||||||
|
System.out.println("[probe] baseUrl=" + BASE_URL |
||||||
|
+ " warehouseId=" + mask(WAREHOUSE_ID) + " country=" + COUNTRY); |
||||||
|
System.out.println("[request] " + new JacksonJsonCodec().toJson(req)); |
||||||
|
|
||||||
|
Assumptions.assumeTrue(CALL, "dry-run:未加 -Dedayun.probe.call=true,不实际调用"); |
||||||
|
Assumptions.assumeTrue(!CLIENT_ID.trim().isEmpty() && !CLIENT_SECRET.trim().isEmpty() |
||||||
|
&& !APP_KEY.trim().isEmpty() && !APP_SECRET.trim().isEmpty(), |
||||||
|
"真查需要 -Dedayun.probe.clientId / clientSecret / appKey / appSecret"); |
||||||
|
|
||||||
|
try { |
||||||
|
WarehouseContext ctx = WarehouseContext.of("EDY-PROBE", WarehouseProvider.EDAYUN, |
||||||
|
emptyToNull(WAREHOUSE_ID), |
||||||
|
WarehouseConnection.of(BASE_URL, |
||||||
|
ChannelSecret.builder() |
||||||
|
.appKey(APP_KEY).appSecret(APP_SECRET) |
||||||
|
.clientId(CLIENT_ID).clientSecret(CLIENT_SECRET) |
||||||
|
.build()), |
||||||
|
"probe-" + UUID.randomUUID(), Clock.systemUTC()); |
||||||
|
EdayunAdapter adapter = new EdayunAdapter( |
||||||
|
new OkHttpTransport("common-ecommerce/1.0.0 (edayun-probe)", 10_000, 60_000), |
||||||
|
new JacksonJsonCodec()); |
||||||
|
|
||||||
|
List<WarehouseCarrier> carriers = adapter.carrierDirectory(ctx); |
||||||
|
System.out.println("[OK] carriers=" + carriers.size()); |
||||||
|
for (WarehouseCarrier c : carriers) { |
||||||
|
System.out.println(" " + c.carrierId() + " " + c.displayName() |
||||||
|
+ " logistics=" + c.logists().size()); |
||||||
|
for (WarehouseCarrier.OwnLogistic l : c.logists()) { |
||||||
|
System.out.println(" - " + l.logisticId() + " " + l.name()); |
||||||
|
} |
||||||
|
} |
||||||
|
} catch (RuntimeException e) { |
||||||
|
String msg = e.getMessage() == null ? e.getClass().getSimpleName() : e.getMessage(); |
||||||
|
System.out.println("[ERROR] " + e.getClass().getSimpleName() + ": " |
||||||
|
+ (msg.length() <= 800 ? msg : msg.substring(0, 800) + "…")); |
||||||
|
if (e instanceof ChannelException) { |
||||||
|
ChannelException ce = (ChannelException) e; |
||||||
|
System.out.println(" platformCode=" + ce.platformCode() |
||||||
|
+ " retryable=" + ce.retryable()); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private static String opt(String name, String fallback) { |
||||||
|
String value = System.getProperty(name, ""); |
||||||
|
String trimmed = value == null ? "" : value.trim(); |
||||||
|
return trimmed.isEmpty() ? fallback : trimmed; |
||||||
|
} |
||||||
|
|
||||||
|
private static String emptyToNull(String v) { |
||||||
|
return v == null || v.trim().isEmpty() ? null : v.trim(); |
||||||
|
} |
||||||
|
|
||||||
|
private static String mask(String v) { |
||||||
|
if (v == null || v.trim().isEmpty()) { |
||||||
|
return "(empty)"; |
||||||
|
} |
||||||
|
String t = v.trim(); |
||||||
|
return t.length() <= 6 ? "***" : t.substring(0, 3) + "***" + t.substring(t.length() - 2); |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue