From 4393ad0d2037a4acb1eb4d5fc9f4a29a3137c1bb Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Sat, 22 Aug 2026 12:20:00 +0800 Subject: [PATCH 1/4] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=E5=BE=AE?= =?UTF-8?q?=E4=BF=A1=E5=B0=8F=E5=BA=97=E7=94=B5=E5=AD=90=E9=9D=A2=E5=8D=95?= =?UTF-8?q?=E6=9C=8D=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../channel/api/WxChannelEwaybillService.java | 60 +++++++ .../weixin/channel/api/WxChannelService.java | 7 + .../api/impl/BaseWxChannelServiceImpl.java | 9 + .../impl/WxChannelEwaybillServiceImpl.java | 155 ++++++++++++++++++ .../ewaybill/AbstractEwaybillRequest.java | 36 ++++ .../ewaybill/AbstractEwaybillResponse.java | 32 ++++ .../bean/ewaybill/AccountInfoResponse.java | 10 ++ .../bean/ewaybill/AddSubOrderRequest.java | 10 ++ .../bean/ewaybill/CreateOrderRequest.java | 10 ++ .../bean/ewaybill/CreateOrderResponse.java | 10 ++ .../bean/ewaybill/DeliveryListResponse.java | 10 ++ .../bean/ewaybill/OrderDetailResponse.java | 10 ++ .../bean/ewaybill/PreCreateRequest.java | 10 ++ .../bean/ewaybill/PreCreateResponse.java | 10 ++ .../bean/ewaybill/PrintContentParam.java | 22 +++ .../bean/ewaybill/PrintContentResponse.java | 10 ++ .../bean/ewaybill/TemplateCodeParam.java | 16 ++ .../bean/ewaybill/TemplateConfigResponse.java | 10 ++ .../bean/ewaybill/TemplateCreateRequest.java | 10 ++ .../bean/ewaybill/TemplateIdParam.java | 22 +++ .../bean/ewaybill/TemplateIdResponse.java | 21 +++ .../bean/ewaybill/TemplateInfoResponse.java | 10 ++ .../bean/ewaybill/TemplateUpdateRequest.java | 10 ++ .../channel/bean/ewaybill/WaybillIdParam.java | 22 +++ .../bean/ewaybill/WaybillIdsParam.java | 23 +++ .../constant/WxChannelApiUrlConstants.java | 36 ++++ .../WxChannelEwaybillServiceAccessorTest.java | 17 ++ .../bean/ewaybill/PrintContentParamTest.java | 21 +++ .../ewaybill/WxChannelEwaybillBeanTest.java | 59 +++++++ 29 files changed, 688 insertions(+) create mode 100644 weixin-java-channel/src/main/java/me/chanjar/weixin/channel/api/WxChannelEwaybillService.java create mode 100644 weixin-java-channel/src/main/java/me/chanjar/weixin/channel/api/impl/WxChannelEwaybillServiceImpl.java create mode 100644 weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/AbstractEwaybillRequest.java create mode 100644 weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/AbstractEwaybillResponse.java create mode 100644 weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/AccountInfoResponse.java create mode 100644 weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/AddSubOrderRequest.java create mode 100644 weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/CreateOrderRequest.java create mode 100644 weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/CreateOrderResponse.java create mode 100644 weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/DeliveryListResponse.java create mode 100644 weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/OrderDetailResponse.java create mode 100644 weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/PreCreateRequest.java create mode 100644 weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/PreCreateResponse.java create mode 100644 weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/PrintContentParam.java create mode 100644 weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/PrintContentResponse.java create mode 100644 weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/TemplateCodeParam.java create mode 100644 weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/TemplateConfigResponse.java create mode 100644 weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/TemplateCreateRequest.java create mode 100644 weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/TemplateIdParam.java create mode 100644 weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/TemplateIdResponse.java create mode 100644 weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/TemplateInfoResponse.java create mode 100644 weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/TemplateUpdateRequest.java create mode 100644 weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/WaybillIdParam.java create mode 100644 weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/WaybillIdsParam.java create mode 100644 weixin-java-channel/src/test/java/me/chanjar/weixin/channel/api/impl/WxChannelEwaybillServiceAccessorTest.java create mode 100644 weixin-java-channel/src/test/java/me/chanjar/weixin/channel/bean/ewaybill/PrintContentParamTest.java create mode 100644 weixin-java-channel/src/test/java/me/chanjar/weixin/channel/bean/ewaybill/WxChannelEwaybillBeanTest.java diff --git a/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/api/WxChannelEwaybillService.java b/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/api/WxChannelEwaybillService.java new file mode 100644 index 000000000..9b668d4c7 --- /dev/null +++ b/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/api/WxChannelEwaybillService.java @@ -0,0 +1,60 @@ +package me.chanjar.weixin.channel.api; + +import java.util.List; +import me.chanjar.weixin.channel.bean.base.WxChannelBaseResponse; +import me.chanjar.weixin.channel.bean.ewaybill.AccountInfoResponse; +import me.chanjar.weixin.channel.bean.ewaybill.AddSubOrderRequest; +import me.chanjar.weixin.channel.bean.ewaybill.CreateOrderRequest; +import me.chanjar.weixin.channel.bean.ewaybill.CreateOrderResponse; +import me.chanjar.weixin.channel.bean.ewaybill.DeliveryListResponse; +import me.chanjar.weixin.channel.bean.ewaybill.OrderDetailResponse; +import me.chanjar.weixin.channel.bean.ewaybill.PreCreateRequest; +import me.chanjar.weixin.channel.bean.ewaybill.PreCreateResponse; +import me.chanjar.weixin.channel.bean.ewaybill.PrintContentResponse; +import me.chanjar.weixin.channel.bean.ewaybill.TemplateConfigResponse; +import me.chanjar.weixin.channel.bean.ewaybill.TemplateCreateRequest; +import me.chanjar.weixin.channel.bean.ewaybill.TemplateIdResponse; +import me.chanjar.weixin.channel.bean.ewaybill.TemplateInfoResponse; +import me.chanjar.weixin.channel.bean.ewaybill.TemplateUpdateRequest; +import me.chanjar.weixin.common.error.WxErrorException; + +/** + * 视频号小店电子面单服务接口 + * + * @author GitHub Copilot + */ +public interface WxChannelEwaybillService { + + TemplateConfigResponse getTemplateConfig() throws WxErrorException; + + TemplateIdResponse createTemplate(TemplateCreateRequest req) throws WxErrorException; + + WxChannelBaseResponse deleteTemplate(String templateId) throws WxErrorException; + + WxChannelBaseResponse updateTemplate(TemplateUpdateRequest req) throws WxErrorException; + + TemplateInfoResponse getTemplate(String templateCode) throws WxErrorException; + + TemplateInfoResponse getTemplateById(String templateId) throws WxErrorException; + + AccountInfoResponse getAccount() throws WxErrorException; + + DeliveryListResponse getDeliveryList() throws WxErrorException; + + PreCreateResponse preCreateOrder(PreCreateRequest req) throws WxErrorException; + + CreateOrderResponse createOrder(CreateOrderRequest req) throws WxErrorException; + + WxChannelBaseResponse addSubOrder(AddSubOrderRequest req) throws WxErrorException; + + WxChannelBaseResponse cancelOrder(String waybillId) throws WxErrorException; + + OrderDetailResponse getOrder(String waybillId) throws WxErrorException; + + PrintContentResponse getPrintContent(List waybillIds, String templateId) + throws WxErrorException; + + WxChannelBaseResponse printOrder(String waybillId) throws WxErrorException; + + WxChannelBaseResponse batchPrintOrder(List waybillIds) throws WxErrorException; +} diff --git a/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/api/WxChannelService.java b/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/api/WxChannelService.java index ab5497e21..89409ac3e 100644 --- a/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/api/WxChannelService.java +++ b/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/api/WxChannelService.java @@ -210,4 +210,11 @@ public interface WxChannelService extends BaseWxChannelService { */ WxChannelFavoriteService getFavoriteService(); + /** + * 电子面单服务 + * + * @return 电子面单服务 + */ + WxChannelEwaybillService getEwaybillService(); + } diff --git a/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/api/impl/BaseWxChannelServiceImpl.java b/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/api/impl/BaseWxChannelServiceImpl.java index 528376993..47a201853 100644 --- a/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/api/impl/BaseWxChannelServiceImpl.java +++ b/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/api/impl/BaseWxChannelServiceImpl.java @@ -64,6 +64,7 @@ public abstract class BaseWxChannelServiceImpl implements WxChannelService private WxChannelQicService qicService = null; private WxTalentService talentService = null; private WxChannelFavoriteService favoriteService = null; + private WxChannelEwaybillService ewaybillService = null; protected WxChannelConfig config; private int retrySleepMillis = 1000; @@ -509,4 +510,12 @@ public synchronized WxChannelFavoriteService getFavoriteService() { return favoriteService; } + @Override + public synchronized WxChannelEwaybillService getEwaybillService() { + if (ewaybillService == null) { + ewaybillService = new WxChannelEwaybillServiceImpl(this); + } + return ewaybillService; + } + } diff --git a/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/api/impl/WxChannelEwaybillServiceImpl.java b/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/api/impl/WxChannelEwaybillServiceImpl.java new file mode 100644 index 000000000..3728f30fb --- /dev/null +++ b/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/api/impl/WxChannelEwaybillServiceImpl.java @@ -0,0 +1,155 @@ +package me.chanjar.weixin.channel.api.impl; + +import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Ewaybill.ADD_SUB_ORDER_URL; +import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Ewaybill.BATCH_PRINT_ORDER_URL; +import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Ewaybill.CANCEL_ORDER_URL; +import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Ewaybill.CREATE_ORDER_URL; +import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Ewaybill.CREATE_TEMPLATE_URL; +import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Ewaybill.DELETE_TEMPLATE_URL; +import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Ewaybill.GET_ACCOUNT_URL; +import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Ewaybill.GET_DELIVERY_LIST_URL; +import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Ewaybill.GET_ORDER_URL; +import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Ewaybill.GET_PRINT_CONTENT_URL; +import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Ewaybill.GET_TEMPLATE_BY_ID_URL; +import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Ewaybill.GET_TEMPLATE_CONFIG_URL; +import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Ewaybill.GET_TEMPLATE_URL; +import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Ewaybill.PRE_CREATE_ORDER_URL; +import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Ewaybill.PRINT_ORDER_URL; +import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Ewaybill.UPDATE_TEMPLATE_URL; + +import java.util.List; +import me.chanjar.weixin.channel.api.WxChannelEwaybillService; +import me.chanjar.weixin.channel.bean.base.WxChannelBaseResponse; +import me.chanjar.weixin.channel.bean.ewaybill.AccountInfoResponse; +import me.chanjar.weixin.channel.bean.ewaybill.AddSubOrderRequest; +import me.chanjar.weixin.channel.bean.ewaybill.CreateOrderRequest; +import me.chanjar.weixin.channel.bean.ewaybill.CreateOrderResponse; +import me.chanjar.weixin.channel.bean.ewaybill.DeliveryListResponse; +import me.chanjar.weixin.channel.bean.ewaybill.OrderDetailResponse; +import me.chanjar.weixin.channel.bean.ewaybill.PreCreateRequest; +import me.chanjar.weixin.channel.bean.ewaybill.PreCreateResponse; +import me.chanjar.weixin.channel.bean.ewaybill.PrintContentResponse; +import me.chanjar.weixin.channel.bean.ewaybill.PrintContentParam; +import me.chanjar.weixin.channel.bean.ewaybill.TemplateCodeParam; +import me.chanjar.weixin.channel.bean.ewaybill.TemplateConfigResponse; +import me.chanjar.weixin.channel.bean.ewaybill.TemplateCreateRequest; +import me.chanjar.weixin.channel.bean.ewaybill.TemplateIdParam; +import me.chanjar.weixin.channel.bean.ewaybill.TemplateIdResponse; +import me.chanjar.weixin.channel.bean.ewaybill.TemplateInfoResponse; +import me.chanjar.weixin.channel.bean.ewaybill.TemplateUpdateRequest; +import me.chanjar.weixin.channel.bean.ewaybill.WaybillIdParam; +import me.chanjar.weixin.channel.bean.ewaybill.WaybillIdsParam; +import me.chanjar.weixin.channel.util.ResponseUtils; +import me.chanjar.weixin.common.error.WxErrorException; + +/** + * 视频号小店电子面单服务实现。 + * + * @author GitHub Copilot + */ +public class WxChannelEwaybillServiceImpl implements WxChannelEwaybillService { + + /** 微信商店服务 */ + private final BaseWxChannelServiceImpl shopService; + + public WxChannelEwaybillServiceImpl(BaseWxChannelServiceImpl shopService) { + this.shopService = shopService; + } + + @Override + public TemplateConfigResponse getTemplateConfig() throws WxErrorException { + String resJson = shopService.post(GET_TEMPLATE_CONFIG_URL, "{}"); + return ResponseUtils.decode(resJson, TemplateConfigResponse.class); + } + + @Override + public TemplateIdResponse createTemplate(TemplateCreateRequest req) throws WxErrorException { + String resJson = shopService.post(CREATE_TEMPLATE_URL, req); + return ResponseUtils.decode(resJson, TemplateIdResponse.class); + } + + @Override + public WxChannelBaseResponse deleteTemplate(String templateId) throws WxErrorException { + String resJson = shopService.post(DELETE_TEMPLATE_URL, new TemplateIdParam(templateId)); + return ResponseUtils.decode(resJson, WxChannelBaseResponse.class); + } + + @Override + public WxChannelBaseResponse updateTemplate(TemplateUpdateRequest req) throws WxErrorException { + String resJson = shopService.post(UPDATE_TEMPLATE_URL, req); + return ResponseUtils.decode(resJson, WxChannelBaseResponse.class); + } + + @Override + public TemplateInfoResponse getTemplate(String templateCode) throws WxErrorException { + String resJson = shopService.post(GET_TEMPLATE_URL, new TemplateCodeParam(templateCode)); + return ResponseUtils.decode(resJson, TemplateInfoResponse.class); + } + + @Override + public TemplateInfoResponse getTemplateById(String templateId) throws WxErrorException { + String resJson = shopService.post(GET_TEMPLATE_BY_ID_URL, new TemplateIdParam(templateId)); + return ResponseUtils.decode(resJson, TemplateInfoResponse.class); + } + + @Override + public AccountInfoResponse getAccount() throws WxErrorException { + String resJson = shopService.post(GET_ACCOUNT_URL, "{}"); + return ResponseUtils.decode(resJson, AccountInfoResponse.class); + } + + @Override + public DeliveryListResponse getDeliveryList() throws WxErrorException { + String resJson = shopService.post(GET_DELIVERY_LIST_URL, "{}"); + return ResponseUtils.decode(resJson, DeliveryListResponse.class); + } + + @Override + public PreCreateResponse preCreateOrder(PreCreateRequest req) throws WxErrorException { + String resJson = shopService.post(PRE_CREATE_ORDER_URL, req); + return ResponseUtils.decode(resJson, PreCreateResponse.class); + } + + @Override + public CreateOrderResponse createOrder(CreateOrderRequest req) throws WxErrorException { + String resJson = shopService.post(CREATE_ORDER_URL, req); + return ResponseUtils.decode(resJson, CreateOrderResponse.class); + } + + @Override + public WxChannelBaseResponse addSubOrder(AddSubOrderRequest req) throws WxErrorException { + String resJson = shopService.post(ADD_SUB_ORDER_URL, req); + return ResponseUtils.decode(resJson, WxChannelBaseResponse.class); + } + + @Override + public WxChannelBaseResponse cancelOrder(String waybillId) throws WxErrorException { + String resJson = shopService.post(CANCEL_ORDER_URL, new WaybillIdParam(waybillId)); + return ResponseUtils.decode(resJson, WxChannelBaseResponse.class); + } + + @Override + public OrderDetailResponse getOrder(String waybillId) throws WxErrorException { + String resJson = shopService.post(GET_ORDER_URL, new WaybillIdParam(waybillId)); + return ResponseUtils.decode(resJson, OrderDetailResponse.class); + } + + @Override + public PrintContentResponse getPrintContent(List waybillIds, String templateId) + throws WxErrorException { + String resJson = shopService.post(GET_PRINT_CONTENT_URL, new PrintContentParam(waybillIds, templateId)); + return ResponseUtils.decode(resJson, PrintContentResponse.class); + } + + @Override + public WxChannelBaseResponse printOrder(String waybillId) throws WxErrorException { + String resJson = shopService.post(PRINT_ORDER_URL, new WaybillIdParam(waybillId)); + return ResponseUtils.decode(resJson, WxChannelBaseResponse.class); + } + + @Override + public WxChannelBaseResponse batchPrintOrder(List waybillIds) throws WxErrorException { + String resJson = shopService.post(BATCH_PRINT_ORDER_URL, new WaybillIdsParam(waybillIds)); + return ResponseUtils.decode(resJson, WxChannelBaseResponse.class); + } +} diff --git a/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/AbstractEwaybillRequest.java b/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/AbstractEwaybillRequest.java new file mode 100644 index 000000000..9fbc3fbf0 --- /dev/null +++ b/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/AbstractEwaybillRequest.java @@ -0,0 +1,36 @@ +package me.chanjar.weixin.channel.bean.ewaybill; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import java.io.Serializable; +import java.util.LinkedHashMap; +import java.util.Map; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * 电子面单通用请求参数容器。 + * + *

