feat(channel): 实现视频号小店缺失的商品相关API(Issue #4002)#4033
Conversation
🤖 Augment PR SummarySummary: This PR implements a set of previously-missing 视频号小店商品相关 API wrappers in Changes:
Technical Notes: Most new endpoints post JSON bodies via 🤖 Was this summary useful? React with 👍 or 👎 |
|
|
||
| @Override | ||
| public GiftGetResponse getGiftProduct(String productId, Integer dataType) throws WxErrorException { | ||
| String reqJson = "{\"product_id\":\"" + productId + "\",\"data_type\":" + dataType + "}"; |
There was a problem hiding this comment.
getGiftProduct is building the request body via raw string concatenation; if productId contains characters needing JSON escaping (or if dataType is null), this can generate invalid JSON or send unintended values to the API. Consider using a structured JSON builder/JsonUtils.encode(...) approach so fields are properly escaped and optional fields can be omitted when unset.
Other locations where this applies: weixin-java-channel/src/main/java/me/chanjar/weixin/channel/api/impl/WxChannelGiftServiceImpl.java:79, weixin-java-channel/src/main/java/me/chanjar/weixin/channel/api/impl/WxChannelProductServiceImpl.java:279, weixin-java-channel/src/main/java/me/chanjar/weixin/channel/api/impl/WxChannelProductServiceImpl.java:310, weixin-java-channel/src/main/java/me/chanjar/weixin/channel/api/impl/WxChannelProductServiceImpl.java:317
Severity: medium
Other Locations
weixin-java-channel/src/main/java/me/chanjar/weixin/channel/api/impl/WxChannelGiftServiceImpl.java:79weixin-java-channel/src/main/java/me/chanjar/weixin/channel/api/impl/WxChannelProductServiceImpl.java:279weixin-java-channel/src/main/java/me/chanjar/weixin/channel/api/impl/WxChannelProductServiceImpl.java:310weixin-java-channel/src/main/java/me/chanjar/weixin/channel/api/impl/WxChannelProductServiceImpl.java:317
🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 22a6f33fbe
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| @JsonProperty("product_id") | ||
| private Long productId; |
There was a problem hiding this comment.
Keep stock-flow product IDs as strings
All existing channel product/stock APIs expose product_id and sku_id as String identifiers, so this new request bean forces callers to parse IDs returned by the SDK before they can call getStockFlow. In cases where WeChat returns a non-numeric or out-of-range identifier, the API becomes unusable and Jackson also emits a JSON number instead of the string form used by the rest of the product APIs; please model these IDs as String here as well.
Useful? React with 👍 / 👎.
| @JsonProperty("order_id") | ||
| private Long orderId; |
There was a problem hiding this comment.
Decode stock-flow order IDs as strings
For stock-flow rows created by order operations, this field is the same order_id that the rest of the channel module consistently models as a String. Mapping it to Long makes a successful response with a quoted, non-numeric, or larger-than-64-bit order ID fail deserialization in JsonUtils.decode, causing ResponseUtils to return an internal-error response instead of the stock-flow data.
Useful? React with 👍 / 👎.
|
|
||
| @Override | ||
| public GiftGetResponse getGiftProduct(String productId, Integer dataType) throws WxErrorException { | ||
| String reqJson = "{\"product_id\":\"" + productId + "\",\"data_type\":" + dataType + "}"; |
There was a problem hiding this comment.
Preserve the default gift data type
The new API documents dataType as defaulting to 3, but when callers pass null to use that default this manually constructed body sends an explicit "data_type":null instead of omitting the optional field like the other request beans do. For stores relying on the documented default, WeChat can reject the request rather than returning both online and draft data; use a NON_NULL request bean or default the value before serializing.
Useful? React with 👍 / 👎.
| /** 在售赠品的来源商品id */ | ||
| @JsonProperty("src_product_id") | ||
| private Long srcProductId; |
There was a problem hiding this comment.
Preserve source product IDs as strings
For gifts converted from an on-sale product, src_product_id is the source product identifier; the existing product model already maps the same JSON field as String. Mapping it to Long here means a successful getGiftProduct response with a quoted, non-numeric, or out-of-range source product ID cannot be decoded correctly, so callers lose the origin product linkage for converted gifts.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Pull request overview
该 PR 针对 weixin-java-channel 模块补齐视频号小店商品相关缺失接口(对应 Issue #4002 的一部分),新增赠品管理子服务,并扩展商品服务以覆盖限时抢购更新、库存流水、类目资质校验、品牌推荐、站内外属性映射、立即开售/取消开售等能力。
Changes:
- 在
WxChannelProductService/WxChannelProductServiceImpl中新增 8 个商品相关接口,并补充对应请求/响应 Bean。 - 新增
WxChannelGiftService/WxChannelGiftServiceImpl(赠品管理 6 个接口)及对应bean/gift/*模型。 - 在
WxChannelApiUrlConstants中补齐新增端点 URL 常量,并在WxChannelService暴露getGiftService()。
Reviewed changes
Copilot reviewed 37 out of 37 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| weixin-java-channel/src/main/java/me/chanjar/weixin/channel/constant/WxChannelApiUrlConstants.java | 新增商品扩展端点与赠品端点 URL 常量 |
| weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/product/StockFlowResponse.java | 新增“库存流水”响应模型 |
| weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/product/StockFlowParam.java | 新增“库存流水”请求参数模型 |
| weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/product/StockFlowInfo.java | 新增库存流水明细模型 |
| weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/product/StockFlowExtInfo.java | 新增库存流水扩展信息模型 |
| weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/product/ProductBrandRecommendResponse.java | 新增品牌推荐响应模型 |
| weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/product/ProductBrandRecommendParam.java | 新增品牌推荐请求参数模型 |
| weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/product/ExternalProductMappingResponse.java | 新增站内外属性映射响应模型 |
| weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/product/ExternalProductMappingParam.java | 新增站内外属性映射请求参数模型 |
| weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/product/ExternalProductMappingNewResponse.java | 新增站内外属性映射(新版)响应模型 |
| weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/product/ExternalProductMappingNewParam.java | 新增站内外属性映射(新版)请求参数模型 |
| weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/product/ExternalAttribute.java | 新增外部属性键值对模型(用于映射新版) |
| weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/product/CategoryPreCheckResponse.java | 新增类目资质预校验响应模型 |
| weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/limit/LimitTaskUpdateResponse.java | 新增更新限时抢购任务响应模型 |
| weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/limit/LimitTaskUpdateParam.java | 新增更新限时抢购任务请求参数模型 |
| weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/limit/LimitSkuUpdate.java | 新增限时抢购 SKU 更新模型(补充 product_id) |
| weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/gift/GiftSkuStockDiff.java | 新增赠品库存差量模型 |
| weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/gift/GiftSetSkuParam.java | 新增在售商品转赠品 SKU 划拨参数模型 |
| weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/gift/GiftSetParam.java | 新增在售商品转赠品请求模型 |
| weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/gift/GiftProductUpdateSkuInfo.java | 新增赠品 SKU 更新模型(含 sku_id/stock_diff) |
| weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/gift/GiftProductUpdateInfo.java | 新增更新非卖赠品请求模型 |
| weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/gift/GiftProductSkuInfo.java | 新增添加非卖赠品 SKU 信息模型 |
| weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/gift/GiftProductSku.java | 新增赠品 SKU 详情模型(查询返回) |
| weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/gift/GiftProductResponse.java | 新增添加/更新赠品响应模型 |
| weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/gift/GiftProductListResponse.java | 新增赠品列表/转赠品响应模型 |
| weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/gift/GiftProductInfo.java | 新增添加非卖赠品请求模型 |
| weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/gift/GiftProduct.java | 新增赠品详情数据模型 |
| weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/gift/GiftListParam.java | 新增赠品列表分页请求模型 |
| weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/gift/GiftGetResponse.java | 新增赠品详情获取响应模型(线上/草稿) |
| weixin-java-channel/src/main/java/me/chanjar/weixin/channel/api/WxChannelService.java | 对外暴露赠品服务入口 getGiftService() |
| weixin-java-channel/src/main/java/me/chanjar/weixin/channel/api/WxChannelProductService.java | 扩展商品服务接口(新增 8 个方法签名) |
| weixin-java-channel/src/main/java/me/chanjar/weixin/channel/api/WxChannelGiftService.java | 新增赠品管理服务接口定义 |
| weixin-java-channel/src/main/java/me/chanjar/weixin/channel/api/impl/WxChannelProductServiceImpl.java | 实现新增商品相关接口调用 |
| weixin-java-channel/src/main/java/me/chanjar/weixin/channel/api/impl/WxChannelGiftServiceImpl.java | 新增赠品管理服务实现 |
| weixin-java-channel/src/main/java/me/chanjar/weixin/channel/api/impl/BaseWxChannelServiceImpl.java | 在基础服务实现中懒加载 GiftService 并实现接口方法 |
| public GiftGetResponse getGiftProduct(String productId, Integer dataType) throws WxErrorException { | ||
| String reqJson = "{\"product_id\":\"" + productId + "\",\"data_type\":" + dataType + "}"; | ||
| String resJson = shopService.post(GET_GIFT_PRODUCT_URL, reqJson); |
| * @param taskId 预售任务ID | ||
| * @return WxChannelBaseResponse | ||
| * @throws WxErrorException 异常 | ||
| */ | ||
| WxChannelBaseResponse beginTimingSale(String productId, String taskId) throws WxErrorException; |
| public WxChannelBaseResponse beginTimingSale(String productId, String taskId) throws WxErrorException { | ||
| String reqJson = "{\"product_id\":\"" + productId + "\",\"task_id\":\"" + taskId + "\"}"; | ||
| String resJson = shopService.post(BEGIN_TIMING_SALE_URL, reqJson); | ||
| return ResponseUtils.decode(resJson, WxChannelBaseResponse.class); |
| /** | ||
| * 操作来源(仅对 op_type=1/2/3 生效)。 | ||
| * 2: API(开发者调用);3: API(服务商代调用);5: 手机端;6: web端 | ||
| */ |
| @Override | ||
| public LimitTaskUpdateResponse updateLimitTask(LimitTaskUpdateParam param) throws WxErrorException { | ||
| String reqJson = JsonUtils.encode(param); | ||
| String resJson = shopService.post(UPDATE_LIMIT_TASK_URL, reqJson); | ||
| return ResponseUtils.decode(resJson, LimitTaskUpdateResponse.class); |
| @Override | ||
| public GiftProductResponse addGiftProduct(GiftProductInfo info) throws WxErrorException { | ||
| String reqJson = JsonUtils.encode(info); | ||
| String resJson = shopService.post(ADD_GIFT_PRODUCT_URL, reqJson); | ||
| return ResponseUtils.decode(resJson, GiftProductResponse.class); |
Issue #4002 列出了
weixin-java-channel模块中缺失的28个视频号小店接口。本次实现其中有官方文档可查的14个接口,跳过文档404的6个接口(礼品活动、审核策略、审核配额)。新增
WxChannelGiftService(赠品管理)6个接口:
addGiftProduct/updateGiftProduct/setProductAsGift/getGiftProduct/listGiftProduct/updateGiftStock扩展
WxChannelProductService(新增8个接口)updateLimitTaskgetStockFlowcategoryPreCheckgetProductBrandRecommendexternalProductMappingexternalProductMappingNewbeginTimingSalecancelTimingSale新增 Bean 类
bean/gift/:13个类,涵盖赠品增删改查及库存变更所需的请求/响应模型bean/limit/:LimitSkuUpdate、LimitTaskUpdateParam、LimitTaskUpdateResponsebean/product/:StockFlow*(4个)、CategoryPreCheckResponse、ProductBrandRecommend*(2个)、ExternalProductMapping*(4个)、ExternalAttribute注意事项
GiftProductUpdateInfo未继承GiftProductInfo,避免 Jackson 对同名@JsonProperty("skus")字段产生重复序列化。