fix(pdd): cat.rule.get param_json 含 goods_id=0,统一 catRuleGetParamJson 与失败日志 paramJsonSnippet
Made-with: Cursor
This commit is contained in:
parent
3976c9f6ad
commit
8dce7135e0
|
|
@ -5,8 +5,6 @@ import cn.qihangerp.model.entity.OGoodsSku;
|
|||
import cn.qihangerp.model.request.ExternalGoodsUpsertRequest;
|
||||
import cn.qihangerp.model.vo.PddPublishLaneResultVo;
|
||||
import cn.qihangerp.service.external.shop.PddShopCredential;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
|
@ -125,10 +123,8 @@ public class ExternalPddPublishService {
|
|||
|
||||
if (props.isAutoFetchCatRule() && !catFetched) {
|
||||
try {
|
||||
JSONObject body = new JSONObject();
|
||||
body.put("cat_id", catId);
|
||||
String raw = pddPopClient.invoke(gateway, cred.getAppKey(), cred.getAppSecret(), cred.getAccessToken(),
|
||||
"pdd.goods.cat.rule.get", JSON.toJSONString(body));
|
||||
"pdd.goods.cat.rule.get", PddOpenApiSupport.catRuleGetParamJson(catId));
|
||||
catRuleSnippet = PddOpenApiSupport.snippet(raw, 2000);
|
||||
catFetched = true;
|
||||
} catch (Exception e) {
|
||||
|
|
|
|||
|
|
@ -75,16 +75,13 @@ public class PddCatRuleSpecAutoResolver {
|
|||
if (catId <= 0) {
|
||||
throw new IllegalArgumentException("cat_id 必须为正数,当前=" + catId);
|
||||
}
|
||||
JSONObject p = new JSONObject();
|
||||
// POP 文档 cat_id 类型为 LONG;部分网关对字符串 cat_id 解析失败会报「请求参数不能为空:cat_id」
|
||||
p.put("cat_id", catId);
|
||||
return popClient.invoke(
|
||||
gatewayUrl,
|
||||
cred.getAppKey(),
|
||||
cred.getAppSecret(),
|
||||
cred.getAccessToken(),
|
||||
"pdd.goods.cat.rule.get",
|
||||
JSON.toJSONString(p)
|
||||
PddOpenApiSupport.catRuleGetParamJson(catId)
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,9 @@ import com.alibaba.fastjson2.JSONArray;
|
|||
import com.alibaba.fastjson2.JSONObject;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 解析拼多多 POP 返回 JSON 的通用工具。
|
||||
*
|
||||
|
|
@ -15,6 +18,20 @@ public final class PddOpenApiSupport {
|
|||
private PddOpenApiSupport() {
|
||||
}
|
||||
|
||||
/**
|
||||
* {@code pdd.goods.cat.rule.get} 的 {@code param_json}。
|
||||
* <p>开放平台约定:除 {@code cat_id} 外,新发品场景须传 {@code goods_id=0};缺省时部分网关会误报「cat_id 不能为空」。</p>
|
||||
*/
|
||||
public static String catRuleGetParamJson(long catId) {
|
||||
if (catId <= 0) {
|
||||
throw new IllegalArgumentException("cat_id 必须为正数: " + catId);
|
||||
}
|
||||
Map<String, Object> m = new LinkedHashMap<>();
|
||||
m.put("cat_id", catId);
|
||||
m.put("goods_id", 0L);
|
||||
return JSON.toJSONString(m);
|
||||
}
|
||||
|
||||
public static String snippet(String s, int max) {
|
||||
if (s == null) {
|
||||
return null;
|
||||
|
|
|
|||
|
|
@ -73,8 +73,9 @@ public class PddPopClient {
|
|||
String snippet = PddOpenApiSupport.snippet(raw, 600);
|
||||
if (!httpOk || popBizError) {
|
||||
String errSummary = popBizError ? PddOpenApiSupport.formatError(raw) : "";
|
||||
log.warn("PDD_POP api={} host={} clientId={} httpStatus={} durationMs={} popBizError={} errSummary={} bodySnippet={}",
|
||||
type, host, clientMasked, httpStatus, durationMs, popBizError, errSummary, snippet);
|
||||
String paramSnippet = StringUtils.hasText(paramJson) ? PddOpenApiSupport.snippet(paramJson, 400) : "";
|
||||
log.warn("PDD_POP api={} host={} clientId={} httpStatus={} durationMs={} popBizError={} errSummary={} paramJsonSnippet={} bodySnippet={}",
|
||||
type, host, clientMasked, httpStatus, durationMs, popBizError, errSummary, paramSnippet, snippet);
|
||||
} else {
|
||||
log.info("PDD_POP api={} host={} clientId={} httpStatus={} durationMs={} bodySnippet={}",
|
||||
type, host, clientMasked, httpStatus, durationMs, snippet);
|
||||
|
|
|
|||
Loading…
Reference in New Issue