Skip to content

Commit 4393ad0

Browse files
committed
feat: 支持微信小店电子面单服务
1 parent ade05b7 commit 4393ad0

29 files changed

Lines changed: 688 additions & 0 deletions
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package me.chanjar.weixin.channel.api;
2+
3+
import java.util.List;
4+
import me.chanjar.weixin.channel.bean.base.WxChannelBaseResponse;
5+
import me.chanjar.weixin.channel.bean.ewaybill.AccountInfoResponse;
6+
import me.chanjar.weixin.channel.bean.ewaybill.AddSubOrderRequest;
7+
import me.chanjar.weixin.channel.bean.ewaybill.CreateOrderRequest;
8+
import me.chanjar.weixin.channel.bean.ewaybill.CreateOrderResponse;
9+
import me.chanjar.weixin.channel.bean.ewaybill.DeliveryListResponse;
10+
import me.chanjar.weixin.channel.bean.ewaybill.OrderDetailResponse;
11+
import me.chanjar.weixin.channel.bean.ewaybill.PreCreateRequest;
12+
import me.chanjar.weixin.channel.bean.ewaybill.PreCreateResponse;
13+
import me.chanjar.weixin.channel.bean.ewaybill.PrintContentResponse;
14+
import me.chanjar.weixin.channel.bean.ewaybill.TemplateConfigResponse;
15+
import me.chanjar.weixin.channel.bean.ewaybill.TemplateCreateRequest;
16+
import me.chanjar.weixin.channel.bean.ewaybill.TemplateIdResponse;
17+
import me.chanjar.weixin.channel.bean.ewaybill.TemplateInfoResponse;
18+
import me.chanjar.weixin.channel.bean.ewaybill.TemplateUpdateRequest;
19+
import me.chanjar.weixin.common.error.WxErrorException;
20+
21+
/**
22+
* 视频号小店电子面单服务接口
23+
*
24+
* @author GitHub Copilot
25+
*/
26+
public interface WxChannelEwaybillService {
27+
28+
TemplateConfigResponse getTemplateConfig() throws WxErrorException;
29+
30+
TemplateIdResponse createTemplate(TemplateCreateRequest req) throws WxErrorException;
31+
32+
WxChannelBaseResponse deleteTemplate(String templateId) throws WxErrorException;
33+
34+
WxChannelBaseResponse updateTemplate(TemplateUpdateRequest req) throws WxErrorException;
35+
36+
TemplateInfoResponse getTemplate(String templateCode) throws WxErrorException;
37+
38+
TemplateInfoResponse getTemplateById(String templateId) throws WxErrorException;
39+
40+
AccountInfoResponse getAccount() throws WxErrorException;
41+
42+
DeliveryListResponse getDeliveryList() throws WxErrorException;
43+
44+
PreCreateResponse preCreateOrder(PreCreateRequest req) throws WxErrorException;
45+
46+
CreateOrderResponse createOrder(CreateOrderRequest req) throws WxErrorException;
47+
48+
WxChannelBaseResponse addSubOrder(AddSubOrderRequest req) throws WxErrorException;
49+
50+
WxChannelBaseResponse cancelOrder(String waybillId) throws WxErrorException;
51+
52+
OrderDetailResponse getOrder(String waybillId) throws WxErrorException;
53+
54+
PrintContentResponse getPrintContent(List<String> waybillIds, String templateId)
55+
throws WxErrorException;
56+
57+
WxChannelBaseResponse printOrder(String waybillId) throws WxErrorException;
58+
59+
WxChannelBaseResponse batchPrintOrder(List<String> waybillIds) throws WxErrorException;
60+
}

‎weixin-java-channel/src/main/java/me/chanjar/weixin/channel/api/WxChannelService.java‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,4 +210,11 @@ public interface WxChannelService extends BaseWxChannelService {
210210
*/
211211
WxChannelFavoriteService getFavoriteService();
212212

213+
/**
214+
* 电子面单服务
215+
*
216+
* @return 电子面单服务
217+
*/
218+
WxChannelEwaybillService getEwaybillService();
219+
213220
}

‎weixin-java-channel/src/main/java/me/chanjar/weixin/channel/api/impl/BaseWxChannelServiceImpl.java‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public abstract class BaseWxChannelServiceImpl<H, P> implements WxChannelService
6464
private WxChannelQicService qicService = null;
6565
private WxTalentService talentService = null;
6666
private WxChannelFavoriteService favoriteService = null;
67+
private WxChannelEwaybillService ewaybillService = null;
6768

6869
protected WxChannelConfig config;
6970
private int retrySleepMillis = 1000;
@@ -509,4 +510,12 @@ public synchronized WxChannelFavoriteService getFavoriteService() {
509510
return favoriteService;
510511
}
511512

513+
@Override
514+
public synchronized WxChannelEwaybillService getEwaybillService() {
515+
if (ewaybillService == null) {
516+
ewaybillService = new WxChannelEwaybillServiceImpl(this);
517+
}
518+
return ewaybillService;
519+
}
520+
512521
}
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
package me.chanjar.weixin.channel.api.impl;
2+
3+
import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Ewaybill.ADD_SUB_ORDER_URL;
4+
import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Ewaybill.BATCH_PRINT_ORDER_URL;
5+
import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Ewaybill.CANCEL_ORDER_URL;
6+
import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Ewaybill.CREATE_ORDER_URL;
7+
import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Ewaybill.CREATE_TEMPLATE_URL;
8+
import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Ewaybill.DELETE_TEMPLATE_URL;
9+
import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Ewaybill.GET_ACCOUNT_URL;
10+
import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Ewaybill.GET_DELIVERY_LIST_URL;
11+
import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Ewaybill.GET_ORDER_URL;
12+
import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Ewaybill.GET_PRINT_CONTENT_URL;
13+
import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Ewaybill.GET_TEMPLATE_BY_ID_URL;
14+
import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Ewaybill.GET_TEMPLATE_CONFIG_URL;
15+
import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Ewaybill.GET_TEMPLATE_URL;
16+
import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Ewaybill.PRE_CREATE_ORDER_URL;
17+
import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Ewaybill.PRINT_ORDER_URL;
18+
import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Ewaybill.UPDATE_TEMPLATE_URL;
19+
20+
import java.util.List;
21+
import me.chanjar.weixin.channel.api.WxChannelEwaybillService;
22+
import me.chanjar.weixin.channel.bean.base.WxChannelBaseResponse;
23+
import me.chanjar.weixin.channel.bean.ewaybill.AccountInfoResponse;
24+
import me.chanjar.weixin.channel.bean.ewaybill.AddSubOrderRequest;
25+
import me.chanjar.weixin.channel.bean.ewaybill.CreateOrderRequest;
26+
import me.chanjar.weixin.channel.bean.ewaybill.CreateOrderResponse;
27+
import me.chanjar.weixin.channel.bean.ewaybill.DeliveryListResponse;
28+
import me.chanjar.weixin.channel.bean.ewaybill.OrderDetailResponse;
29+
import me.chanjar.weixin.channel.bean.ewaybill.PreCreateRequest;
30+
import me.chanjar.weixin.channel.bean.ewaybill.PreCreateResponse;
31+
import me.chanjar.weixin.channel.bean.ewaybill.PrintContentResponse;
32+
import me.chanjar.weixin.channel.bean.ewaybill.PrintContentParam;
33+
import me.chanjar.weixin.channel.bean.ewaybill.TemplateCodeParam;
34+
import me.chanjar.weixin.channel.bean.ewaybill.TemplateConfigResponse;
35+
import me.chanjar.weixin.channel.bean.ewaybill.TemplateCreateRequest;
36+
import me.chanjar.weixin.channel.bean.ewaybill.TemplateIdParam;
37+
import me.chanjar.weixin.channel.bean.ewaybill.TemplateIdResponse;
38+
import me.chanjar.weixin.channel.bean.ewaybill.TemplateInfoResponse;
39+
import me.chanjar.weixin.channel.bean.ewaybill.TemplateUpdateRequest;
40+
import me.chanjar.weixin.channel.bean.ewaybill.WaybillIdParam;
41+
import me.chanjar.weixin.channel.bean.ewaybill.WaybillIdsParam;
42+
import me.chanjar.weixin.channel.util.ResponseUtils;
43+
import me.chanjar.weixin.common.error.WxErrorException;
44+
45+
/**
46+
* 视频号小店电子面单服务实现。
47+
*
48+
* @author GitHub Copilot
49+
*/
50+
public class WxChannelEwaybillServiceImpl implements WxChannelEwaybillService {
51+
52+
/** 微信商店服务 */
53+
private final BaseWxChannelServiceImpl<?, ?> shopService;
54+
55+
public WxChannelEwaybillServiceImpl(BaseWxChannelServiceImpl<?, ?> shopService) {
56+
this.shopService = shopService;
57+
}
58+
59+
@Override
60+
public TemplateConfigResponse getTemplateConfig() throws WxErrorException {
61+
String resJson = shopService.post(GET_TEMPLATE_CONFIG_URL, "{}");
62+
return ResponseUtils.decode(resJson, TemplateConfigResponse.class);
63+
}
64+
65+
@Override
66+
public TemplateIdResponse createTemplate(TemplateCreateRequest req) throws WxErrorException {
67+
String resJson = shopService.post(CREATE_TEMPLATE_URL, req);
68+
return ResponseUtils.decode(resJson, TemplateIdResponse.class);
69+
}
70+
71+
@Override
72+
public WxChannelBaseResponse deleteTemplate(String templateId) throws WxErrorException {
73+
String resJson = shopService.post(DELETE_TEMPLATE_URL, new TemplateIdParam(templateId));
74+
return ResponseUtils.decode(resJson, WxChannelBaseResponse.class);
75+
}
76+
77+
@Override
78+
public WxChannelBaseResponse updateTemplate(TemplateUpdateRequest req) throws WxErrorException {
79+
String resJson = shopService.post(UPDATE_TEMPLATE_URL, req);
80+
return ResponseUtils.decode(resJson, WxChannelBaseResponse.class);
81+
}
82+
83+
@Override
84+
public TemplateInfoResponse getTemplate(String templateCode) throws WxErrorException {
85+
String resJson = shopService.post(GET_TEMPLATE_URL, new TemplateCodeParam(templateCode));
86+
return ResponseUtils.decode(resJson, TemplateInfoResponse.class);
87+
}
88+
89+
@Override
90+
public TemplateInfoResponse getTemplateById(String templateId) throws WxErrorException {
91+
String resJson = shopService.post(GET_TEMPLATE_BY_ID_URL, new TemplateIdParam(templateId));
92+
return ResponseUtils.decode(resJson, TemplateInfoResponse.class);
93+
}
94+
95+
@Override
96+
public AccountInfoResponse getAccount() throws WxErrorException {
97+
String resJson = shopService.post(GET_ACCOUNT_URL, "{}");
98+
return ResponseUtils.decode(resJson, AccountInfoResponse.class);
99+
}
100+
101+
@Override
102+
public DeliveryListResponse getDeliveryList() throws WxErrorException {
103+
String resJson = shopService.post(GET_DELIVERY_LIST_URL, "{}");
104+
return ResponseUtils.decode(resJson, DeliveryListResponse.class);
105+
}
106+
107+
@Override
108+
public PreCreateResponse preCreateOrder(PreCreateRequest req) throws WxErrorException {
109+
String resJson = shopService.post(PRE_CREATE_ORDER_URL, req);
110+
return ResponseUtils.decode(resJson, PreCreateResponse.class);
111+
}
112+
113+
@Override
114+
public CreateOrderResponse createOrder(CreateOrderRequest req) throws WxErrorException {
115+
String resJson = shopService.post(CREATE_ORDER_URL, req);
116+
return ResponseUtils.decode(resJson, CreateOrderResponse.class);
117+
}
118+
119+
@Override
120+
public WxChannelBaseResponse addSubOrder(AddSubOrderRequest req) throws WxErrorException {
121+
String resJson = shopService.post(ADD_SUB_ORDER_URL, req);
122+
return ResponseUtils.decode(resJson, WxChannelBaseResponse.class);
123+
}
124+
125+
@Override
126+
public WxChannelBaseResponse cancelOrder(String waybillId) throws WxErrorException {
127+
String resJson = shopService.post(CANCEL_ORDER_URL, new WaybillIdParam(waybillId));
128+
return ResponseUtils.decode(resJson, WxChannelBaseResponse.class);
129+
}
130+
131+
@Override
132+
public OrderDetailResponse getOrder(String waybillId) throws WxErrorException {
133+
String resJson = shopService.post(GET_ORDER_URL, new WaybillIdParam(waybillId));
134+
return ResponseUtils.decode(resJson, OrderDetailResponse.class);
135+
}
136+
137+
@Override
138+
public PrintContentResponse getPrintContent(List<String> waybillIds, String templateId)
139+
throws WxErrorException {
140+
String resJson = shopService.post(GET_PRINT_CONTENT_URL, new PrintContentParam(waybillIds, templateId));
141+
return ResponseUtils.decode(resJson, PrintContentResponse.class);
142+
}
143+
144+
@Override
145+
public WxChannelBaseResponse printOrder(String waybillId) throws WxErrorException {
146+
String resJson = shopService.post(PRINT_ORDER_URL, new WaybillIdParam(waybillId));
147+
return ResponseUtils.decode(resJson, WxChannelBaseResponse.class);
148+
}
149+
150+
@Override
151+
public WxChannelBaseResponse batchPrintOrder(List<String> waybillIds) throws WxErrorException {
152+
String resJson = shopService.post(BATCH_PRINT_ORDER_URL, new WaybillIdsParam(waybillIds));
153+
return ResponseUtils.decode(resJson, WxChannelBaseResponse.class);
154+
}
155+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package me.chanjar.weixin.channel.bean.ewaybill;
2+
3+
import com.fasterxml.jackson.annotation.JsonAnyGetter;
4+
import com.fasterxml.jackson.annotation.JsonAnySetter;
5+
import com.fasterxml.jackson.annotation.JsonIgnore;
6+
import java.io.Serializable;
7+
import java.util.LinkedHashMap;
8+
import java.util.Map;
9+
import lombok.Data;
10+
import lombok.NoArgsConstructor;
11+
12+
/**
13+
* 电子面单通用请求参数容器。
14+
*
15+
* <p>字段按官方文档动态透传,避免非官方字段定义。</p>
16+
*
17+
* @author GitHub Copilot
18+
*/
19+
@Data
20+
@NoArgsConstructor
21+
public abstract class AbstractEwaybillRequest implements Serializable {
22+
23+
private static final long serialVersionUID = 4213577159985597237L;
24+
25+
@JsonIgnore private Map<String, Object> params = new LinkedHashMap<>();
26+
27+
@JsonAnySetter
28+
public void addParam(String key, Object value) {
29+
params.put(key, value);
30+
}
31+
32+
@JsonAnyGetter
33+
public Map<String, Object> anyParams() {
34+
return params;
35+
}
36+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package me.chanjar.weixin.channel.bean.ewaybill;
2+
3+
import com.fasterxml.jackson.annotation.JsonAnySetter;
4+
import com.fasterxml.jackson.annotation.JsonIgnore;
5+
import java.util.LinkedHashMap;
6+
import java.util.Map;
7+
import lombok.Data;
8+
import lombok.EqualsAndHashCode;
9+
import lombok.NoArgsConstructor;
10+
import me.chanjar.weixin.channel.bean.base.WxChannelBaseResponse;
11+
12+
/**
13+
* 电子面单通用响应参数容器。
14+
*
15+
* <p>未显式声明字段将保存到 extra 字段,便于兼容官方接口变更。</p>
16+
*
17+
* @author GitHub Copilot
18+
*/
19+
@Data
20+
@NoArgsConstructor
21+
@EqualsAndHashCode(callSuper = true)
22+
public abstract class AbstractEwaybillResponse extends WxChannelBaseResponse {
23+
24+
private static final long serialVersionUID = -2460196179063989718L;
25+
26+
@JsonIgnore private Map<String, Object> extra = new LinkedHashMap<>();
27+
28+
@JsonAnySetter
29+
public void addExtra(String key, Object value) {
30+
extra.put(key, value);
31+
}
32+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package me.chanjar.weixin.channel.bean.ewaybill;
2+
3+
/**
4+
* 电子面单网点/账号信息响应。
5+
*
6+
* @author GitHub Copilot
7+
*/
8+
public class AccountInfoResponse extends AbstractEwaybillResponse {
9+
private static final long serialVersionUID = 5682783958522805959L;
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package me.chanjar.weixin.channel.bean.ewaybill;
2+
3+
/**
4+
* 电子面单子件追加请求。
5+
*
6+
* @author GitHub Copilot
7+
*/
8+
public class AddSubOrderRequest extends AbstractEwaybillRequest {
9+
private static final long serialVersionUID = 4250200603210217269L;
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package me.chanjar.weixin.channel.bean.ewaybill;
2+
3+
/**
4+
* 电子面单取号请求。
5+
*
6+
* @author GitHub Copilot
7+
*/
8+
public class CreateOrderRequest extends AbstractEwaybillRequest {
9+
private static final long serialVersionUID = 2521225918646916853L;
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package me.chanjar.weixin.channel.bean.ewaybill;
2+
3+
/**
4+
* 电子面单取号响应。
5+
*
6+
* @author GitHub Copilot
7+
*/
8+
public class CreateOrderResponse extends AbstractEwaybillResponse {
9+
private static final long serialVersionUID = 9115454170108519187L;
10+
}

0 commit comments

Comments
 (0)