Browse Source
端点与凭据此前固化成常量或注入的 SecretProvider,等于 SDK 在替宿主保存连接配置。 现在改为调用方每次调用显式传入: - 新增 ChannelConnection(endpointBaseUrl + ChannelSecret) - ChannelContext 持有 connection;新增 endpointBaseUrl() / secret() - ChannelSdk.salesOrders(key, conn) / products(key, conn) 必须传连接 - LingxingAdapter 构造函数不再接收 baseUrl 与 SecretProvider - LingxingRequestFactory 的 baseUrl 改为每次 post 传入 - LingxingTokenClient.fetch(baseUrl, appId, appSecret) - ChannelSecret 增加 endpointBaseUrl:TokenManager 的 refresh 回调只拿得到凭据对象 - LingxingConstants.DEFAULT_BASE_URL 改名 PRODUCTION_BASE_URL,明确仅作参考/测试常量 TokenManager 仍按设计文档 9.1 管理 token 生命周期(缓存、提前续期、防击穿、 失效重取),token 存储仍走宿主 TokenStore SPI——文档没要求 SDK 自己存。 Co-Authored-By: Claude <noreply@anthropic.com>feature/supplier-lingxing
18 changed files with 224 additions and 90 deletions
@ -0,0 +1,64 @@
@@ -0,0 +1,64 @@
|
||||
package common.ecommerce.sdk; |
||||
|
||||
import common.ecommerce.spi.ChannelSecret; |
||||
|
||||
import java.util.Objects; |
||||
|
||||
/** |
||||
* 一次调用的连接信息:目标地址 + 凭据。 |
||||
* |
||||
* <p><b>由调用方在每次调用时传入,SDK 不保存、不读配置、不读环境变量。</b> |
||||
* 适配器只持有协议(路径、签名算法、限流),不持有「连哪台机器、用谁的身份」。</p> |
||||
* |
||||
* <p>不同平台需要的凭据字段不同(领星 appId/appSecret、亚马逊 clientId/secret/refreshToken), |
||||
* 统一由 {@link ChannelSecret} 承载,适配器按需取用。</p> |
||||
*/ |
||||
public final class ChannelConnection { |
||||
|
||||
private final String endpointBaseUrl; |
||||
private final ChannelSecret secret; |
||||
|
||||
private ChannelConnection(String endpointBaseUrl, ChannelSecret secret) { |
||||
if (endpointBaseUrl == null || endpointBaseUrl.trim().isEmpty()) { |
||||
throw new IllegalArgumentException("endpointBaseUrl must not be blank"); |
||||
} |
||||
this.endpointBaseUrl = trimTrailingSlash(endpointBaseUrl.trim()); |
||||
Objects.requireNonNull(secret, "secret"); |
||||
// 端点写回凭据:TokenManager 的 refresh 回调只拿得到 ChannelSecret
|
||||
this.secret = ChannelSecret.builder() |
||||
.endpointBaseUrl(this.endpointBaseUrl) |
||||
.appKey(secret.appKey()) |
||||
.appSecret(secret.appSecret()) |
||||
.clientId(secret.clientId()) |
||||
.clientSecret(secret.clientSecret()) |
||||
.refreshToken(secret.refreshToken()) |
||||
.build(); |
||||
} |
||||
|
||||
public static ChannelConnection of(String endpointBaseUrl, ChannelSecret secret) { |
||||
return new ChannelConnection(endpointBaseUrl, secret); |
||||
} |
||||
|
||||
/** 目标基址,末尾斜杠已去掉。 */ |
||||
public String endpointBaseUrl() { |
||||
return endpointBaseUrl; |
||||
} |
||||
|
||||
public ChannelSecret secret() { |
||||
return secret; |
||||
} |
||||
|
||||
@Override |
||||
public String toString() { |
||||
// 只打指纹与地址,凭据本体不出现在日志里
|
||||
return "ChannelConnection{" + endpointBaseUrl + ", " + secret.fingerprint() + '}'; |
||||
} |
||||
|
||||
private static String trimTrailingSlash(String url) { |
||||
int end = url.length(); |
||||
while (end > 0 && url.charAt(end - 1) == '/') { |
||||
end--; |
||||
} |
||||
return url.substring(0, end); |
||||
} |
||||
} |
||||
Loading…
Reference in new issue