diff --git a/apps/server/docs/pdd/__pycache__/clean_scraped_md.cpython-312.pyc b/apps/server/docs/pdd/__pycache__/clean_scraped_md.cpython-312.pyc new file mode 100644 index 00000000..0bda636a Binary files /dev/null and b/apps/server/docs/pdd/__pycache__/clean_scraped_md.cpython-312.pyc differ diff --git a/apps/server/docs/pdd/api-docs/goods/pdd.goods.cat.rule.get类目商品发布规则查询接口.md b/apps/server/docs/pdd/api-docs/goods/pdd.goods.cat.rule.get类目商品发布规则查询接口.md new file mode 100644 index 00000000..c1300ee4 --- /dev/null +++ b/apps/server/docs/pdd/api-docs/goods/pdd.goods.cat.rule.get类目商品发布规则查询接口.md @@ -0,0 +1,364 @@ +API文档/商品API/pdd.goods.cat.rule.get + +# pdd.goods.cat.rule.get + +## 类目商品发布规则查询接口 + +更新时间:2026-05-12 20:45:43 + +¥免费API + +必须用户授权 + +通过叶子类目id获取该类目的发布规则,目前返回标品、商品服务、属性等规则。 + +### 公共参数 + +#### 请求地址(目前只提供正式环境,暂无沙箱环境) + +| 环境 | HTTP地址 | HTTPS地址 | +| --- | --- | --- | +| 正式环境 | http://gw-api.pinduoduo.com/api/router | https://gw-api.pinduoduo.com/api/router | + +#### 公共请求参数 + +| 参数名称 | 参数类型 | 是否必填 | 参数描述 | +| --- | --- | --- | --- | +| type | String | 必填 | API接口名称 | +| client\_id | String | 必填 | POP分配给应用的client\_id | +| access\_token | String | 非必填 | 通过code获取的access\_token | +| timestamp | String | 必填 | UNIX时间戳,单位秒,需要与拼多多服务器时间差值在10分钟内 | +| data\_type | String | 非必填 | 响应格式,即返回数据的格式,JSON或者XML(二选一),默认JSON,注意是大写 | +| version | String | 非必填 | API协议版本号,默认为V1,可不填 | +| sign | String | 必填 | API输入参数签名结果,签名算法参考开放平台接入指南第三部分底部。 | + +### 请求参数说明 + +| 参数接口 | 参数类型 | 是否必填 | 说明 | +| --- | --- | --- | --- | +| cat\_id | LONG | 必填 | 类目id | +| goods\_id | LONG | 非必填 | 商品id,编辑的时候需要传被编辑的商品id,发布商品时如果已有商品id也需要传 | +| goods\_properties | OBJECT\[\] | 非必填 | 商品属性列表 | +| group\_id | INTEGER | 非必填 | 属性值分组ID,非销售属性不用传 | +| img\_url | STRING | 非必填 | 图片url,非销售属性不用传 | +| note | STRING | 非必填 | 备注,非销售属性不用传 | +| parent\_spec\_id | LONG | 非必填 | 父规格ID,非销售属性不用传 | +| ref\_pid | LONG | 非必填 | LONG | +| spec\_id | LONG | 非必填 | 规格ID,非销售属性不用传 | +| table\_info | OBJECT | 非必填 | 成分表表单信息 | +| table\_value\_list | OBJECT\[\] | 非必填 | 表单内容列表 | +| column\_type | INTEGER | 非必填 | 列类型 1-材质成分百分比 | +| unit | STRING | 非必填 | 表单单位,材质成分表时为:% | +| value | STRING | 非必填 | 表单值,材质成分表时为:占比百分值 | +| template\_pid | LONG | 非必填 | 模板属性id | +| value | STRING | 非必填 | 属性值 | +| value\_unit | STRING | 非必填 | 属性单位 | +| vid | LONG | 非必填 | 属性值id | + +### 返回参数说明 + +| 参数接口 | 参数类型 | 例子 | 说明 | +| --- | --- | --- | --- | +| cat\_rule\_get\_response | OBJECT | | 类目规则 | +| goods\_properties\_rule | OBJECT | | 商品属性规则 | +| choose\_all\_qualify\_spec | BOOLEAN | true | 多个销售属性是否需要同时传 | +| input\_max\_spec\_num | LONG | 1 | 允许自定义的销售属性数量 | +| properties | OBJECT\[\] | | 属性信息 | +| can\_note | BOOLEAN | true | 是否允许填写备注,仅当是销售属性时有意义 | +| choose\_max\_num | INTEGER | 1 | 可选择属性值数目,为0时代表不限。包括自定义的属性值和模版中给出的属性值。 | +| input\_max\_num | INTEGER | 0 | 可自定义属性值数目,为0时代表不可自定义。 | +| is\_important | BOOLEAN | true | 是否重要属性。填写重要属性有更多机会获取搜索、活动等场景流量。 | +| is\_sale | BOOLEAN | true | 是否销售属性。销售属性需要在发商品时,商品属性上的属性值与规格中中的spec对应。 | +| is\_sku | BOOLEAN | false | 是否sku属性,sku维度的属性在商品发布时入参在sku对象下 | +| max\_value | STRING | 10 | 最大值。在不同的属性值类型下有不同的含义。 文本类型时,代表文本最大长度; 数值类型时,代表数字最大值; 时间类型且最大值为时间时,代表时间最大值; 时间类型且最大值为数字时,代表距离今天或者本月往后的天数或月数。 | +| min\_value | STRING | 1 | 最小值。在不同的属性值类型下有不同的含义。 文本类型时,代表文本最小长度; 数值类型时,代表数字最小值; 时间类型且最小值为时间时,代表时间最小值; 时间类型且最小值为数字时,代表距离今天或者本月往前的天数或月数。 | +| name | STRING | 品牌 | 属性名称 | +| parent\_spec\_id | LONG | 111111 | 销售属性对应的父规格id。 | +| property\_value\_type | INTEGER | 0 | 属性值类型。在发商品时传自定义的属性值时,有不同的格式。 0=文本; 1=数值,如“100”; 2=数值范围,如“10,20”,表示10到20之间; 3=数值乘积-二维,如“10,10”,表示10\*10; 4=数值乘积-三维,如“10,10,10”,表示10\*10\*10; 5=单项时间选择-年月日,如“2020-05-20”; 6=双项时间选择-年月日,如“2020-05-20,2020-06-20”; 7=单项时间选择-年月,如“2020-05”; 8=双项时间选择-年月,如“2020-05,2020-06”;9=材质成分表,支持补充材质百分比,在table\_info字段。 | +| ref\_pid | LONG | 310 | 属性id | +| required | BOOLEAN | true | 是否必填 | +| required\_rule | STRING | | 必填规则具体内容,当required=true且required\_rule\_type=1时该字段有效,表示当出现哪些属性/属性值时,该属性需要必填,json格式,两层List结构,外层list代表"或"关系,内层list代表"且"关系,例如:\[\[{\\"ref\_pid\\":123,\\"vid\\":123}\]\] | +| required\_rule\_type | INTEGER | 0 | required=true时,该字段有效,为“0”时表示当前属性必填,不受其他属性影响,为“1”时表示当前属性是否必填由已填写的其他属性值决定 | +| show\_condition | OBJECT\[\] | | 该属性的父属性。只有parent\_pid下的show\_vids中的值被选择时才可入参该属性。有多组父属性时,为且的关系。 | +| parent\_ref\_pid | LONG | 1111 | 父属性id。 | +| parent\_vids | LONG\[\] | | 父属性值id。多个值任选其一即可。若为空表示任意值都可以。 | +| value\_precision | INTEGER | 0 | 小数点允许最大精度,为0时代表不允许输入小数。对数值类属性值限制。 | +| value\_unit | STRING\[\] | | 可选属性值单位,发商品填写自定义数值属性值时,选择其中之一作为单位。 | +| values | OBJECT\[\] | | 属性值列表 | +| extend\_info | STRING | (255,255,255,1) | 扩展信息,表示颜色的色号。格式为ARGB | +| group | OBJECT | | 分组信息 | +| id | INTEGER | 1 | 组id | +| name | STRING | 红色系 | 组名称 | +| parent\_vids | LONG\[\] | | 表示对应父属性值id。当其中父属性值被选中时该子属性值才可选。为空则表示无此限制。 | +| spec\_id | LONG | 1122 | 规格id,发商品时需要和sku上的spec对应。 | +| value | STRING | aaa | 属性值 | +| vid | LONG | 1111 | 基础属性值id | +| goods\_service\_rule | OBJECT | | 商品服务规则 | +| goods\_service\_rule\_map | MAP | | | +| $key | STRING | | 商品类型 | +| $value | OBJECT | | | +| bad\_claim\_rule | INTEGER | | 坏了包赔规则:0不可选、1可选、2必选 | +| can\_select\_delivery\_type | BOOLEAN | | 是否可以选择物流方式 | +| delivery\_one\_day\_rule | INTEGER | | 当日发货规则:0不可选、1可选 | +| folt\_rule | INTEGER | | 假一赔十规则:0不可选、1可选、2必选 | +| lack\_of\_weight\_claim\_rule | INTEGER | | 缺重包退规则:0不可选、1可选、2必选 | +| need\_upload\_package\_label | BOOLEAN | | 可以上传包装标签图 | +| need\_upload\_package\_label\_required | BOOLEAN | | 是否必填包装标签图 | +| need\_upload\_package\_label\_type | INTEGER | | 包装标签图类型:1化妆品、2食品、3农药、4安全帽、5调压阀、6玩具 | +| privacy\_delivery\_rule | INTEGER | | 保密发货:0不可选、1可选 | +| quan\_guo\_lian\_bao\_rule | INTEGER | | 全国联保规则:0不可选、1可选 | +| refundable\_rule | INTEGER | | 7天无理由退换货规则:0不可选、1可选、2必选 | +| rule\_related\_ref\_pid\_map | MAP | | 规则相关属性,变更时需重新调用rule接口 | +| $key | STRING | | 规则相关属性场景枚举值。1、packageLabelImg包装标签图 | +| $value | LONG\[\] | | 属性id | +| shipment\_limit\_second\_list | INTEGER\[\] | | 可选承诺发货时间列表,单位:秒 | +| zhi\_huan\_bu\_xiu\_rule | INTEGER | | 只换不修规则:0不可选、1可选 | +| goods\_type\_list | INTEGER\[\] | | 可选的商品类型列表 | +| goods\_sku\_rule | OBJECT | | sku规则 | +| price\_range\_ratio | DOUBLE | | 团购价最高差倍率 | +| spec\_num\_limit | INTEGER | | 同个商品下规格值的加和数量上限 | +| spu\_rule | OBJECT | | 标品规则 | +| control\_type | INTEGER | | 标品管控类型。0=不管控;1=管控,表示商品发布时必须命中标品,且发布成功后不可更改关键属性;2=不可换品,表示发布成功后不可更改关键属性。 | +| key\_prop | OBJECT\[\] | | 关键属性 | +| pname | STRING | | 关键属性名 | +| ref\_pid | LONG | | 关键属性id | +| two\_pieces\_discount\_rule | OBJECT | | 满2件折扣相关规则 | +| if\_must\_two\_pieces\_discount | BOOLEAN | | 是否必须设置 | +| max\_two\_pieces\_discount | INTEGER | | 允许的最大折扣 | +| min\_two\_pieces\_discount | INTEGER | | 允许的最小折扣 | +| recommend\_two\_pieces\_discount | INTEGER | | 推荐的折扣 | + +### 请求示例 + +JAVA + +CURL + +``` +package com.pdd.pop.sdk.http.demo; + +import com.pdd.pop.sdk.common.util.JsonUtil; +import com.pdd.pop.sdk.http.api.pop.request.PddGoodsCatRuleGetRequest; +import com.pdd.pop.sdk.http.api.pop.response.PddGoodsCatRuleGetResponse; +import com.pdd.pop.sdk.http.api.pop.request.PddGoodsCatRuleGetRequest.GoodsPropertiesItem; +import com.pdd.pop.sdk.http.api.pop.request.PddGoodsCatRuleGetRequest.GoodsPropertiesItemTableInfo; +import com.pdd.pop.sdk.http.api.pop.request.PddGoodsCatRuleGetRequest.GoodsPropertiesItemTableInfoTableValueListItem; +import com.pdd.pop.sdk.http.PopClient; +import com.pdd.pop.sdk.http.PopHttpClient; + +import java.util.*; + +public class PopClientDemo { + + public static void main(String[] args) throws Exception { + + String clientId = "your clientId"; + String clientSecret = "your clientSecret"; + String accessToken = "your accessToken"; + PopClient client = new PopHttpClient(clientId, clientSecret); + + PddGoodsCatRuleGetRequest request = new PddGoodsCatRuleGetRequest(); + request.setCatId(123L); + request.setGoodsId(123123L); + List goodsProperties = new ArrayList(); + + GoodsPropertiesItem item = new GoodsPropertiesItem(); + item.setGroupId(0); + item.setImgUrl("str"); + item.setNote("str"); + item.setParentSpecId(0L); + item.setRefPid(0L); + item.setSpecId(0L); + + GoodsPropertiesItemTableInfo tableInfo = new GoodsPropertiesItemTableInfo(); + List tableValueList = new ArrayList(); + + GoodsPropertiesItemTableInfoTableValueListItem item1 = new GoodsPropertiesItemTableInfoTableValueListItem(); + item1.setColumnType(1); + item1.setUnit("str"); + item1.setValue("str"); + tableValueList.add(item1); + tableInfo.setTableValueList(tableValueList); + item.setTableInfo(tableInfo); + item.setTemplatePid(0L); + item.setValue("str"); + item.setValueUnit("str"); + item.setVid(0L); + goodsProperties.add(item); + request.setGoodsProperties(goodsProperties); + PddGoodsCatRuleGetResponse response = client.syncInvoke(request, accessToken); + System.out.println(JsonUtil.transferToJson(response)); + } +} +``` + +### 响应示例 + +``` +{ + "cat_rule_get_response": { + "goods_properties_rule": { + "choose_all_qualify_spec": true, + "input_max_spec_num": 1, + "properties": [ + { + "can_note": true, + "choose_max_num": 1, + "input_max_num": 0, + "is_important": true, + "is_sale": true, + "is_sku": false, + "max_value": "10", + "min_value": "1", + "name": "品牌", + "parent_spec_id": 111111, + "property_value_type": 0, + "ref_pid": 310, + "required": true, + "required_rule": "str", + "required_rule_type": 0, + "show_condition": [ + { + "parent_ref_pid": 1111, + "parent_vids": [ + 1234 + ] + } + ], + "value_precision": 0, + "value_unit": [ + "kg" + ], + "values": [ + { + "extend_info": "(255,255,255,1)", + "group": { + "id": 1, + "name": "红色系" + }, + "parent_vids": [ + 12345 + ], + "spec_id": 1122, + "value": "aaa", + "vid": 1111 + } + ] + } + ] + }, + "goods_service_rule": { + "goods_service_rule_map": { + "": { + "bad_claim_rule": 0, + "can_select_delivery_type": false, + "delivery_one_day_rule": 0, + "folt_rule": 0, + "lack_of_weight_claim_rule": 0, + "need_upload_package_label": false, + "need_upload_package_label_required": false, + "need_upload_package_label_type": 0, + "privacy_delivery_rule": 0, + "quan_guo_lian_bao_rule": 0, + "refundable_rule": 0, + "rule_related_ref_pid_map": { + "": [ + 0 + ] + }, + "shipment_limit_second_list": [ + 0 + ], + "zhi_huan_bu_xiu_rule": 0 + } + }, + "goods_type_list": [ + 0 + ] + }, + "goods_sku_rule": { + "price_range_ratio": 0.0, + "spec_num_limit": 0 + }, + "spu_rule": { + "control_type": 0, + "key_prop": [ + { + "pname": "str", + "ref_pid": 0 + } + ] + }, + "two_pieces_discount_rule": { + "if_must_two_pieces_discount": false, + "max_two_pieces_discount": 0, + "min_two_pieces_discount": 0, + "recommend_two_pieces_discount": 0 + } + } +} +``` + +### 异常示例 + +JSON + +XML + +``` +{ + "error_response": { + "error_msg": "公共参数错误:type", + "sub_msg": "", + "sub_code": null, + "error_code": 10001, + "request_id": "15440104776643887" + } +} +``` + +### 相关权限包 + +| 拥有此接口的权限包 | 可获得/可申请此权限包的应用类型 | +| --- | --- | +| 商品编辑 | 进销存、商品优化分析、虚拟商家后台系统、企业ERP、商家后台系统、电子凭证商家后台系统、跨境企业ERP报关版 | + +### 返回错误码说明 + +| 主错误码 | 主错误描述 | 子错误码 | 子错误描述 | 解决办法 | +| --- | --- | --- | --- | --- | +| 10000 | 参数错误 | 10000 | 参数错误 | 参数值有误,按照文档要求填写请求参数 | +| 10001 | 公共参数错误 | 10001 | 公共参数错误 | 请检查请求的公共参数 | +| 10016 | client下线或者clientId不正确 | 10016 | client下线或者clientId不正确 | 请核查您的client\_id是否正确 | +| 10017 | type不正确 | 10017 | type不正确 | 检查type是否正确 | +| 10018 | target\_client\_id下线或者target\_client\_id不正确 | 10018 | target\_client\_id下线或者target\_client\_id不正确 | 检查target\_client\_id 是否正确 | +| 10019 | access\_token已过期 | 10019 | access\_token已过期 | 刷新access\_token或者重新授权再次获取access\_token | +| 20004 | 签名sign校验失败 | 20004 | 签名sign校验失败 | 请按照接入指南第三部分指导,生成签名 | +| 20005 | ip无权访问接口,请加入ip白名单 | 20005 | ip无权访问接口,请加入ip白名单 | 把ip白名单加入白名单 | +| 20031 | 用户没有授权访问此接口 | 20031 | 用户没有授权访问此接口 | 您创建的应用中不包含此接口,请查看API文档,了解相关权限包 | +| 20032 | access\_token或client\_id错误 | 20032 | access\_token或client\_id错误 | 检查access\_token或client\_id | +| 20034 | 接口处于下线状态 | 20034 | 接口处于下线状态 | 检查接口状态 | +| 20035 | 接口不属于当前网关 | 20035 | 接口不属于当前网关 | 判断调用网关url 是否正确 | +| 21001 | 请求参数错误 | 21001 | 请求参数错误 | 业务参数输入错误 | +| 21002 | 请求参数不能为空 | 21002 | 请求参数不能为空 | 检查业务参数必填是否已填 | +| 30000 | 没有调用此target接口权限 | 30000 | 没有调用此target接口权限 | 检查是否获得调用此target接口权限 | +| 30001 | client\_id和partner\_id不匹配 | 30001 | client\_id和partner\_id不匹配 | 检查partner\_id是否正确 | +| 50000 | 系统内部错误 | 50000 | 系统内部错误 | 系统内部错误,请加群联系相关负责人 | +| 50002 | 业务系统内部异常 | 50002 | 业务系统内部异常 | 请加群联系相关负责人 | +| 52001 | 网关业务服务错误 | 52001 | 网关业务服务错误 | 联系技术支持解决 | +| 52002 | 网关系统内部异常 | 52002 | 网关系统内部异常 | 联系技术支持解决 | +| 52004 | 请求body 太大 | 52004 | 请求body 太大 | 检查请求体是否过大 | +| 52101 | 当前接口被限流,请稍后重试 | 52101 | 当前接口被限流,请稍后重试 | 当前接口被限流,请稍后重试 | +| 52102 | 当前接口暂时不可用,请稍后重试 | 52102 | 当前接口暂时不可用,请稍后重试 | 当前接口被降级,请稍后重试 | +| 52103 | 服务暂时不可用,请稍后重试 | 52103 | 服务暂时不可用,请稍后重试 | 当前接口被降级,请稍后重试 | +| 70031 | 调用过于频繁,请调整调用频率 | 70031 | 调用过于频繁,请调整调用频率 | 调用过于频繁,请调整调用频率 | +| 70032 | 当前请求被禁止调用 | 70032 | 当前请求被禁止调用 | 当前请求被禁止调用 | +| 70033 | 当前接口因系统维护,暂时下线,请稍后再试! | 70033 | 当前接口因系统维护,暂时下线,请稍后再试! | 当前接口因系统维护,暂时下线,请稍后再试! | +| 70034 | 当前用户或应用存在风险,禁止调用! | 70034 | 当前用户或应用存在风险,禁止调用! | 当前用户或应用存在风险,禁止调用! | +| 70035 | 当前用户或应用存在风险,禁止调用。请联系ddjb@pinduoduo.com | 70035 | 当前用户或应用存在风险,禁止调用。请联系ddjb@pinduoduo.com | 当前用户或应用存在风险,禁止调用。请联系ddjb@pinduoduo.com | +| 70036 | 应用处于测试状态,调用次数被限制 | 70036 | 应用处于测试状态,调用次数被限制 | 应用处于测试状态,调用次数达到上限被限制 | +| 50001 | 业务服务错误 | isv.###-not-exist:20002 | 类目不存在 | 输入正确的类目 | + +### 限流规则 + +接口总限流频次:5000次/1秒 diff --git a/apps/server/docs/pdd/api-docs/goods/pdd.goods.cat.template.get获取商品类目属性(已废弃).md b/apps/server/docs/pdd/api-docs/goods/pdd.goods.cat.template.get获取商品类目属性(已废弃).md new file mode 100644 index 00000000..5833293c --- /dev/null +++ b/apps/server/docs/pdd/api-docs/goods/pdd.goods.cat.template.get获取商品类目属性(已废弃).md @@ -0,0 +1,247 @@ +API文档/商品API/pdd.goods.cat.template.get + +# pdd.goods.cat.template.get + +## 获取商品类目属性(已废弃) + +更新时间:2021-04-13 23:04:54 + +¥免费API + +必须用户授权 + +商品发布前,需要查询该类目的商品发布需要的属性,获取商品发布需要的模板-属性-属性值。已废弃,建议使用pdd.goods.cat.rule.get代替 + +### 公共参数 + +#### 请求地址(目前只提供正式环境,暂无沙箱环境) + +| 环境 | HTTP地址 | HTTPS地址 | +| --- | --- | --- | +| 正式环境 | http://gw-api.pinduoduo.com/api/router | https://gw-api.pinduoduo.com/api/router | + +#### 公共请求参数 + +| 参数名称 | 参数类型 | 是否必填 | 参数描述 | +| --- | --- | --- | --- | +| type | String | 必填 | API接口名称 | +| client\_id | String | 必填 | POP分配给应用的client\_id | +| access\_token | String | 非必填 | 通过code获取的access\_token | +| timestamp | String | 必填 | UNIX时间戳,单位秒,需要与拼多多服务器时间差值在10分钟内 | +| data\_type | String | 非必填 | 响应格式,即返回数据的格式,JSON或者XML(二选一),默认JSON,注意是大写 | +| version | String | 非必填 | API协议版本号,默认为V1,可不填 | +| sign | String | 必填 | API输入参数签名结果,签名算法参考开放平台接入指南第三部分底部。 | + +### 请求参数说明 + +| 参数接口 | 参数类型 | 是否必填 | 说明 | +| --- | --- | --- | --- | +| cat\_id | LONG | 必填 | 类目id | + +### 返回参数说明 + +| 参数接口 | 参数类型 | 例子 | 说明 | +| --- | --- | --- | --- | +| open\_api\_response | OBJECT | | 属性信息 | +| choose\_all\_qualify\_spec | BOOLEAN | | 限定规格不支持部分选取,为true时限定规格要么全选要么全不选 | +| id | LONG | | 模板id | +| input\_max\_spec\_num | LONG | | 模板允许的最大的自定义规格数量 | +| is\_single\_item | BOOLEAN | | is\_single\_item | +| max\_sku\_num | LONG | | 最大sku数目上限 | +| properties | OBJECT\[\] | | 属性信息 | +| can\_note | BOOLEAN | | 是否允许填写备注 | +| choose\_max\_num | INTEGER | | 最大可勾选数目,为0时代表不限 | +| control\_type | INTEGER | | 控件类型(0-可输入、1-可勾选、3-可输入又可勾选、5-单项时间选择器-年月日、6-双项时间选择器-年月日、7-单项时间选择器-年月、8-双项时间选择器-年月)9-调色盘、10-尺码选择器、11-输入数值范围、12-输入数值乘积-2维、13-输入数值乘积-3维 | +| feature | INTEGER | | 属性特性:0普通,1颜色,2尺码 | +| id | LONG | | 模板属性id | +| input\_max\_num | INTEGER | | 最大可输入数目,为0时代表不可输入,非销售属性为null | +| is\_condition\_show | BOOLEAN | | 是否按条件展示 | +| is\_key | BOOLEAN | | is\_key | +| is\_parent | BOOLEAN | | 是否父属性 | +| is\_sale | BOOLEAN | | 是否销售属性 | +| max\_value | STRING | | 输入最大值:文本类型代表文本最长长度、 数值类型代表数字最大值、时间类型代表时间最大值 | +| min\_value | STRING | | 输入最小值:文本类型代表文本最小长度、数值类型代表数字最小值、时间类型代表时间最小值 | +| name | STRING | | 属性名称 | +| name\_alias | STRING | | 属性别名 | +| parent\_id | LONG | | 父属性id | +| ref\_pid | LONG | | 引用属性id | +| required | BOOLEAN | | 是否必填 | +| required\_rule | STRING | | 必填规则具体内容,当required=true且required\_rule\_type=1时该字段有效,表示当出现哪些属性/属性值时,该属性需要必填,json格式,两层List结构,外层list代表"或"关系,内层list代表"且"关系,例如:\[\[{\\"ref\_pid\\":123,\\"vid\\":123}\]\] | +| required\_rule\_type | INTEGER | | required=true时,该字段有效,为“0”时表示当前属性必填,不受其他属性影响,为“1”时表示当前属性是否必填由已填写的其他属性值决定 | +| show\_only\_standard | BOOLEAN | | show\_only\_standard | +| show\_vids | LONG\[\] | | 若属性按条件展示,则只有show\_vids中的值被选择时属性才可使用 | +| spec\_id | LONG | | 销售属性规格id,非销售属性为null | +| values | OBJECT\[\] | | 属性值列表 | +| extend\_info | STRING | | 扩展信息,颜色的话色号在这里,ARGB,非销售属性为null | +| group | OBJECT | | 分组信息,非销售属性为null | +| id | INTEGER | | 组id | +| name | STRING | | 组名称 | +| is\_parent | BOOLEAN | | 是否父属性值 | +| parent\_vids | LONG\[\] | | 对应的父属性值id | +| spec\_id | LONG | | 规格id,非销售属性为null | +| value | STRING | | 属性值 | +| vid | LONG | | 基础属性值id | +| value\_precision | INTEGER | | 小数点允许最大精度,为0时代表不允许输入小数 | +| value\_type | INTEGER | | 属性值类型(0-文本、1-数值、4-绝对时间、5-相对时间) | +| value\_unit | STRING | | 属性值单位 | +| single\_spec\_value\_num | LONG | | 单个自定义规格值上限 | + +### 请求示例 + +JAVA + +CURL + +``` +package com.pdd.pop.sdk.http.demo; + +import com.pdd.pop.sdk.common.util.JsonUtil; +import com.pdd.pop.sdk.http.api.pop.request.PddGoodsCatTemplateGetRequest; +import com.pdd.pop.sdk.http.api.pop.response.PddGoodsCatTemplateGetResponse; +import com.pdd.pop.sdk.http.PopClient; +import com.pdd.pop.sdk.http.PopHttpClient; + +public class PopClientDemo { + + public static void main(String[] args) throws Exception { + + String clientId = "your clientId"; + String clientSecret = "your clientSecret"; + String accessToken = "your accessToken"; + PopClient client = new PopHttpClient(clientId, clientSecret); + + PddGoodsCatTemplateGetRequest request = new PddGoodsCatTemplateGetRequest(); + request.setCatId(0L); + PddGoodsCatTemplateGetResponse response = client.syncInvoke(request, accessToken); + System.out.println(JsonUtil.transferToJson(response)); + } +} +``` + +### 响应示例 + +``` +{ + "open_api_response": { + "choose_all_qualify_spec": false, + "id": 0, + "input_max_spec_num": 0, + "is_single_item": false, + "max_sku_num": 0, + "properties": [ + { + "can_note": false, + "choose_max_num": 0, + "control_type": 0, + "feature": 0, + "id": 0, + "input_max_num": 0, + "is_condition_show": false, + "is_key": false, + "is_parent": false, + "is_sale": false, + "max_value": "str", + "min_value": "str", + "name": "str", + "name_alias": "str", + "parent_id": 0, + "ref_pid": 0, + "required": false, + "required_rule": "str", + "required_rule_type": 0, + "show_only_standard": false, + "show_vids": [ + 0 + ], + "spec_id": 0, + "value_precision": 0, + "value_type": 0, + "value_unit": "str", + "values": [ + { + "extend_info": "str", + "group": { + "id": 0, + "name": "str" + }, + "is_parent": false, + "parent_vids": [ + 0 + ], + "spec_id": 0, + "value": "str", + "vid": 0 + } + ] + } + ], + "single_spec_value_num": 0 + } +} +``` + +### 异常示例 + +JSON + +XML + +``` +{ + "error_response": { + "error_msg": "公共参数错误:type", + "sub_msg": "", + "sub_code": null, + "error_code": 10001, + "request_id": "15440104776643887" + } +} +``` + +### 相关权限包 + +| 拥有此接口的权限包 | 可获得/可申请此权限包的应用类型 | +| --- | --- | +| 商品类目属性权限包 | 进销存、商品优化分析、虚拟商家后台系统、企业ERP、商家后台系统、电子凭证商家后台系统、跨境企业ERP报关版 | + +### 返回错误码说明 + +| 主错误码 | 主错误描述 | 子错误码 | 子错误描述 | 解决办法 | +| --- | --- | --- | --- | --- | +| 10000 | 参数错误 | 10000 | 参数错误 | 参数值有误,按照文档要求填写请求参数 | +| 10001 | 公共参数错误 | 10001 | 公共参数错误 | 请检查请求的公共参数 | +| 10016 | client下线或者clientId不正确 | 10016 | client下线或者clientId不正确 | 请核查您的client\_id是否正确 | +| 10017 | type不正确 | 10017 | type不正确 | 检查type是否正确 | +| 10018 | target\_client\_id下线或者target\_client\_id不正确 | 10018 | target\_client\_id下线或者target\_client\_id不正确 | 检查target\_client\_id 是否正确 | +| 10019 | access\_token已过期 | 10019 | access\_token已过期 | 刷新access\_token或者重新授权再次获取access\_token | +| 20004 | 签名sign校验失败 | 20004 | 签名sign校验失败 | 请按照接入指南第三部分指导,生成签名 | +| 20005 | ip无权访问接口,请加入ip白名单 | 20005 | ip无权访问接口,请加入ip白名单 | 把ip白名单加入白名单 | +| 20031 | 用户没有授权访问此接口 | 20031 | 用户没有授权访问此接口 | 您创建的应用中不包含此接口,请查看API文档,了解相关权限包 | +| 20032 | access\_token或client\_id错误 | 20032 | access\_token或client\_id错误 | 检查access\_token或client\_id | +| 20034 | 接口处于下线状态 | 20034 | 接口处于下线状态 | 检查接口状态 | +| 20035 | 接口不属于当前网关 | 20035 | 接口不属于当前网关 | 判断调用网关url 是否正确 | +| 21001 | 请求参数错误 | 21001 | 请求参数错误 | 业务参数输入错误 | +| 21002 | 请求参数不能为空 | 21002 | 请求参数不能为空 | 检查业务参数必填是否已填 | +| 30000 | 没有调用此target接口权限 | 30000 | 没有调用此target接口权限 | 检查是否获得调用此target接口权限 | +| 30001 | client\_id和partner\_id不匹配 | 30001 | client\_id和partner\_id不匹配 | 检查partner\_id是否正确 | +| 50000 | 系统内部错误 | 50000 | 系统内部错误 | 系统内部错误,请加群联系相关负责人 | +| 50002 | 业务系统内部异常 | 50002 | 业务系统内部异常 | 请加群联系相关负责人 | +| 52001 | 网关业务服务错误 | 52001 | 网关业务服务错误 | 联系技术支持解决 | +| 52002 | 网关系统内部异常 | 52002 | 网关系统内部异常 | 联系技术支持解决 | +| 52004 | 请求body 太大 | 52004 | 请求body 太大 | 检查请求体是否过大 | +| 52101 | 当前接口被限流,请稍后重试 | 52101 | 当前接口被限流,请稍后重试 | 当前接口被限流,请稍后重试 | +| 52102 | 当前接口暂时不可用,请稍后重试 | 52102 | 当前接口暂时不可用,请稍后重试 | 当前接口被降级,请稍后重试 | +| 52103 | 服务暂时不可用,请稍后重试 | 52103 | 服务暂时不可用,请稍后重试 | 当前接口被降级,请稍后重试 | +| 70031 | 调用过于频繁,请调整调用频率 | 70031 | 调用过于频繁,请调整调用频率 | 调用过于频繁,请调整调用频率 | +| 70032 | 当前请求被禁止调用 | 70032 | 当前请求被禁止调用 | 当前请求被禁止调用 | +| 70033 | 当前接口因系统维护,暂时下线,请稍后再试! | 70033 | 当前接口因系统维护,暂时下线,请稍后再试! | 当前接口因系统维护,暂时下线,请稍后再试! | +| 70034 | 当前用户或应用存在风险,禁止调用! | 70034 | 当前用户或应用存在风险,禁止调用! | 当前用户或应用存在风险,禁止调用! | +| 70035 | 当前用户或应用存在风险,禁止调用。请联系ddjb@pinduoduo.com | 70035 | 当前用户或应用存在风险,禁止调用。请联系ddjb@pinduoduo.com | 当前用户或应用存在风险,禁止调用。请联系ddjb@pinduoduo.com | +| 70036 | 应用处于测试状态,调用次数被限制 | 70036 | 应用处于测试状态,调用次数被限制 | 应用处于测试状态,调用次数达到上限被限制 | +| 50001 | 业务服务错误 | | | | + +### 限流规则 + +商家限流频次:2000次/10秒 + +接口总限流频次:2000次/10秒 diff --git a/apps/server/docs/pdd/api-docs/goods/pdd.goods.submit.goods.commit编辑并提交草稿接口.md b/apps/server/docs/pdd/api-docs/goods/pdd.goods.submit.goods.commit编辑并提交草稿接口.md index 9c8f6f91..66d0021b 100644 --- a/apps/server/docs/pdd/api-docs/goods/pdd.goods.submit.goods.commit编辑并提交草稿接口.md +++ b/apps/server/docs/pdd/api-docs/goods/pdd.goods.submit.goods.commit编辑并提交草稿接口.md @@ -14,7 +14,6 @@ API文档/商品API/pdd.goods.submit.goods.commit ### 公共参数 - #### 请求地址(目前只提供正式环境,暂无沙箱环境) | 环境 | HTTP地址 | HTTPS地址 | @@ -35,7 +34,6 @@ API文档/商品API/pdd.goods.submit.goods.commit ### 请求参数说明 - | 参数接口 | 参数类型 | 是否必填 | 说明 | | --- | --- | --- | --- | | auto\_fill\_spu\_property | BOOLEAN | 非必填 | 是否自动补充标品属性 | @@ -157,7 +155,6 @@ API文档/商品API/pdd.goods.submit.goods.commit ### 返回参数说明 - | 参数接口 | 参数类型 | 例子 | 说明 | | --- | --- | --- | --- | | goods\_update\_response | OBJECT | | 返回response | @@ -167,11 +164,6 @@ API文档/商品API/pdd.goods.submit.goods.commit ### 请求示例 - -JAVA - -CURL - ``` xxxxxxxxxx package com.pdd.pop.sdk.http.demo; @@ -374,8 +366,8 @@ public class PopClientDemo { } ​ ``` -### 响应示例 +### 响应示例 ``` xxxxxxxxxx @@ -387,13 +379,9 @@ xxxxxxxxxx } } ``` + ### 异常示例 - -JSON - -XML - ``` xxxxxxxxxx ​ @@ -407,8 +395,8 @@ xxxxxxxxxx } } ``` -### 相关权限包 +### 相关权限包 | 拥有此接口的权限包 | 可获得/可申请此权限包的应用类型 | | --- | --- | @@ -416,7 +404,6 @@ xxxxxxxxxx ### 返回错误码说明 - | 主错误码 | 主错误描述 | 子错误码 | 子错误描述 | 解决办法 | | --- | --- | --- | --- | --- | | 10000 | 参数错误 | 10000 | 参数错误 | 参数值有误,按照文档要求填写请求参数 | @@ -453,10 +440,6 @@ xxxxxxxxxx ### 限流规则 - 接口总限流频次:3750次/10秒 应用限流频次:100次/1秒 - -### API工具 - diff --git a/apps/server/docs/pdd/api-docs/goods/pdd.one.express.cost.template按id获取商品运费模版接口.md b/apps/server/docs/pdd/api-docs/goods/pdd.one.express.cost.template按id获取商品运费模版接口.md index 9aab97e0..7f60c24f 100644 --- a/apps/server/docs/pdd/api-docs/goods/pdd.one.express.cost.template按id获取商品运费模版接口.md +++ b/apps/server/docs/pdd/api-docs/goods/pdd.one.express.cost.template按id获取商品运费模版接口.md @@ -77,265 +77,102 @@ API文档/商品API/pdd.one.express.cost.template ### 请求示例 -JAVA - -CURL - 195 ``` package com.pdd.pop.sdk.http.demo; -``` -``` -​ -``` -``` + import com.pdd.pop.sdk.common.util.JsonUtil; -``` -``` import com.pdd.pop.sdk.http.api.pop.request.PddOneExpressCostTemplateRequest; -``` -``` import com.pdd.pop.sdk.http.api.pop.response.PddOneExpressCostTemplateResponse; -``` -``` import com.pdd.pop.sdk.http.PopClient; -``` -``` import com.pdd.pop.sdk.http.PopHttpClient; -``` -``` -​ -``` -``` + public class PopClientDemo { -``` -``` -​ -``` -``` -    public static void main(String[] args) throws Exception { -``` -``` -​ -``` -``` -        String clientId = "your clientId"; -``` -``` -        String clientSecret = "your clientSecret"; -``` -``` -        String accessToken = "your accessToken"; -``` -``` -        PopClient client = new PopHttpClient(clientId, clientSecret); -``` -``` -​ -``` -``` -        PddOneExpressCostTemplateRequest request = new PddOneExpressCostTemplateRequest(); -``` -``` -        request.setCostTemplateId(0L); -``` -``` -        PddOneExpressCostTemplateResponse response = client.syncInvoke(request, accessToken); -``` -``` -        System.out.println(JsonUtil.transferToJson(response)); -``` -``` -   } -``` -``` + + public static void main(String[] args) throws Exception { + + String clientId = "your clientId"; + String clientSecret = "your clientSecret"; + String accessToken = "your accessToken"; + PopClient client = new PopHttpClient(clientId, clientSecret); + + PddOneExpressCostTemplateRequest request = new PddOneExpressCostTemplateRequest(); + request.setCostTemplateId(0L); + PddOneExpressCostTemplateResponse response = client.syncInvoke(request, accessToken); + System.out.println(JsonUtil.transferToJson(response)); + } } ``` -``` -​ -``` + ### 响应示例 7 ``` { -``` -``` -  "one_express_cost_template_response": { -``` -``` -    "additional_service_type": 0, -``` -``` -    "city_id": 0, -``` -``` -    "cost_template_list": [ -``` -``` -     { -``` -``` -        "add_cost": 0, -``` -``` -        "add_standard": 0, -``` -``` -        "cost_province_list": [ -``` -``` -         { -``` -``` -            "province": "str", -``` -``` -            "province_id": 0 -``` -``` -         } -``` -``` -       ], -``` -``` -        "first_cost": 0, -``` -``` -        "first_standard": 0, -``` -``` -        "have_free_min_amount": 0, -``` -``` -        "have_free_min_count": 0, -``` -``` -        "is_have_free_min_amount": false, -``` -``` -        "is_have_free_min_count": false -``` -``` -     } -``` -``` -   ], -``` -``` -    "cost_type": 0, -``` -``` -    "district_id": 0, -``` -``` -    "free_deliver_house": false, -``` -``` -    "free_deliver_house_area_list": [ -``` -``` -     { -``` -``` -        "city": "str", -``` -``` -        "city_id": 0, -``` -``` -        "province": "str", -``` -``` -        "province_id": 0, -``` -``` -        "town": "str", -``` -``` -        "town_id": 0 -``` -``` -     } -``` -``` -   ], -``` -``` -    "free_province_list": [ -``` -``` -     { -``` -``` -        "province": "str", -``` -``` -        "province_id": 0 -``` -``` -     } -``` -``` -   ], -``` -``` -    "province_id": 0, -``` -``` -    "sf_free_type": 0, -``` -``` -    "template_id": 0, -``` -``` -    "template_name": "str" -``` -``` + "one_express_cost_template_response": { + "additional_service_type": 0, + "city_id": 0, + "cost_template_list": [ + { + "add_cost": 0, + "add_standard": 0, + "cost_province_list": [ + { + "province": "str", + "province_id": 0 + } + ], + "first_cost": 0, + "first_standard": 0, + "have_free_min_amount": 0, + "have_free_min_count": 0, + "is_have_free_min_amount": false, + "is_have_free_min_count": false + } + ], + "cost_type": 0, + "district_id": 0, + "free_deliver_house": false, + "free_deliver_house_area_list": [ + { + "city": "str", + "city_id": 0, + "province": "str", + "province_id": 0, + "town": "str", + "town_id": 0 + } + ], + "free_province_list": [ + { + "province": "str", + "province_id": 0 + } + ], + "province_id": 0, + "sf_free_type": 0, + "template_id": 0, + "template_name": "str" } -``` -``` } ``` + ### 异常示例 -JSON - -XML - -``` -​ -``` ``` { -``` -``` -  "error_response": { -``` -``` -    "error_msg": "公共参数错误:type", -``` -``` -    "sub_msg": "", -``` -``` -    "sub_code": null, -``` -``` -    "error_code": 10001, -``` -``` -    "request_id": "15440104776643887" -``` -``` + "error_response": { + "error_msg": "公共参数错误:type", + "sub_msg": "", + "sub_code": null, + "error_code": 10001, + "request_id": "15440104776643887" } -``` -``` } ``` + ### 相关权限包 | 拥有此接口的权限包 | 可获得/可申请此权限包的应用类型 | @@ -381,6 +218,3 @@ XML ### 限流规则 接口总限流频次:2500次/1秒 - -### API工具 - diff --git a/apps/server/docs/pdd/clean_scraped_md.py b/apps/server/docs/pdd/clean_scraped_md.py new file mode 100755 index 00000000..cfd1a97a --- /dev/null +++ b/apps/server/docs/pdd/clean_scraped_md.py @@ -0,0 +1,313 @@ +#!/usr/bin/env python3 +"""清理拼多多开放平台文档抓取污染。 + +处理内容: +1. 将「一行一个代码块 + 行号」合并为完整代码块 +2. 去掉 xxxxxxxxxx 占位、行号、零宽字符 / 不间断空格 +3. 去掉「点击收起」「点击展开」等页面交互文案 +4. 去掉仅含空内容的「### API工具」小节 + +用法: + python clean_scraped_md.py # 交互选择 + python clean_scraped_md.py --all # 处理目录下全部 md + python clean_scraped_md.py a.md b.md # 指定文件(相对本脚本目录或绝对路径) + python clean_scraped_md.py --dry-run --all +""" + +from __future__ import annotations + +import argparse +import re +import sys +from pathlib import Path + +ROOT = Path(__file__).resolve().parent + +NUM_LINE = re.compile(r"^\d+\s*$") +UI_TOGGLE = re.compile(r"^(点击收起|点击展开)\s*$") +EMPTY_API_TOOLS = re.compile(r"\n### API工具\s*$") +MULTI_BLANK = re.compile(r"\n{3,}") +TAB_LABEL = re.compile(r"^(JAVA|CURL|JSON|XML)\s*$", re.I) + + +def list_md_files() -> list[Path]: + """列出本目录下全部 md,相对 ROOT 排序。""" + files = sorted(ROOT.rglob("*.md"), key=lambda p: str(p.relative_to(ROOT))) + return [p for p in files if p.is_file()] + + +def resolve_targets(raw: list[str]) -> list[Path]: + """把用户输入的路径解析为绝对路径。""" + out: list[Path] = [] + for item in raw: + p = Path(item) + if not p.is_absolute(): + cand = (ROOT / p).resolve() + if not cand.exists(): + cand = Path.cwd().joinpath(p).resolve() + p = cand + else: + p = p.resolve() + if not p.is_file() or p.suffix.lower() != ".md": + raise FileNotFoundError(f"不是有效的 md 文件: {item}") + out.append(p) + return out + + +def normalize_content(s: str) -> str: + """规范化代码行:nbsp→空格,纯零宽行→空行。""" + s = s.replace("\xa0", " ").replace("\u00a0", " ") + if "\u200b" in s and s.strip("\u200b").strip() == "": + return "" + return s.replace("\u200b", "") + + +def is_xxxx_placeholder(s: str) -> bool: + t = s.strip() + return bool(t) and set(t) <= {"x"} and len(t) >= 4 + + +def merge_polluted_fences(text: str) -> str: + """合并抓取产生的单行代码块序列。""" + raw = text.split("\n") + n = len(raw) + out: list[str] = [] + i = 0 + + def is_fence(idx: int) -> bool: + return idx < n and raw[idx].strip() == "```" + + while i < n: + if not is_fence(i): + line = raw[i] + if "\u200b" in line or "\xa0" in line: + if "\u200b" in line and line.strip("\u200b").strip() == "": + out.append("") + else: + out.append(line.replace("\xa0", " ").replace("\u200b", "")) + else: + out.append(line) + i += 1 + continue + + # 解析当前 fence + j = i + 1 + content_lines: list[str] = [] + while j < n and raw[j].strip() != "```": + content_lines.append(raw[j]) + j += 1 + if j >= n: + out.append(raw[i]) + i += 1 + continue + + # 已是多行代码块,保持原样 + if len(content_lines) > 1: + out.extend(raw[i : j + 1]) + i = j + 1 + continue + + content = content_lines[0] if content_lines else "" + + # 跳过 xxxxxxxxxx 占位及其后的行号 + if is_xxxx_placeholder(content): + k = j + 1 + while k < n and (raw[k].strip() == "" or NUM_LINE.match(raw[k].strip())): + k += 1 + i = k + continue + + seq_start = i + code_parts: list[str] = [] + cur = i + end = j + 1 + + while is_fence(cur): + j2 = cur + 1 + cl: list[str] = [] + while j2 < n and raw[j2].strip() != "```": + cl.append(raw[j2]) + j2 += 1 + if j2 >= n or len(cl) > 1: + break + + c = cl[0] if cl else "" + if not is_xxxx_placeholder(c): + code_parts.append(normalize_content(c)) + + k = j2 + 1 + while k < n and (raw[k].strip() == "" or NUM_LINE.match(raw[k].strip())): + k += 1 + + if is_fence(k): + pj = k + 1 + pcl: list[str] = [] + while pj < n and raw[pj].strip() != "```": + pcl.append(raw[pj]) + pj += 1 + if pj < n and len(pcl) <= 1: + cur = k + end = k + continue + end = k + break + + had_numbers = any( + NUM_LINE.match(raw[t].strip()) for t in range(seq_start, min(end, n)) + ) + + if len(code_parts) >= 2 or (len(code_parts) == 1 and had_numbers): + out.append("```") + out.extend(code_parts) + out.append("```") + i = end + continue + + out.extend(raw[i : j + 1]) + i = j + 1 + + return "\n".join(out) + + +def polish_fences(text: str) -> str: + """整理代码块内外空白。""" + + def repl(m: re.Match[str]) -> str: + body = m.group(1).strip("\n") + return f"```\n{body}\n```" + + text = re.sub(r"```\n(.*?)```", repl, text, flags=re.S) + text = re.sub(r"```\n(#{1,6} )", r"```\n\n\1", text) + return text + + +def strip_ui_noise(text: str) -> str: + """去掉点击收起/展开、语言 Tab 标签、空 API工具 小节。""" + lines = text.split("\n") + kept: list[str] = [] + for line in lines: + if UI_TOGGLE.match(line) or TAB_LABEL.match(line): + continue + kept.append(line) + text = "\n".join(kept) + text = EMPTY_API_TOOLS.sub("\n", text) + text = MULTI_BLANK.sub("\n\n", text) + return text.rstrip() + "\n" + + +def clean_markdown(text: str) -> str: + """对单份文档做完整清理。""" + text = merge_polluted_fences(text) + text = polish_fences(text) + text = strip_ui_noise(text) + return text + + +def interactive_select(files: list[Path]) -> list[Path]: + """终端交互多选 md 文件。""" + if not files: + print("未找到任何 .md 文件。") + return [] + + print(f"目录: {ROOT}") + print("可选文档(输入序号,逗号/空格分隔;a=全部;q=退出):\n") + for idx, path in enumerate(files, 1): + rel = path.relative_to(ROOT) + print(f" {idx:3d}. {rel}") + + print() + raw = input("> ").strip() + if not raw or raw.lower() in {"q", "quit", "exit"}: + return [] + if raw.lower() in {"a", "all", "*"}: + return files + + tokens = re.split(r"[\s,,]+", raw) + selected: list[Path] = [] + for tok in tokens: + if not tok: + continue + if not tok.isdigit(): + print(f"无效输入: {tok}", file=sys.stderr) + return [] + num = int(tok) + if num < 1 or num > len(files): + print(f"序号越界: {num}", file=sys.stderr) + return [] + selected.append(files[num - 1]) + # 保序去重 + seen: set[Path] = set() + uniq: list[Path] = [] + for p in selected: + if p not in seen: + seen.add(p) + uniq.append(p) + return uniq + + +def process_file(path: Path, *, dry_run: bool) -> bool: + """处理单个文件;有实质改动返回 True。""" + original = path.read_text(encoding="utf-8") + cleaned = clean_markdown(original) + rel = path.relative_to(ROOT) if path.is_relative_to(ROOT) else path + + # 仅补文件末尾换行不算实质改动,避免反复误报 + if cleaned.rstrip("\n") == original.rstrip("\n"): + print(f" skip {rel}(无需清理)") + return False + + stats = ( + f"lines {original.count(chr(10))}→{cleaned.count(chr(10))}, " + f"fences {original.count('```')}→{cleaned.count('```')}" + ) + if dry_run: + print(f" dry {rel}({stats})") + return True + + path.write_text(cleaned, encoding="utf-8") + print(f" ok {rel}({stats})") + return True + + +def main(argv: list[str] | None = None) -> int: + parser = argparse.ArgumentParser(description="清理拼多多文档抓取污染") + parser.add_argument( + "paths", + nargs="*", + help="要处理的 md(相对 docs/pdd 或绝对路径);省略则交互选择", + ) + parser.add_argument("--all", action="store_true", help="处理目录下全部 md") + parser.add_argument( + "--dry-run", + action="store_true", + help="只预览改动统计,不写回文件", + ) + args = parser.parse_args(argv) + + all_md = list_md_files() + try: + if args.all: + targets = all_md + elif args.paths: + targets = resolve_targets(args.paths) + else: + targets = interactive_select(all_md) + except FileNotFoundError as e: + print(str(e), file=sys.stderr) + return 1 + + if not targets: + print("未选择文件。") + return 0 + + print(("预览" if args.dry_run else "处理") + f" {len(targets)} 个文件:") + changed = 0 + for path in targets: + if process_file(path, dry_run=args.dry_run): + changed += 1 + print(f"完成:改动 {changed}/{len(targets)}") + return 0 + + +if __name__ == "__main__": + raise SystemExit(main())