增加抢购货品接口
This commit is contained in:
@@ -42,8 +42,9 @@ public class HxrAdminBuyService {
|
||||
* @return {@code apiCode} 为 -1 表示 HTTP 或解析失败
|
||||
*/
|
||||
public BuyApiResult buy(long goodsId, long sellerId, String token) throws Exception {
|
||||
if (token == null || token.isBlank()) {
|
||||
return BuyApiResult.failure(-1, "token不能为空");
|
||||
String resolvedToken = resolveToken(token);
|
||||
if (resolvedToken == null) {
|
||||
return BuyApiResult.failure(-1, "未提供 token 且未配置 hxr.admin.goods-api-token");
|
||||
}
|
||||
String appStr = properties.getGoodsApiAppStr();
|
||||
if (appStr == null || appStr.isBlank()) {
|
||||
@@ -78,7 +79,7 @@ public class HxrAdminBuyService {
|
||||
.header("Origin", properties.getGoodsApiOrigin())
|
||||
.header("Referer", properties.getGoodsApiReferer())
|
||||
.header("User-Agent", USER_AGENT)
|
||||
.header("token", token.trim())
|
||||
.header("token", resolvedToken)
|
||||
.header("S", sign)
|
||||
.header("T", String.valueOf(timestamp))
|
||||
.header("N", noncestr)
|
||||
@@ -108,6 +109,18 @@ public class HxrAdminBuyService {
|
||||
return new BuyApiResult(code == 0, code, msg);
|
||||
}
|
||||
|
||||
/** 优先使用入参 token,否则回退到配置 {@code goods-api-token}。 */
|
||||
private String resolveToken(String token) {
|
||||
if (token != null && !token.isBlank()) {
|
||||
return token.trim();
|
||||
}
|
||||
String configured = properties.getGoodsApiToken();
|
||||
if (configured != null && !configured.isBlank()) {
|
||||
return configured.trim();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public record BuyApiResult(boolean success, int apiCode, String apiMsg) {
|
||||
|
||||
public static BuyApiResult failure(int code, String msg) {
|
||||
|
||||
Reference in New Issue
Block a user