字段按官方文档动态透传,避免非官方字段定义。

+ * + * @author GitHub Copilot + */ +@Data +@NoArgsConstructor +public abstract class AbstractEwaybillRequest implements Serializable { + + private static final long serialVersionUID = 4213577159985597237L; + + @JsonIgnore private Map params = new LinkedHashMap<>(); + + @JsonAnySetter + public void addParam(String key, Object value) { + params.put(key, value); + } + + @JsonAnyGetter + public Map anyParams() { + return params; + } +} diff --git a/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/AbstractEwaybillResponse.java b/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/AbstractEwaybillResponse.java new file mode 100644 index 000000000..a73c2a8e3 --- /dev/null +++ b/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/AbstractEwaybillResponse.java @@ -0,0 +1,32 @@ +package me.chanjar.weixin.channel.bean.ewaybill; + +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import java.util.LinkedHashMap; +import java.util.Map; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; +import me.chanjar.weixin.channel.bean.base.WxChannelBaseResponse; + +/** + * 电子面单通用响应参数容器。 + * + *

未显式声明字段将保存到 extra 字段,便于兼容官方接口变更。

+ * + * @author GitHub Copilot + */ +@Data +@NoArgsConstructor +@EqualsAndHashCode(callSuper = true) +public abstract class AbstractEwaybillResponse extends WxChannelBaseResponse { + + private static final long serialVersionUID = -2460196179063989718L; + + @JsonIgnore private Map extra = new LinkedHashMap<>(); + + @JsonAnySetter + public void addExtra(String key, Object value) { + extra.put(key, value); + } +} diff --git a/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/AccountInfoResponse.java b/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/AccountInfoResponse.java new file mode 100644 index 000000000..4a460bcc6 --- /dev/null +++ b/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/AccountInfoResponse.java @@ -0,0 +1,10 @@ +package me.chanjar.weixin.channel.bean.ewaybill; + +/** + * 电子面单网点/账号信息响应。 + * + * @author GitHub Copilot + */ +public class AccountInfoResponse extends AbstractEwaybillResponse { + private static final long serialVersionUID = 5682783958522805959L; +} diff --git a/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/AddSubOrderRequest.java b/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/AddSubOrderRequest.java new file mode 100644 index 000000000..2e0b90e1f --- /dev/null +++ b/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/AddSubOrderRequest.java @@ -0,0 +1,10 @@ +package me.chanjar.weixin.channel.bean.ewaybill; + +/** + * 电子面单子件追加请求。 + * + * @author GitHub Copilot + */ +public class AddSubOrderRequest extends AbstractEwaybillRequest { + private static final long serialVersionUID = 4250200603210217269L; +} diff --git a/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/CreateOrderRequest.java b/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/CreateOrderRequest.java new file mode 100644 index 000000000..87e8bad3c --- /dev/null +++ b/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/CreateOrderRequest.java @@ -0,0 +1,10 @@ +package me.chanjar.weixin.channel.bean.ewaybill; + +/** + * 电子面单取号请求。 + * + * @author GitHub Copilot + */ +public class CreateOrderRequest extends AbstractEwaybillRequest { + private static final long serialVersionUID = 2521225918646916853L; +} diff --git a/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/CreateOrderResponse.java b/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/CreateOrderResponse.java new file mode 100644 index 000000000..89eafa012 --- /dev/null +++ b/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/CreateOrderResponse.java @@ -0,0 +1,10 @@ +package me.chanjar.weixin.channel.bean.ewaybill; + +/** + * 电子面单取号响应。 + * + * @author GitHub Copilot + */ +public class CreateOrderResponse extends AbstractEwaybillResponse { + private static final long serialVersionUID = 9115454170108519187L; +} diff --git a/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/DeliveryListResponse.java b/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/DeliveryListResponse.java new file mode 100644 index 000000000..eef815afc --- /dev/null +++ b/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/DeliveryListResponse.java @@ -0,0 +1,10 @@ +package me.chanjar.weixin.channel.bean.ewaybill; + +/** + * 开通快递公司列表响应。 + * + * @author GitHub Copilot + */ +public class DeliveryListResponse extends AbstractEwaybillResponse { + private static final long serialVersionUID = 494164885034906535L; +} diff --git a/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/OrderDetailResponse.java b/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/OrderDetailResponse.java new file mode 100644 index 000000000..4717bdcd6 --- /dev/null +++ b/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/OrderDetailResponse.java @@ -0,0 +1,10 @@ +package me.chanjar.weixin.channel.bean.ewaybill; + +/** + * 面单详情响应。 + * + * @author GitHub Copilot + */ +public class OrderDetailResponse extends AbstractEwaybillResponse { + private static final long serialVersionUID = -2406734055149395916L; +} diff --git a/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/PreCreateRequest.java b/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/PreCreateRequest.java new file mode 100644 index 000000000..b76d4f8c3 --- /dev/null +++ b/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/PreCreateRequest.java @@ -0,0 +1,10 @@ +package me.chanjar.weixin.channel.bean.ewaybill; + +/** + * 电子面单预取号请求。 + * + * @author GitHub Copilot + */ +public class PreCreateRequest extends AbstractEwaybillRequest { + private static final long serialVersionUID = 3761501770378571724L; +} diff --git a/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/PreCreateResponse.java b/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/PreCreateResponse.java new file mode 100644 index 000000000..ded9e53da --- /dev/null +++ b/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/PreCreateResponse.java @@ -0,0 +1,10 @@ +package me.chanjar.weixin.channel.bean.ewaybill; + +/** + * 电子面单预取号响应。 + * + * @author GitHub Copilot + */ +public class PreCreateResponse extends AbstractEwaybillResponse { + private static final long serialVersionUID = -6302826807350860584L; +} diff --git a/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/PrintContentParam.java b/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/PrintContentParam.java new file mode 100644 index 000000000..a780162e6 --- /dev/null +++ b/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/PrintContentParam.java @@ -0,0 +1,22 @@ +package me.chanjar.weixin.channel.bean.ewaybill; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import java.io.Serializable; +import java.util.List; +import lombok.AllArgsConstructor; +import lombok.Data; + +/** 获取电子面单打印报文请求参数。 */ +@Data +@AllArgsConstructor +public class PrintContentParam implements Serializable { + private static final long serialVersionUID = 6898522842175667816L; + + @JsonProperty("waybill_ids") + private List waybillIds; + + @JsonInclude(JsonInclude.Include.NON_NULL) + @JsonProperty("template_id") + private String templateId; +} diff --git a/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/PrintContentResponse.java b/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/PrintContentResponse.java new file mode 100644 index 000000000..6a66ffca1 --- /dev/null +++ b/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/PrintContentResponse.java @@ -0,0 +1,10 @@ +package me.chanjar.weixin.channel.bean.ewaybill; + +/** + * 打印报文响应。 + * + * @author GitHub Copilot + */ +public class PrintContentResponse extends AbstractEwaybillResponse { + private static final long serialVersionUID = 1097526332493027364L; +} diff --git a/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/TemplateCodeParam.java b/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/TemplateCodeParam.java new file mode 100644 index 000000000..6772770b6 --- /dev/null +++ b/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/TemplateCodeParam.java @@ -0,0 +1,16 @@ +package me.chanjar.weixin.channel.bean.ewaybill; + +import com.fasterxml.jackson.annotation.JsonProperty; +import java.io.Serializable; +import lombok.AllArgsConstructor; +import lombok.Data; + +/** 面单标准模板编码请求参数。 */ +@Data +@AllArgsConstructor +public class TemplateCodeParam implements Serializable { + private static final long serialVersionUID = 4473438799300843172L; + + @JsonProperty("template_code") + private String templateCode; +} diff --git a/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/TemplateConfigResponse.java b/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/TemplateConfigResponse.java new file mode 100644 index 000000000..f97a7ef52 --- /dev/null +++ b/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/TemplateConfigResponse.java @@ -0,0 +1,10 @@ +package me.chanjar.weixin.channel.bean.ewaybill; + +/** + * 面单标准模板响应。 + * + * @author GitHub Copilot + */ +public class TemplateConfigResponse extends AbstractEwaybillResponse { + private static final long serialVersionUID = 6779567498624326386L; +} diff --git a/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/TemplateCreateRequest.java b/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/TemplateCreateRequest.java new file mode 100644 index 000000000..382f35564 --- /dev/null +++ b/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/TemplateCreateRequest.java @@ -0,0 +1,10 @@ +package me.chanjar.weixin.channel.bean.ewaybill; + +/** + * 新增面单模板请求。 + * + * @author GitHub Copilot + */ +public class TemplateCreateRequest extends AbstractEwaybillRequest { + private static final long serialVersionUID = 2974771986022948202L; +} diff --git a/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/TemplateIdParam.java b/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/TemplateIdParam.java new file mode 100644 index 000000000..5289c4523 --- /dev/null +++ b/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/TemplateIdParam.java @@ -0,0 +1,22 @@ +package me.chanjar.weixin.channel.bean.ewaybill; + +import com.fasterxml.jackson.annotation.JsonProperty; +import java.io.Serializable; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * 模板ID请求参数。 + * + * @author GitHub Copilot + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +public class TemplateIdParam implements Serializable { + private static final long serialVersionUID = -2397006631686547550L; + + @JsonProperty("template_id") + private String templateId; +} diff --git a/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/TemplateIdResponse.java b/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/TemplateIdResponse.java new file mode 100644 index 000000000..878ef5b25 --- /dev/null +++ b/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/TemplateIdResponse.java @@ -0,0 +1,21 @@ +package me.chanjar.weixin.channel.bean.ewaybill; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; + +/** + * 面单模板ID响应。 + * + * @author GitHub Copilot + */ +@Data +@NoArgsConstructor +@EqualsAndHashCode(callSuper = true) +public class TemplateIdResponse extends AbstractEwaybillResponse { + private static final long serialVersionUID = -6756111662032438585L; + + @JsonProperty("template_id") + private String templateId; +} diff --git a/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/TemplateInfoResponse.java b/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/TemplateInfoResponse.java new file mode 100644 index 000000000..62d50dc14 --- /dev/null +++ b/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/TemplateInfoResponse.java @@ -0,0 +1,10 @@ +package me.chanjar.weixin.channel.bean.ewaybill; + +/** + * 面单模板信息响应。 + * + * @author GitHub Copilot + */ +public class TemplateInfoResponse extends AbstractEwaybillResponse { + private static final long serialVersionUID = 5718279884380636289L; +} diff --git a/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/TemplateUpdateRequest.java b/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/TemplateUpdateRequest.java new file mode 100644 index 000000000..752aea304 --- /dev/null +++ b/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/TemplateUpdateRequest.java @@ -0,0 +1,10 @@ +package me.chanjar.weixin.channel.bean.ewaybill; + +/** + * 更新面单模板请求。 + * + * @author GitHub Copilot + */ +public class TemplateUpdateRequest extends AbstractEwaybillRequest { + private static final long serialVersionUID = -6201137374059216895L; +} diff --git a/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/WaybillIdParam.java b/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/WaybillIdParam.java new file mode 100644 index 000000000..a62821d32 --- /dev/null +++ b/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/WaybillIdParam.java @@ -0,0 +1,22 @@ +package me.chanjar.weixin.channel.bean.ewaybill; + +import com.fasterxml.jackson.annotation.JsonProperty; +import java.io.Serializable; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * 运单ID请求参数。 + * + * @author GitHub Copilot + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +public class WaybillIdParam implements Serializable { + private static final long serialVersionUID = -7601452772833268240L; + + @JsonProperty("waybill_id") + private String waybillId; +} diff --git a/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/WaybillIdsParam.java b/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/WaybillIdsParam.java new file mode 100644 index 000000000..49129280b --- /dev/null +++ b/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/WaybillIdsParam.java @@ -0,0 +1,23 @@ +package me.chanjar.weixin.channel.bean.ewaybill; + +import com.fasterxml.jackson.annotation.JsonProperty; +import java.io.Serializable; +import java.util.List; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * 批量运单ID请求参数。 + * + * @author GitHub Copilot + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +public class WaybillIdsParam implements Serializable { + private static final long serialVersionUID = -9030594599179993010L; + + @JsonProperty("waybill_ids") + private List waybillIds; +} diff --git a/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/constant/WxChannelApiUrlConstants.java b/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/constant/WxChannelApiUrlConstants.java index 0b62bf59d..8e7898a01 100644 --- a/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/constant/WxChannelApiUrlConstants.java +++ b/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/constant/WxChannelApiUrlConstants.java @@ -325,6 +325,42 @@ public interface Delivery { String DELIVERY_SEND_URL = "https://api.weixin.qq.com/channels/ec/order/delivery/send"; } + /** 电子面单相关接口 */ + public interface Ewaybill { + /** 获取面单标准模板 */ + String GET_TEMPLATE_CONFIG_URL = "https://api.weixin.qq.com/channels/ec/logistics/ewaybill/biz/template/config"; + /** 新增面单模板 */ + String CREATE_TEMPLATE_URL = "https://api.weixin.qq.com/channels/ec/logistics/ewaybill/biz/template/create"; + /** 删除面单模板 */ + String DELETE_TEMPLATE_URL = "https://api.weixin.qq.com/channels/ec/logistics/ewaybill/biz/template/delete"; + /** 更新面单模板 */ + String UPDATE_TEMPLATE_URL = "https://api.weixin.qq.com/channels/ec/logistics/ewaybill/biz/template/update"; + /** 获取面单模板信息 */ + String GET_TEMPLATE_URL = "https://api.weixin.qq.com/channels/ec/logistics/ewaybill/biz/template/get"; + /** 根据模板ID获取面单模板信息 */ + String GET_TEMPLATE_BY_ID_URL = "https://api.weixin.qq.com/channels/ec/logistics/ewaybill/biz/template/getbyid"; + /** 查询开通的电子面单网点/账号信息 */ + String GET_ACCOUNT_URL = "https://api.weixin.qq.com/channels/ec/logistics/ewaybill/biz/account/get"; + /** 查询开通的快递公司列表 */ + String GET_DELIVERY_LIST_URL = "https://api.weixin.qq.com/channels/ec/logistics/ewaybill/biz/delivery/get"; + /** 电子面单预取号 */ + String PRE_CREATE_ORDER_URL = "https://api.weixin.qq.com/channels/ec/logistics/ewaybill/biz/order/precreate"; + /** 电子面单取号 */ + String CREATE_ORDER_URL = "https://api.weixin.qq.com/channels/ec/logistics/ewaybill/biz/order/create"; + /** 电子面单子件追加 */ + String ADD_SUB_ORDER_URL = "https://api.weixin.qq.com/channels/ec/logistics/ewaybill/biz/order/addsuborder"; + /** 电子面单取消下单 */ + String CANCEL_ORDER_URL = "https://api.weixin.qq.com/channels/ec/logistics/ewaybill/biz/order/cancel"; + /** 查询面单详情 */ + String GET_ORDER_URL = "https://api.weixin.qq.com/channels/ec/logistics/ewaybill/biz/order/get"; + /** 获取打印报文 */ + String GET_PRINT_CONTENT_URL = "https://api.weixin.qq.com/channels/ec/logistics/ewaybill/biz/print/get"; + /** 打印成功通知 */ + String PRINT_ORDER_URL = "https://api.weixin.qq.com/channels/ec/logistics/ewaybill/biz/order/print"; + /** 批量打印通知 */ + String BATCH_PRINT_ORDER_URL = "https://api.weixin.qq.com/channels/ec/logistics/ewaybill/biz/order/batchprint"; + } + /** 运费模板相关接口 */ public interface FreightTemplate { diff --git a/weixin-java-channel/src/test/java/me/chanjar/weixin/channel/api/impl/WxChannelEwaybillServiceAccessorTest.java b/weixin-java-channel/src/test/java/me/chanjar/weixin/channel/api/impl/WxChannelEwaybillServiceAccessorTest.java new file mode 100644 index 000000000..0f53dad6c --- /dev/null +++ b/weixin-java-channel/src/test/java/me/chanjar/weixin/channel/api/impl/WxChannelEwaybillServiceAccessorTest.java @@ -0,0 +1,17 @@ +package me.chanjar.weixin.channel.api.impl; + +import static org.testng.Assert.assertNotNull; + +import org.testng.annotations.Test; + +/** + * @author GitHub Copilot + */ +public class WxChannelEwaybillServiceAccessorTest { + + @Test + public void testGetEwaybillService() { + WxChannelServiceImpl service = new WxChannelServiceImpl(); + assertNotNull(service.getEwaybillService()); + } +} diff --git a/weixin-java-channel/src/test/java/me/chanjar/weixin/channel/bean/ewaybill/PrintContentParamTest.java b/weixin-java-channel/src/test/java/me/chanjar/weixin/channel/bean/ewaybill/PrintContentParamTest.java new file mode 100644 index 000000000..87fb4f9c6 --- /dev/null +++ b/weixin-java-channel/src/test/java/me/chanjar/weixin/channel/bean/ewaybill/PrintContentParamTest.java @@ -0,0 +1,21 @@ +package me.chanjar.weixin.channel.bean.ewaybill; + +import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertTrue; + +import java.util.Arrays; +import me.chanjar.weixin.channel.util.JsonUtils; +import org.testng.annotations.Test; + +/** 电子面单打印请求 JSON 契约测试。 */ +public class PrintContentParamTest { + + @Test + public void shouldEncodeWaybillIdsAndOptionalTemplateId() { + String json = JsonUtils.encode(new PrintContentParam(Arrays.asList("wb_1", "wb_2"), "tpl_1")); + + assertTrue(json.contains("\"waybill_ids\"")); + assertTrue(json.contains("\"template_id\":\"tpl_1\"")); + assertFalse(json.contains("\"waybill_id\"")); + } +} diff --git a/weixin-java-channel/src/test/java/me/chanjar/weixin/channel/bean/ewaybill/WxChannelEwaybillBeanTest.java b/weixin-java-channel/src/test/java/me/chanjar/weixin/channel/bean/ewaybill/WxChannelEwaybillBeanTest.java new file mode 100644 index 000000000..aae2a1b74 --- /dev/null +++ b/weixin-java-channel/src/test/java/me/chanjar/weixin/channel/bean/ewaybill/WxChannelEwaybillBeanTest.java @@ -0,0 +1,59 @@ +package me.chanjar.weixin.channel.bean.ewaybill; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertTrue; + +import java.util.Arrays; +import me.chanjar.weixin.channel.util.JsonUtils; +import me.chanjar.weixin.channel.util.ResponseUtils; +import org.testng.annotations.Test; + +/** + * @author GitHub Copilot + */ +public class WxChannelEwaybillBeanTest { + + @Test + public void testTemplateIdParamEncode() { + TemplateIdParam param = new TemplateIdParam("tpl_1"); + String json = JsonUtils.encode(param); + assertNotNull(json); + assertTrue(json.contains("\"template_id\":\"tpl_1\"")); + } + + @Test + public void testWaybillIdsParamEncode() { + WaybillIdsParam param = new WaybillIdsParam(Arrays.asList("wb_1", "wb_2")); + String json = JsonUtils.encode(param); + assertNotNull(json); + assertTrue(json.contains("\"waybill_ids\"")); + assertTrue(json.contains("wb_1")); + assertTrue(json.contains("wb_2")); + } + + @Test + public void testDynamicRequestEncode() { + PreCreateRequest request = new PreCreateRequest(); + request.addParam("order_id", "o_1"); + request.addParam("package_quantity", 2); + + String json = JsonUtils.encode(request); + assertNotNull(json); + assertTrue(json.contains("\"order_id\":\"o_1\"")); + assertTrue(json.contains("\"package_quantity\":2")); + assertFalse(json.contains("\"params\"")); + } + + @Test + public void testDynamicResponseDecode() { + String json = "{\"errcode\":0,\"errmsg\":\"ok\",\"waybill_id\":\"wb_1\",\"print_info\":\"abc\"}"; + PrintContentResponse response = ResponseUtils.decode(json, PrintContentResponse.class); + + assertNotNull(response); + assertTrue(response.isSuccess()); + assertEquals(response.getExtra().get("waybill_id"), "wb_1"); + assertEquals(response.getExtra().get("print_info"), "abc"); + } +} From 29e306064ecca2725817d6574869e4afec65067d Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Sat, 22 Aug 2026 12:28:31 +0800 Subject: [PATCH 2/4] =?UTF-8?q?fix:=20=E5=A4=84=E7=90=86=E7=94=B5=E5=AD=90?= =?UTF-8?q?=E9=9D=A2=E5=8D=95=E4=BB=A3=E7=A0=81=E5=AE=A1=E6=9F=A5=E6=84=8F?= =?UTF-8?q?=E8=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bean/ewaybill/AbstractEwaybillRequest.java | 3 ++- .../bean/ewaybill/AbstractEwaybillResponse.java | 3 ++- .../channel/bean/ewaybill/PrintContentParam.java | 2 ++ .../channel/bean/ewaybill/TemplateCodeParam.java | 2 ++ .../bean/ewaybill/PrintContentParamTest.java | 8 ++++++++ .../bean/ewaybill/WxChannelEwaybillBeanTest.java | 13 ++++++++++--- 6 files changed, 26 insertions(+), 5 deletions(-) diff --git a/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/AbstractEwaybillRequest.java b/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/AbstractEwaybillRequest.java index 9fbc3fbf0..d863c7c89 100644 --- a/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/AbstractEwaybillRequest.java +++ b/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/AbstractEwaybillRequest.java @@ -22,7 +22,8 @@ public abstract class AbstractEwaybillRequest implements Serializable { private static final long serialVersionUID = 4213577159985597237L; - @JsonIgnore private Map params = new LinkedHashMap<>(); + @JsonIgnore + private Map params = new LinkedHashMap<>(); @JsonAnySetter public void addParam(String key, Object value) { diff --git a/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/AbstractEwaybillResponse.java b/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/AbstractEwaybillResponse.java index a73c2a8e3..f62aab4ad 100644 --- a/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/AbstractEwaybillResponse.java +++ b/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/AbstractEwaybillResponse.java @@ -23,7 +23,8 @@ public abstract class AbstractEwaybillResponse extends WxChannelBaseResponse { private static final long serialVersionUID = -2460196179063989718L; - @JsonIgnore private Map extra = new LinkedHashMap<>(); + @JsonIgnore + private Map extra = new LinkedHashMap<>(); @JsonAnySetter public void addExtra(String key, Object value) { diff --git a/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/PrintContentParam.java b/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/PrintContentParam.java index a780162e6..8af2b7c30 100644 --- a/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/PrintContentParam.java +++ b/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/PrintContentParam.java @@ -6,9 +6,11 @@ import java.util.List; import lombok.AllArgsConstructor; import lombok.Data; +import lombok.NoArgsConstructor; /** 获取电子面单打印报文请求参数。 */ @Data +@NoArgsConstructor @AllArgsConstructor public class PrintContentParam implements Serializable { private static final long serialVersionUID = 6898522842175667816L; diff --git a/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/TemplateCodeParam.java b/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/TemplateCodeParam.java index 6772770b6..ae062ea74 100644 --- a/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/TemplateCodeParam.java +++ b/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/TemplateCodeParam.java @@ -4,9 +4,11 @@ import java.io.Serializable; import lombok.AllArgsConstructor; import lombok.Data; +import lombok.NoArgsConstructor; /** 面单标准模板编码请求参数。 */ @Data +@NoArgsConstructor @AllArgsConstructor public class TemplateCodeParam implements Serializable { private static final long serialVersionUID = 4473438799300843172L; diff --git a/weixin-java-channel/src/test/java/me/chanjar/weixin/channel/bean/ewaybill/PrintContentParamTest.java b/weixin-java-channel/src/test/java/me/chanjar/weixin/channel/bean/ewaybill/PrintContentParamTest.java index 87fb4f9c6..04b489be4 100644 --- a/weixin-java-channel/src/test/java/me/chanjar/weixin/channel/bean/ewaybill/PrintContentParamTest.java +++ b/weixin-java-channel/src/test/java/me/chanjar/weixin/channel/bean/ewaybill/PrintContentParamTest.java @@ -10,6 +10,14 @@ /** 电子面单打印请求 JSON 契约测试。 */ public class PrintContentParamTest { + @Test + public void shouldHaveNoArgsConstructor() { + PrintContentParam param = new PrintContentParam(); + param.setWaybillIds(Arrays.asList("wb_1")); + + assertTrue(JsonUtils.encode(param).contains("\"waybill_ids\"")); + } + @Test public void shouldEncodeWaybillIdsAndOptionalTemplateId() { String json = JsonUtils.encode(new PrintContentParam(Arrays.asList("wb_1", "wb_2"), "tpl_1")); diff --git a/weixin-java-channel/src/test/java/me/chanjar/weixin/channel/bean/ewaybill/WxChannelEwaybillBeanTest.java b/weixin-java-channel/src/test/java/me/chanjar/weixin/channel/bean/ewaybill/WxChannelEwaybillBeanTest.java index aae2a1b74..dcb79908b 100644 --- a/weixin-java-channel/src/test/java/me/chanjar/weixin/channel/bean/ewaybill/WxChannelEwaybillBeanTest.java +++ b/weixin-java-channel/src/test/java/me/chanjar/weixin/channel/bean/ewaybill/WxChannelEwaybillBeanTest.java @@ -23,6 +23,14 @@ public void testTemplateIdParamEncode() { assertTrue(json.contains("\"template_id\":\"tpl_1\"")); } + @Test + public void testTemplateCodeParamNoArgsConstructor() { + TemplateCodeParam param = new TemplateCodeParam(); + param.setTemplateCode("standard_tpl"); + + assertTrue(JsonUtils.encode(param).contains("\"template_code\":\"standard_tpl\"")); + } + @Test public void testWaybillIdsParamEncode() { WaybillIdsParam param = new WaybillIdsParam(Arrays.asList("wb_1", "wb_2")); @@ -48,12 +56,11 @@ public void testDynamicRequestEncode() { @Test public void testDynamicResponseDecode() { - String json = "{\"errcode\":0,\"errmsg\":\"ok\",\"waybill_id\":\"wb_1\",\"print_info\":\"abc\"}"; + String json = "{\"errcode\":0,\"errmsg\":\"ok\",\"future_extension\":\"value\"}"; PrintContentResponse response = ResponseUtils.decode(json, PrintContentResponse.class); assertNotNull(response); assertTrue(response.isSuccess()); - assertEquals(response.getExtra().get("waybill_id"), "wb_1"); - assertEquals(response.getExtra().get("print_info"), "abc"); + assertEquals(response.getExtra().get("future_extension"), "value"); } } From c3e2426e2a4bdbfc994eb57a51dfece9d8835cf1 Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Sat, 22 Aug 2026 12:35:25 +0800 Subject: [PATCH 3/4] =?UTF-8?q?fix:=20=E5=AE=8C=E5=96=84=E7=94=B5=E5=AD=90?= =?UTF-8?q?=E9=9D=A2=E5=8D=95=E6=8E=A5=E5=8F=A3=E5=AE=89=E5=85=A8=E4=B8=8E?= =?UTF-8?q?=E5=85=BC=E5=AE=B9=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../channel/api/WxChannelEwaybillService.java | 16 ++++++++ .../weixin/channel/api/WxChannelService.java | 4 +- .../api/impl/BaseWxChannelServiceImpl.java | 9 +++-- .../impl/WxChannelEwaybillServiceImpl.java | 39 +++++++++++-------- 4 files changed, 48 insertions(+), 20 deletions(-) diff --git a/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/api/WxChannelEwaybillService.java b/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/api/WxChannelEwaybillService.java index 9b668d4c7..bea879040 100644 --- a/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/api/WxChannelEwaybillService.java +++ b/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/api/WxChannelEwaybillService.java @@ -25,36 +25,52 @@ */ public interface WxChannelEwaybillService { + /** 获取可用的标准面单模板。 @return 模板配置 @throws WxErrorException 微信接口调用失败 */ TemplateConfigResponse getTemplateConfig() throws WxErrorException; + /** 创建商家面单模板。 @param req 官方模板创建字段 @return 新模板 ID @throws WxErrorException 调用失败 */ TemplateIdResponse createTemplate(TemplateCreateRequest req) throws WxErrorException; + /** 删除商家面单模板。 @param templateId 模板 ID @return 操作结果 @throws WxErrorException 调用失败 */ WxChannelBaseResponse deleteTemplate(String templateId) throws WxErrorException; + /** 更新商家面单模板。 @param req 官方模板更新字段 @return 操作结果 @throws WxErrorException 调用失败 */ WxChannelBaseResponse updateTemplate(TemplateUpdateRequest req) throws WxErrorException; + /** 查询标准模板信息。 @param templateCode 标准模板编码 @return 模板详情 @throws WxErrorException 调用失败 */ TemplateInfoResponse getTemplate(String templateCode) throws WxErrorException; + /** 按模板 ID 查询商家模板。 @param templateId 模板 ID @return 模板详情 @throws WxErrorException 调用失败 */ TemplateInfoResponse getTemplateById(String templateId) throws WxErrorException; + /** 查询已开通电子面单的网点和账号。 @return 账号信息 @throws WxErrorException 调用失败 */ AccountInfoResponse getAccount() throws WxErrorException; + /** 查询已开通电子面单的快递公司。 @return 快递公司列表 @throws WxErrorException 调用失败 */ DeliveryListResponse getDeliveryList() throws WxErrorException; + /** 预取电子面单号。 @param req 官方预取号字段 @return 预取号结果 @throws WxErrorException 调用失败 */ PreCreateResponse preCreateOrder(PreCreateRequest req) throws WxErrorException; + /** 获取电子面单号。 @param req 官方取号字段,含收寄件信息 @return 面单号结果 @throws WxErrorException 调用失败 */ CreateOrderResponse createOrder(CreateOrderRequest req) throws WxErrorException; + /** 追加电子面单子件。 @param req 官方子件字段 @return 操作结果 @throws WxErrorException 调用失败 */ WxChannelBaseResponse addSubOrder(AddSubOrderRequest req) throws WxErrorException; + /** 取消电子面单下单。 @param waybillId 运单 ID @return 操作结果 @throws WxErrorException 调用失败 */ WxChannelBaseResponse cancelOrder(String waybillId) throws WxErrorException; + /** 查询电子面单详情。 @param waybillId 运单 ID @return 面单详情 @throws WxErrorException 调用失败 */ OrderDetailResponse getOrder(String waybillId) throws WxErrorException; + /** 获取打印报文。 @param waybillIds 运单 ID 列表 @param templateId 可选模板 ID @return 打印内容 @throws WxErrorException 调用失败 */ PrintContentResponse getPrintContent(List waybillIds, String templateId) throws WxErrorException; + /** 通知单个运单打印成功。 @param waybillId 运单 ID @return 操作结果 @throws WxErrorException 调用失败 */ WxChannelBaseResponse printOrder(String waybillId) throws WxErrorException; + /** 批量通知运单打印成功。 @param waybillIds 运单 ID 列表 @return 操作结果 @throws WxErrorException 调用失败 */ WxChannelBaseResponse batchPrintOrder(List waybillIds) throws WxErrorException; } diff --git a/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/api/WxChannelService.java b/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/api/WxChannelService.java index 89409ac3e..64c21408c 100644 --- a/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/api/WxChannelService.java +++ b/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/api/WxChannelService.java @@ -215,6 +215,8 @@ public interface WxChannelService extends BaseWxChannelService { * * @return 电子面单服务 */ - WxChannelEwaybillService getEwaybillService(); + default WxChannelEwaybillService getEwaybillService() { + throw new UnsupportedOperationException("当前 WxChannelService 实现不支持电子面单服务"); + } } diff --git a/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/api/impl/BaseWxChannelServiceImpl.java b/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/api/impl/BaseWxChannelServiceImpl.java index 47a201853..fd432e972 100644 --- a/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/api/impl/BaseWxChannelServiceImpl.java +++ b/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/api/impl/BaseWxChannelServiceImpl.java @@ -236,7 +236,8 @@ protected T executeInternal(RequestExecutor executor, String uri, E try { T result = executor.execute(uriWithAccessToken, data, WxType.Channel); - log.debug("\n【请求地址】: {}\n【请求参数】:{}\n【响应数据】:{}", uriWithAccessToken, dataForLog, + log.debug("\n【请求地址】: {}\n【请求参数】:{}\n【响应数据】:{}", uriWithAccessToken, + printResult ? dataForLog : "...", printResult ? result : "..."); return result; } catch (WxErrorException e) { @@ -263,12 +264,14 @@ protected T executeInternal(RequestExecutor executor, String uri, E } if (error.getErrorCode() != 0) { - log.warn("\n【请求地址】: {}\n【请求参数】:{}\n【错误信息】:{}", uriWithAccessToken, dataForLog, error); + log.warn("\n【请求地址】: {}\n【请求参数】:{}\n【错误信息】:{}", uriWithAccessToken, + printResult ? dataForLog : "...", error); throw new WxErrorException(error, e); } return null; } catch (IOException e) { - log.warn("\n【请求地址】: {}\n【请求参数】:{}\n【异常信息】:{}", uriWithAccessToken, dataForLog, e.getMessage()); + log.warn("\n【请求地址】: {}\n【请求参数】:{}\n【异常信息】:{}", uriWithAccessToken, + printResult ? dataForLog : "...", e.getMessage()); throw new WxRuntimeException(e); } } diff --git a/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/api/impl/WxChannelEwaybillServiceImpl.java b/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/api/impl/WxChannelEwaybillServiceImpl.java index 3728f30fb..195b634d6 100644 --- a/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/api/impl/WxChannelEwaybillServiceImpl.java +++ b/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/api/impl/WxChannelEwaybillServiceImpl.java @@ -39,8 +39,10 @@ import me.chanjar.weixin.channel.bean.ewaybill.TemplateUpdateRequest; import me.chanjar.weixin.channel.bean.ewaybill.WaybillIdParam; import me.chanjar.weixin.channel.bean.ewaybill.WaybillIdsParam; +import me.chanjar.weixin.channel.util.JsonUtils; import me.chanjar.weixin.channel.util.ResponseUtils; import me.chanjar.weixin.common.error.WxErrorException; +import me.chanjar.weixin.common.util.http.SimplePostRequestExecutor; /** * 视频号小店电子面单服务实现。 @@ -58,98 +60,103 @@ public WxChannelEwaybillServiceImpl(BaseWxChannelServiceImpl shopService) @Override public TemplateConfigResponse getTemplateConfig() throws WxErrorException { - String resJson = shopService.post(GET_TEMPLATE_CONFIG_URL, "{}"); + String resJson = post(GET_TEMPLATE_CONFIG_URL, "{}"); return ResponseUtils.decode(resJson, TemplateConfigResponse.class); } @Override public TemplateIdResponse createTemplate(TemplateCreateRequest req) throws WxErrorException { - String resJson = shopService.post(CREATE_TEMPLATE_URL, req); + String resJson = post(CREATE_TEMPLATE_URL, req); return ResponseUtils.decode(resJson, TemplateIdResponse.class); } @Override public WxChannelBaseResponse deleteTemplate(String templateId) throws WxErrorException { - String resJson = shopService.post(DELETE_TEMPLATE_URL, new TemplateIdParam(templateId)); + String resJson = post(DELETE_TEMPLATE_URL, new TemplateIdParam(templateId)); return ResponseUtils.decode(resJson, WxChannelBaseResponse.class); } @Override public WxChannelBaseResponse updateTemplate(TemplateUpdateRequest req) throws WxErrorException { - String resJson = shopService.post(UPDATE_TEMPLATE_URL, req); + String resJson = post(UPDATE_TEMPLATE_URL, req); return ResponseUtils.decode(resJson, WxChannelBaseResponse.class); } @Override public TemplateInfoResponse getTemplate(String templateCode) throws WxErrorException { - String resJson = shopService.post(GET_TEMPLATE_URL, new TemplateCodeParam(templateCode)); + String resJson = post(GET_TEMPLATE_URL, new TemplateCodeParam(templateCode)); return ResponseUtils.decode(resJson, TemplateInfoResponse.class); } @Override public TemplateInfoResponse getTemplateById(String templateId) throws WxErrorException { - String resJson = shopService.post(GET_TEMPLATE_BY_ID_URL, new TemplateIdParam(templateId)); + String resJson = post(GET_TEMPLATE_BY_ID_URL, new TemplateIdParam(templateId)); return ResponseUtils.decode(resJson, TemplateInfoResponse.class); } @Override public AccountInfoResponse getAccount() throws WxErrorException { - String resJson = shopService.post(GET_ACCOUNT_URL, "{}"); + String resJson = post(GET_ACCOUNT_URL, "{}"); return ResponseUtils.decode(resJson, AccountInfoResponse.class); } @Override public DeliveryListResponse getDeliveryList() throws WxErrorException { - String resJson = shopService.post(GET_DELIVERY_LIST_URL, "{}"); + String resJson = post(GET_DELIVERY_LIST_URL, "{}"); return ResponseUtils.decode(resJson, DeliveryListResponse.class); } @Override public PreCreateResponse preCreateOrder(PreCreateRequest req) throws WxErrorException { - String resJson = shopService.post(PRE_CREATE_ORDER_URL, req); + String resJson = post(PRE_CREATE_ORDER_URL, req); return ResponseUtils.decode(resJson, PreCreateResponse.class); } @Override public CreateOrderResponse createOrder(CreateOrderRequest req) throws WxErrorException { - String resJson = shopService.post(CREATE_ORDER_URL, req); + String resJson = post(CREATE_ORDER_URL, req); return ResponseUtils.decode(resJson, CreateOrderResponse.class); } @Override public WxChannelBaseResponse addSubOrder(AddSubOrderRequest req) throws WxErrorException { - String resJson = shopService.post(ADD_SUB_ORDER_URL, req); + String resJson = post(ADD_SUB_ORDER_URL, req); return ResponseUtils.decode(resJson, WxChannelBaseResponse.class); } @Override public WxChannelBaseResponse cancelOrder(String waybillId) throws WxErrorException { - String resJson = shopService.post(CANCEL_ORDER_URL, new WaybillIdParam(waybillId)); + String resJson = post(CANCEL_ORDER_URL, new WaybillIdParam(waybillId)); return ResponseUtils.decode(resJson, WxChannelBaseResponse.class); } @Override public OrderDetailResponse getOrder(String waybillId) throws WxErrorException { - String resJson = shopService.post(GET_ORDER_URL, new WaybillIdParam(waybillId)); + String resJson = post(GET_ORDER_URL, new WaybillIdParam(waybillId)); return ResponseUtils.decode(resJson, OrderDetailResponse.class); } @Override public PrintContentResponse getPrintContent(List waybillIds, String templateId) throws WxErrorException { - String resJson = shopService.post(GET_PRINT_CONTENT_URL, new PrintContentParam(waybillIds, templateId)); + String resJson = post(GET_PRINT_CONTENT_URL, new PrintContentParam(waybillIds, templateId)); return ResponseUtils.decode(resJson, PrintContentResponse.class); } @Override public WxChannelBaseResponse printOrder(String waybillId) throws WxErrorException { - String resJson = shopService.post(PRINT_ORDER_URL, new WaybillIdParam(waybillId)); + String resJson = post(PRINT_ORDER_URL, new WaybillIdParam(waybillId)); return ResponseUtils.decode(resJson, WxChannelBaseResponse.class); } @Override public WxChannelBaseResponse batchPrintOrder(List waybillIds) throws WxErrorException { - String resJson = shopService.post(BATCH_PRINT_ORDER_URL, new WaybillIdsParam(waybillIds)); + String resJson = post(BATCH_PRINT_ORDER_URL, new WaybillIdsParam(waybillIds)); return ResponseUtils.decode(resJson, WxChannelBaseResponse.class); } + + private String post(String url, Object request) throws WxErrorException { + return shopService.executeWithoutLog( + SimplePostRequestExecutor.create(shopService), url, JsonUtils.encode(request)); + } } From e6caf70d3272464cce74803f0f1ed2e387034c87 Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Sat, 22 Aug 2026 18:32:02 +0800 Subject: [PATCH 4/4] =?UTF-8?q?fix:=20=E4=BF=AE=E6=AD=A3=E7=94=B5=E5=AD=90?= =?UTF-8?q?=E9=9D=A2=E5=8D=95=E6=89=93=E5=8D=B0=E6=8E=A5=E5=8F=A3=E5=8F=82?= =?UTF-8?q?=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../channel/api/WxChannelEwaybillService.java | 12 ++++++---- .../impl/WxChannelEwaybillServiceImpl.java | 23 +++++++++++-------- .../bean/ewaybill/BatchPrintOrderRequest.java | 12 ++++++++++ .../bean/ewaybill/EwaybillOrderIdParam.java | 14 +++++++++++ .../bean/ewaybill/PrintContentParam.java | 6 ++--- .../bean/ewaybill/PrintOrderRequest.java | 13 +++++++++++ .../bean/ewaybill/PrintContentParamTest.java | 8 +++---- 7 files changed, 65 insertions(+), 23 deletions(-) create mode 100644 weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/BatchPrintOrderRequest.java create mode 100644 weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/EwaybillOrderIdParam.java create mode 100644 weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/PrintOrderRequest.java diff --git a/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/api/WxChannelEwaybillService.java b/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/api/WxChannelEwaybillService.java index bea879040..714f75b44 100644 --- a/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/api/WxChannelEwaybillService.java +++ b/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/api/WxChannelEwaybillService.java @@ -7,6 +7,8 @@ import me.chanjar.weixin.channel.bean.ewaybill.CreateOrderRequest; import me.chanjar.weixin.channel.bean.ewaybill.CreateOrderResponse; import me.chanjar.weixin.channel.bean.ewaybill.DeliveryListResponse; +import me.chanjar.weixin.channel.bean.ewaybill.PrintOrderRequest; +import me.chanjar.weixin.channel.bean.ewaybill.BatchPrintOrderRequest; import me.chanjar.weixin.channel.bean.ewaybill.OrderDetailResponse; import me.chanjar.weixin.channel.bean.ewaybill.PreCreateRequest; import me.chanjar.weixin.channel.bean.ewaybill.PreCreateResponse; @@ -59,18 +61,18 @@ public interface WxChannelEwaybillService { WxChannelBaseResponse addSubOrder(AddSubOrderRequest req) throws WxErrorException; /** 取消电子面单下单。 @param waybillId 运单 ID @return 操作结果 @throws WxErrorException 调用失败 */ - WxChannelBaseResponse cancelOrder(String waybillId) throws WxErrorException; + WxChannelBaseResponse cancelOrder(PrintOrderRequest req) throws WxErrorException; /** 查询电子面单详情。 @param waybillId 运单 ID @return 面单详情 @throws WxErrorException 调用失败 */ - OrderDetailResponse getOrder(String waybillId) throws WxErrorException; + OrderDetailResponse getOrder(String ewaybillOrderId) throws WxErrorException; /** 获取打印报文。 @param waybillIds 运单 ID 列表 @param templateId 可选模板 ID @return 打印内容 @throws WxErrorException 调用失败 */ - PrintContentResponse getPrintContent(List waybillIds, String templateId) + PrintContentResponse getPrintContent(String ewaybillOrderId, String templateId) throws WxErrorException; /** 通知单个运单打印成功。 @param waybillId 运单 ID @return 操作结果 @throws WxErrorException 调用失败 */ - WxChannelBaseResponse printOrder(String waybillId) throws WxErrorException; + WxChannelBaseResponse printOrder(PrintOrderRequest req) throws WxErrorException; /** 批量通知运单打印成功。 @param waybillIds 运单 ID 列表 @return 操作结果 @throws WxErrorException 调用失败 */ - WxChannelBaseResponse batchPrintOrder(List waybillIds) throws WxErrorException; + WxChannelBaseResponse batchPrintOrder(BatchPrintOrderRequest req) throws WxErrorException; } diff --git a/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/api/impl/WxChannelEwaybillServiceImpl.java b/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/api/impl/WxChannelEwaybillServiceImpl.java index 195b634d6..293230585 100644 --- a/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/api/impl/WxChannelEwaybillServiceImpl.java +++ b/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/api/impl/WxChannelEwaybillServiceImpl.java @@ -25,6 +25,9 @@ import me.chanjar.weixin.channel.bean.ewaybill.CreateOrderRequest; import me.chanjar.weixin.channel.bean.ewaybill.CreateOrderResponse; import me.chanjar.weixin.channel.bean.ewaybill.DeliveryListResponse; +import me.chanjar.weixin.channel.bean.ewaybill.EwaybillOrderIdParam; +import me.chanjar.weixin.channel.bean.ewaybill.PrintOrderRequest; +import me.chanjar.weixin.channel.bean.ewaybill.BatchPrintOrderRequest; import me.chanjar.weixin.channel.bean.ewaybill.OrderDetailResponse; import me.chanjar.weixin.channel.bean.ewaybill.PreCreateRequest; import me.chanjar.weixin.channel.bean.ewaybill.PreCreateResponse; @@ -125,33 +128,33 @@ public WxChannelBaseResponse addSubOrder(AddSubOrderRequest req) throws WxErrorE } @Override - public WxChannelBaseResponse cancelOrder(String waybillId) throws WxErrorException { - String resJson = post(CANCEL_ORDER_URL, new WaybillIdParam(waybillId)); + public WxChannelBaseResponse cancelOrder(PrintOrderRequest req) throws WxErrorException { + String resJson = post(CANCEL_ORDER_URL, req); return ResponseUtils.decode(resJson, WxChannelBaseResponse.class); } @Override - public OrderDetailResponse getOrder(String waybillId) throws WxErrorException { - String resJson = post(GET_ORDER_URL, new WaybillIdParam(waybillId)); + public OrderDetailResponse getOrder(String ewaybillOrderId) throws WxErrorException { + String resJson = post(GET_ORDER_URL, new EwaybillOrderIdParam(ewaybillOrderId)); return ResponseUtils.decode(resJson, OrderDetailResponse.class); } @Override - public PrintContentResponse getPrintContent(List waybillIds, String templateId) + public PrintContentResponse getPrintContent(String ewaybillOrderId, String templateId) throws WxErrorException { - String resJson = post(GET_PRINT_CONTENT_URL, new PrintContentParam(waybillIds, templateId)); + String resJson = post(GET_PRINT_CONTENT_URL, new PrintContentParam(ewaybillOrderId, templateId)); return ResponseUtils.decode(resJson, PrintContentResponse.class); } @Override - public WxChannelBaseResponse printOrder(String waybillId) throws WxErrorException { - String resJson = post(PRINT_ORDER_URL, new WaybillIdParam(waybillId)); + public WxChannelBaseResponse printOrder(PrintOrderRequest req) throws WxErrorException { + String resJson = post(PRINT_ORDER_URL, req); return ResponseUtils.decode(resJson, WxChannelBaseResponse.class); } @Override - public WxChannelBaseResponse batchPrintOrder(List waybillIds) throws WxErrorException { - String resJson = post(BATCH_PRINT_ORDER_URL, new WaybillIdsParam(waybillIds)); + public WxChannelBaseResponse batchPrintOrder(BatchPrintOrderRequest req) throws WxErrorException { + String resJson = post(BATCH_PRINT_ORDER_URL, req); return ResponseUtils.decode(resJson, WxChannelBaseResponse.class); } diff --git a/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/BatchPrintOrderRequest.java b/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/BatchPrintOrderRequest.java new file mode 100644 index 000000000..a06d26b87 --- /dev/null +++ b/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/BatchPrintOrderRequest.java @@ -0,0 +1,12 @@ +package me.chanjar.weixin.channel.bean.ewaybill; + +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.List; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +public class BatchPrintOrderRequest { + @JsonProperty("req_list") private List reqList; +} diff --git a/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/EwaybillOrderIdParam.java b/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/EwaybillOrderIdParam.java new file mode 100644 index 000000000..81a099f9f --- /dev/null +++ b/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/EwaybillOrderIdParam.java @@ -0,0 +1,14 @@ +package me.chanjar.weixin.channel.bean.ewaybill; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class EwaybillOrderIdParam { + @JsonProperty("ewaybill_order_id") + private String ewaybillOrderId; +} diff --git a/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/PrintContentParam.java b/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/PrintContentParam.java index 8af2b7c30..3ef3e240b 100644 --- a/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/PrintContentParam.java +++ b/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/PrintContentParam.java @@ -3,7 +3,6 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import java.io.Serializable; -import java.util.List; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; @@ -15,10 +14,9 @@ public class PrintContentParam implements Serializable { private static final long serialVersionUID = 6898522842175667816L; - @JsonProperty("waybill_ids") - private List waybillIds; + @JsonProperty("ewaybill_order_id") + private String ewaybillOrderId; - @JsonInclude(JsonInclude.Include.NON_NULL) @JsonProperty("template_id") private String templateId; } diff --git a/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/PrintOrderRequest.java b/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/PrintOrderRequest.java new file mode 100644 index 000000000..14be4f62c --- /dev/null +++ b/weixin-java-channel/src/main/java/me/chanjar/weixin/channel/bean/ewaybill/PrintOrderRequest.java @@ -0,0 +1,13 @@ +package me.chanjar.weixin.channel.bean.ewaybill; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +public class PrintOrderRequest extends EwaybillOrderIdParam { + @JsonProperty("delivery_id") private String deliveryId; + @JsonProperty("waybill_id") private String waybillId; + @JsonProperty("re_print") private Boolean rePrint; +} diff --git a/weixin-java-channel/src/test/java/me/chanjar/weixin/channel/bean/ewaybill/PrintContentParamTest.java b/weixin-java-channel/src/test/java/me/chanjar/weixin/channel/bean/ewaybill/PrintContentParamTest.java index 04b489be4..9b2e23436 100644 --- a/weixin-java-channel/src/test/java/me/chanjar/weixin/channel/bean/ewaybill/PrintContentParamTest.java +++ b/weixin-java-channel/src/test/java/me/chanjar/weixin/channel/bean/ewaybill/PrintContentParamTest.java @@ -13,16 +13,16 @@ public class PrintContentParamTest { @Test public void shouldHaveNoArgsConstructor() { PrintContentParam param = new PrintContentParam(); - param.setWaybillIds(Arrays.asList("wb_1")); + param.setEwaybillOrderId("order_1"); - assertTrue(JsonUtils.encode(param).contains("\"waybill_ids\"")); + assertTrue(JsonUtils.encode(param).contains("\"ewaybill_order_id\"")); } @Test public void shouldEncodeWaybillIdsAndOptionalTemplateId() { - String json = JsonUtils.encode(new PrintContentParam(Arrays.asList("wb_1", "wb_2"), "tpl_1")); + String json = JsonUtils.encode(new PrintContentParam("order_1", "tpl_1")); - assertTrue(json.contains("\"waybill_ids\"")); + assertTrue(json.contains("\"ewaybill_order_id\"")); assertTrue(json.contains("\"template_id\":\"tpl_1\"")); assertFalse(json.contains("\"waybill_id\"")); }