feat(channel): 新增微信小店电子面单服务模块与16个官方接口接入#4036
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 89da6f1782
ℹ️ 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".
|
|
||
| private static final long serialVersionUID = 4213577159985597237L; | ||
|
|
||
| private Map<String, Object> params = new LinkedHashMap<>(); |
There was a problem hiding this comment.
Avoid serializing the params backing map
When any dynamic ewaybill request is populated with addParam, Lombok's @Data also exposes this field as getParams(), while @JsonAnyGetter emits the same entries at the top level. The actual POST body therefore includes both the documented fields and an extra params object (for example {"params":{"order_id":"o_1"},"order_id":"o_1"}), which the new API wrappers send to WeChat and can be rejected as an invalid request; the test only checks that the top-level substrings exist. Please hide this backing map from Jackson or avoid generating a public getter for it.
Useful? React with 👍 / 👎.
|
|
||
| @Override | ||
| public TemplateInfoResponse getTemplate(String templateId) throws WxErrorException { | ||
| String resJson = shopService.post(GET_TEMPLATE_URL, new TemplateIdParam(templateId)); |
There was a problem hiding this comment.
Use template_code for template lookup
For the .../biz/template/get endpoint, the request parameter is the standard template code, while template_id is used by the separate getbyid endpoint below. As written, callers of getTemplate(...) will always post {"template_id":...} to the code-based endpoint, so looking up a standard template returned by getTemplateConfig() fails even with a valid code.
Useful? React with 👍 / 👎.
|
|
||
| @Override | ||
| public PrintContentResponse getPrintContent(String waybillId) throws WxErrorException { | ||
| String resJson = shopService.post(GET_PRINT_CONTENT_URL, new WaybillIdParam(waybillId)); |
There was a problem hiding this comment.
Send waybill_ids when fetching print content
The print-content endpoint takes a list field named waybill_ids (and optional template_id), but this wrapper posts a single waybill_id. Any caller using getPrintContent(...) will therefore omit the required array parameter and be unable to retrieve print payloads; this needs a request object/list form matching the endpoint contract.
Useful? React with 👍 / 👎.
| public class WaybillIdsParam implements Serializable { | ||
| private static final long serialVersionUID = -9030594599179993010L; | ||
|
|
||
| @JsonProperty("waybill_id_list") |
There was a problem hiding this comment.
Serialize batch IDs as waybill_ids
The batch print notification API expects the array field waybill_ids, but this shared parameter object serializes it as waybill_id_list. As a result, batchPrintOrder(...) sends a body with the wrong key and the server will treat the required list as missing for otherwise valid batches.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Pull request overview
本 PR 在 weixin-java-channel 模块中新增微信小店电子面单(Ewaybill)能力,按官方文档接入 16 个服务端接口,并按现有 channel 模块的服务注册/懒加载约定纳入 WxChannelService。
Changes:
- 新增
WxChannelEwaybillService接口与WxChannelEwaybillServiceImpl实现,在WxChannelService/BaseWxChannelServiceImpl中加入getEwaybillService()的懒加载接入。 - 在
WxChannelApiUrlConstants增加Ewaybill常量分组,覆盖模板、账号/快递、订单、打印共 16 个 URL。 - 新增
bean.ewaybill包,包括动态参数容器AbstractEwaybillRequest/AbstractEwaybillResponse、显式 ID 包装类(Template/Waybill)、以及各请求/响应子类,并补充序列化/服务入口测试。
Reviewed changes
Copilot reviewed 26 out of 26 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| weixin-java-channel/src/main/java/me/chanjar/weixin/channel/api/WxChannelService.java | 新增 getEwaybillService() 入口 |
| weixin-java-channel/src/main/java/me/chanjar/weixin/channel/api/WxChannelEwaybillService.java | 新增电子面单服务接口(16 方法) |
| weixin-java-channel/src/main/java/me/chanjar/weixin/channel/api/impl/BaseWxChannelServiceImpl.java | 接入 ewaybill 服务的同步懒加载字段 |
| weixin-java-channel/src/main/java/me/chanjar/weixin/channel/api/impl/WxChannelEwaybillServiceImpl.java | 实现 16 个接口,统一通过 shopService.post + ResponseUtils.decode |
| weixin-java-channel/src/main/java/me/chanjar/weixin/channel/constant/WxChannelApiUrlConstants.java | 新增 Ewaybill URL 常量分组 |
| weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/AbstractEwaybillRequest.java | 动态参数请求基类(@JsonAnyGetter/Setter)—存在序列化双写问题 |
| weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/AbstractEwaybillResponse.java | 动态参数响应基类,未匹配字段进 extra |
| weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/TemplateIdParam.java | 模板 ID 参数包装 |
| weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/TemplateIdResponse.java | 显式声明 template_id 字段的响应 |
| weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/TemplateConfigResponse.java、TemplateInfoResponse.java、TemplateCreateRequest.java、TemplateUpdateRequest.java | 模板相关请求/响应包装 |
| weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/AccountInfoResponse.java、DeliveryListResponse.java | 账号/快递公司列表响应 |
| weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/PreCreateRequest.java、PreCreateResponse.java、CreateOrderRequest.java、CreateOrderResponse.java、AddSubOrderRequest.java、OrderDetailResponse.java | 订单/子件相关请求与响应 |
| weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/PrintContentResponse.java | 打印报文响应 |
| weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/WaybillIdParam.java、WaybillIdsParam.java | 单/批量运单 ID 参数包装 |
| weixin-java-channel/src/test/java/me/chanjar/weixin/channel/bean/ewaybill/WxChannelEwaybillBeanTest.java | 序列化/反序列化基础用例 |
| weixin-java-channel/src/test/java/me/chanjar/weixin/channel/api/impl/WxChannelEwaybillServiceAccessorTest.java | 服务入口可用性用例 |
| private Map<String, Object> params = new LinkedHashMap<>(); | ||
|
|
||
| @JsonAnySetter | ||
| public void addParam(String key, Object value) { | ||
| params.put(key, value); | ||
| } | ||
|
|
||
| @JsonAnyGetter | ||
| public Map<String, Object> anyParams() { | ||
| return params; | ||
| } |
| private Map<String, Object> extra = new LinkedHashMap<>(); | ||
|
|
||
| @JsonAnySetter | ||
| public void addExtra(String key, Object value) { | ||
| extra.put(key, value); | ||
| } |
当前
weixin-java-channel缺少电子面单能力,无法覆盖模板管理、账号查询、面单取号、子件追加与打印回传等完整链路。该变更按微信小店官方电子面单文档接入 16 个服务端接口,并统一纳入WxChannelService能力域。服务层接入(API 能力暴露)
WxChannelEwaybillService接口与WxChannelEwaybillServiceImpl实现。WxChannelService增加getEwaybillService()。BaseWxChannelServiceImpl中完成 Ewaybill 服务懒加载接入,保持与现有模块一致的获取方式。官方接口常量补全(16个)
WxChannelApiUrlConstants新增Ewaybill常量分组。template/*、account/get、delivery/get、order/*、print/get。数据模型与参数封装
bean.ewaybill。TemplateIdParam、WaybillIdParam、WaybillIdsParam)。AbstractEwaybillRequest/AbstractEwaybillResponse),保证“按官方字段透传”与向后兼容。单元测试补充
WxChannelEwaybillBeanTest:覆盖关键参数序列化与动态响应反序列化。WxChannelEwaybillServiceAccessorTest:覆盖服务入口可用性(getEwaybillService())。示例(新增服务调用):