Browse Source
- EdayunConstants.PR_BASE_URL 填成 https://test.omniselling.com.cn/saas-service/openapi/microService - HEADER_TOKEN 的 Javadoc 写明「仅业务接口使用」:POST /oauth/token 本身不带 这个头,文档里那行是全局头定义,不是该接口的参数(已确认) - EdayunRequestFactory.businessUnsigned(...):测试环境可直接把 openApiAdminSecret 当 sign 传,不必算 MD5;生产走带 appSecret 的重载 新增 EdayunTokenProbeTest(默认跳过): - probeToken:真实调用 /oauth/token,打印 token 脱敏、tokenType、过期时刻、 剩余秒数、是否带 refreshToken;异常只打印不抛出 - probeSignatureShape:不联网,核对 MD5(body + "." + appSecret) 形态 凭据一律走系统属性,不入库: -Dedayun.probe.clientId / clientSecret / appSecret 全量测试仍绿(533)。 Co-Authored-By: Claude <noreply@anthropic.com>master
3 changed files with 131 additions and 4 deletions
@ -0,0 +1,100 @@ |
|||||||
|
package common.ecommerce.edayun.probe; |
||||||
|
|
||||||
|
import common.ecommerce.edayun.EdayunConstants; |
||||||
|
import common.ecommerce.edayun.auth.EdayunTokenClient; |
||||||
|
import common.ecommerce.edayun.http.EdayunRequestFactory; |
||||||
|
import common.ecommerce.http.JacksonJsonCodec; |
||||||
|
import common.ecommerce.http.OkHttpTransport; |
||||||
|
import common.ecommerce.shared.error.ChannelException; |
||||||
|
import common.ecommerce.shared.spi.AccessToken; |
||||||
|
import org.junit.jupiter.api.Assumptions; |
||||||
|
import org.junit.jupiter.api.Test; |
||||||
|
import org.junit.jupiter.api.condition.EnabledIfSystemProperty; |
||||||
|
|
||||||
|
import java.time.Clock; |
||||||
|
|
||||||
|
/** |
||||||
|
* 易达云获取 token 的联调探针。 |
||||||
|
* |
||||||
|
* <p>默认跳过,用 {@code -Dedayun.probe=true} 开启;凭据走系统属性, |
||||||
|
* <b>真实值不入库</b>:</p> |
||||||
|
* |
||||||
|
* <pre> |
||||||
|
* mvn -pl warehouse-sdk-edayun -DfailIfNoTests=false \ |
||||||
|
* -Dedayun.probe=true \ |
||||||
|
* -Dedayun.probe.baseUrl=https://test.omniselling.com.cn/saas-service/openapi/microService \
|
||||||
|
* -Dedayun.probe.clientId=你的OMS授权用户名 \ |
||||||
|
* -Dedayun.probe.clientSecret=你的OMS授权密码 \ |
||||||
|
* -Dtest=EdayunTokenProbeTest test |
||||||
|
* </pre> |
||||||
|
* |
||||||
|
* <p>只调只读的 token 接口,不碰任何业务写接口。异常只打印不抛出, |
||||||
|
* 便于一次跑完对照真实报文。</p> |
||||||
|
*/ |
||||||
|
@EnabledIfSystemProperty(named = "edayun.probe", matches = "true") |
||||||
|
class EdayunTokenProbeTest { |
||||||
|
|
||||||
|
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", ""); |
||||||
|
|
||||||
|
@Test |
||||||
|
void probeToken() { |
||||||
|
Assumptions.assumeTrue(!CLIENT_ID.trim().isEmpty() && !CLIENT_SECRET.trim().isEmpty(), |
||||||
|
"未提供 -Dedayun.probe.clientId / clientSecret,跳过"); |
||||||
|
|
||||||
|
System.out.println("\n================ edayun / POST /oauth/token ================"); |
||||||
|
System.out.println("[probe] baseUrl=" + BASE_URL |
||||||
|
+ " clientId=" + mask(CLIENT_ID) + " clientSecret=" + mask(CLIENT_SECRET)); |
||||||
|
|
||||||
|
EdayunTokenClient client = new EdayunTokenClient( |
||||||
|
new OkHttpTransport("common-ecommerce/1.0.0 (edayun-probe)"), |
||||||
|
new JacksonJsonCodec(), Clock.systemUTC()); |
||||||
|
|
||||||
|
try { |
||||||
|
AccessToken token = client.fetch(BASE_URL, CLIENT_ID, CLIENT_SECRET); |
||||||
|
System.out.println("[OK] token=" + mask(token.value()) |
||||||
|
+ " tokenType=" + token.tokenType() |
||||||
|
+ " expiresAt=" + token.expiresAt() |
||||||
|
+ " refreshToken=" + (token.refreshToken() == null ? "null" : "present")); |
||||||
|
System.out.println(" 有效期剩余(秒)=" |
||||||
|
+ (token.expiresAt().getEpochSecond() - java.time.Instant.now().getEpochSecond())); |
||||||
|
} catch (RuntimeException e) { |
||||||
|
String msg = e.getMessage() == null ? e.getClass().getSimpleName() : e.getMessage(); |
||||||
|
System.out.println("[ERROR] " + e.getClass().getSimpleName() + ": " |
||||||
|
+ (msg.length() <= 600 ? msg : msg.substring(0, 600) + "…")); |
||||||
|
if (e instanceof ChannelException) { |
||||||
|
ChannelException ce = (ChannelException) e; |
||||||
|
System.out.println(" platformCode=" + ce.platformCode() |
||||||
|
+ " retryable=" + ce.retryable()); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** 签名算法自检:不联网,确认 MD5(body + "." + appSecret) 的低 8 位形态。 */ |
||||||
|
@Test |
||||||
|
void probeSignatureShape() { |
||||||
|
String secret = System.getProperty("edayun.probe.appSecret", ""); |
||||||
|
Assumptions.assumeTrue(!secret.trim().isEmpty(), |
||||||
|
"未提供 -Dedayun.probe.appSecret,跳过签名自检"); |
||||||
|
String sign = EdayunRequestFactory.sign("{\"a\":1}", secret); |
||||||
|
System.out.println("[sign] MD5(body + \".\" + appSecret) = " + sign |
||||||
|
+ " (长度应为 32 的小写十六进制)"); |
||||||
|
} |
||||||
|
|
||||||
|
private static String mask(String v) { |
||||||
|
if (v == null || v.length() <= 6) { |
||||||
|
return "***"; |
||||||
|
} |
||||||
|
return v.substring(0, 4) + "***" + v.substring(v.length() - 2); |
||||||
|
} |
||||||
|
|
||||||
|
private static String opt(String name, String fallback) { |
||||||
|
String value = System.getProperty(name, ""); |
||||||
|
if (value == null) { |
||||||
|
return fallback; |
||||||
|
} |
||||||
|
String trimmed = value.trim(); |
||||||
|
return trimmed.isEmpty() ? fallback : trimmed; |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue