Skip to content

Commit 6d58434

Browse files
authored
🆕 #4031 【视频号】新增微信小店代发管理模块:Supplier 关联、自动分配与 Dropship 单据等接口支持
1 parent 732d4b1 commit 6d58434

19 files changed

Lines changed: 684 additions & 0 deletions

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
@@ -119,6 +119,13 @@ public interface WxChannelService extends BaseWxChannelService {
119119
*/
120120
WxLeagueWindowService getLeagueWindowService();
121121

122+
/**
123+
* 代发管理服务
124+
*
125+
* @return 代发管理服务
126+
*/
127+
WxChannelSupplierService getSupplierService();
128+
122129
/**
123130
* 优选联盟-团长服务
124131
*
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package me.chanjar.weixin.channel.api;
2+
3+
import me.chanjar.weixin.channel.bean.base.WxChannelBaseResponse;
4+
import me.chanjar.weixin.channel.bean.supplier.DistributeTypeResponse;
5+
import me.chanjar.weixin.channel.bean.supplier.DropshipAssignRequest;
6+
import me.chanjar.weixin.channel.bean.supplier.DropshipDetailResponse;
7+
import me.chanjar.weixin.channel.bean.supplier.DropshipListRequest;
8+
import me.chanjar.weixin.channel.bean.supplier.DropshipListResponse;
9+
import me.chanjar.weixin.channel.bean.supplier.DropshipResponse;
10+
import me.chanjar.weixin.channel.bean.supplier.DropshipSearchRequest;
11+
import me.chanjar.weixin.channel.bean.supplier.ProductDistributeRequest;
12+
import me.chanjar.weixin.channel.bean.supplier.ProductListResponse;
13+
import me.chanjar.weixin.channel.bean.supplier.SupplierInfoResponse;
14+
import me.chanjar.weixin.channel.bean.supplier.SupplierListResponse;
15+
import me.chanjar.weixin.common.error.WxErrorException;
16+
17+
/**
18+
* 视频号小店代发管理服务。
19+
*
20+
* @author <a href="https://github.com/github-copilot">GitHub Copilot</a>
21+
* @see <a href="https://developers.weixin.qq.com/doc/channels/API/supplier/">代发管理接口文档</a>
22+
*/
23+
public interface WxChannelSupplierService {
24+
25+
/** 获取供货商列表。 */
26+
SupplierListResponse getSupplierList() throws WxErrorException;
27+
28+
/**
29+
* 获取供货商列表。
30+
*
31+
* @param pageSize 每页数量
32+
* @param nextKey 由上次请求返回,记录翻页的上下文。传入时会从上次返回的结果往后翻一页
33+
* @return 供货商列表响应
34+
* @throws WxErrorException 异常
35+
*/
36+
SupplierListResponse getSupplierList(Integer pageSize, String nextKey) throws WxErrorException;
37+
38+
/** 获取分配方式。 */
39+
DistributeTypeResponse getDistribute() throws WxErrorException;
40+
41+
/** 设置全店订单手动分配。 */
42+
WxChannelBaseResponse setManuallyDistribute() throws WxErrorException;
43+
44+
/** 设置全店订单自动分配。 */
45+
WxChannelBaseResponse setAllDistribute(String supplierId) throws WxErrorException;
46+
47+
/** 设置按商品自动分配。 */
48+
WxChannelBaseResponse setProductDistribute(ProductDistributeRequest req) throws WxErrorException;
49+
50+
/** 获取商品对应的自动分配供货商。 */
51+
SupplierInfoResponse getProductDefaultDistribute(String productId) throws WxErrorException;
52+
53+
/** 获取按商品自动分配的商品列表。 */
54+
ProductListResponse getProductList(String supplierId) throws WxErrorException;
55+
56+
/** 分配订单代发。 */
57+
DropshipResponse assignOrder(DropshipAssignRequest req) throws WxErrorException;
58+
59+
/** 取消分配代发单。 */
60+
WxChannelBaseResponse cancelDropship(String orderId) throws WxErrorException;
61+
62+
/** 查询代发单详情。 */
63+
DropshipDetailResponse getDropship(String orderId) throws WxErrorException;
64+
65+
/** 拉取代发单列表。 */
66+
DropshipListResponse listDropship(DropshipListRequest req) throws WxErrorException;
67+
68+
/** 搜索代发单。 */
69+
DropshipListResponse searchDropship(DropshipSearchRequest req) throws WxErrorException;
70+
}

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
@@ -50,6 +50,7 @@ public abstract class BaseWxChannelServiceImpl<H, P> implements WxChannelService
5050
private WxStoreHomePageService homePageService = null;
5151
private WxStoreCooperationService cooperationService = null;
5252
private WxChannelCompassShopService compassShopService = null;
53+
private WxChannelSupplierService supplierService = null;
5354
private WxLeagueWindowService leagueWindowService = null;
5455
private WxLeagueSupplierService leagueSupplierService = null;
5556
private WxLeaguePromoterService leaguePromoterService = null;
@@ -395,6 +396,14 @@ public synchronized WxChannelCompassShopService getCompassShopService() {
395396
return compassShopService;
396397
}
397398

399+
@Override
400+
public synchronized WxChannelSupplierService getSupplierService() {
401+
if (supplierService == null) {
402+
supplierService = new WxChannelSupplierServiceImpl(this);
403+
}
404+
return supplierService;
405+
}
406+
398407
@Override
399408
public synchronized WxLeagueWindowService getLeagueWindowService() {
400409
if (leagueWindowService == null) {
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
package me.chanjar.weixin.channel.api.impl;
2+
3+
import com.google.gson.JsonObject;
4+
import lombok.extern.slf4j.Slf4j;
5+
import me.chanjar.weixin.channel.api.WxChannelSupplierService;
6+
import me.chanjar.weixin.channel.bean.base.StreamPageParam;
7+
import me.chanjar.weixin.channel.bean.base.WxChannelBaseResponse;
8+
import me.chanjar.weixin.channel.bean.supplier.DistributeTypeResponse;
9+
import me.chanjar.weixin.channel.bean.supplier.DropshipAssignRequest;
10+
import me.chanjar.weixin.channel.bean.supplier.DropshipDetailResponse;
11+
import me.chanjar.weixin.channel.bean.supplier.DropshipListRequest;
12+
import me.chanjar.weixin.channel.bean.supplier.DropshipListResponse;
13+
import me.chanjar.weixin.channel.bean.supplier.DropshipResponse;
14+
import me.chanjar.weixin.channel.bean.supplier.DropshipSearchRequest;
15+
import me.chanjar.weixin.channel.bean.supplier.ProductDistributeRequest;
16+
import me.chanjar.weixin.channel.bean.supplier.ProductListResponse;
17+
import me.chanjar.weixin.channel.bean.supplier.SupplierInfoResponse;
18+
import me.chanjar.weixin.channel.bean.supplier.SupplierListResponse;
19+
import me.chanjar.weixin.channel.util.ResponseUtils;
20+
import me.chanjar.weixin.common.error.WxErrorException;
21+
import me.chanjar.weixin.common.util.json.GsonHelper;
22+
23+
import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Supplier.ASSIGN_DROPSHIP_URL;
24+
import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Supplier.CANCEL_DROPSHIP_URL;
25+
import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Supplier.GET_DISTRIBUTE_URL;
26+
import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Supplier.GET_DROPSHIP_LIST_URL;
27+
import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Supplier.GET_DROPSHIP_URL;
28+
import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Supplier.GET_PRODUCT_DEFAULT_DISTRIBUTE_URL;
29+
import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Supplier.GET_PRODUCT_LIST_URL;
30+
import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Supplier.GET_SUPPLIER_LIST_URL;
31+
import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Supplier.SEARCH_DROPSHIP_URL;
32+
import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Supplier.SET_ALL_DISTRIBUTION_URL;
33+
import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Supplier.SET_MANUALLY_DISTRIBUTE_URL;
34+
import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Supplier.SET_PRODUCT_DISTRIBUTE_URL;
35+
36+
/**
37+
* 视频号小店代发管理服务。
38+
*
39+
* @author <a href="https://github.com/github-copilot">GitHub Copilot</a>
40+
*/
41+
@Slf4j
42+
public class WxChannelSupplierServiceImpl implements WxChannelSupplierService {
43+
44+
private final BaseWxChannelServiceImpl<?, ?> shopService;
45+
46+
public WxChannelSupplierServiceImpl(BaseWxChannelServiceImpl<?, ?> shopService) {
47+
this.shopService = shopService;
48+
}
49+
50+
@Override
51+
public SupplierListResponse getSupplierList() throws WxErrorException {
52+
return getSupplierList(null, null);
53+
}
54+
55+
@Override
56+
public SupplierListResponse getSupplierList(Integer pageSize, String nextKey) throws WxErrorException {
57+
StreamPageParam param = new StreamPageParam(pageSize, nextKey);
58+
String respJson = shopService.post(GET_SUPPLIER_LIST_URL, param);
59+
return ResponseUtils.decode(respJson, SupplierListResponse.class);
60+
}
61+
62+
@Override
63+
public DistributeTypeResponse getDistribute() throws WxErrorException {
64+
String respJson = shopService.post(GET_DISTRIBUTE_URL, "{}");
65+
return ResponseUtils.decode(respJson, DistributeTypeResponse.class);
66+
}
67+
68+
@Override
69+
public WxChannelBaseResponse setManuallyDistribute() throws WxErrorException {
70+
String respJson = shopService.post(SET_MANUALLY_DISTRIBUTE_URL, "{}");
71+
return ResponseUtils.decode(respJson, WxChannelBaseResponse.class);
72+
}
73+
74+
@Override
75+
public WxChannelBaseResponse setAllDistribute(String supplierId) throws WxErrorException {
76+
JsonObject req = GsonHelper.buildJsonObject("supplier_id", supplierId);
77+
String respJson = shopService.post(SET_ALL_DISTRIBUTION_URL, req);
78+
return ResponseUtils.decode(respJson, WxChannelBaseResponse.class);
79+
}
80+
81+
@Override
82+
public WxChannelBaseResponse setProductDistribute(ProductDistributeRequest req) throws WxErrorException {
83+
String respJson = shopService.post(SET_PRODUCT_DISTRIBUTE_URL, req);
84+
return ResponseUtils.decode(respJson, WxChannelBaseResponse.class);
85+
}
86+
87+
@Override
88+
public SupplierInfoResponse getProductDefaultDistribute(String productId) throws WxErrorException {
89+
JsonObject req = GsonHelper.buildJsonObject("product_id", productId);
90+
String respJson = shopService.post(GET_PRODUCT_DEFAULT_DISTRIBUTE_URL, req);
91+
return ResponseUtils.decode(respJson, SupplierInfoResponse.class);
92+
}
93+
94+
@Override
95+
public ProductListResponse getProductList(String supplierId) throws WxErrorException {
96+
JsonObject req = GsonHelper.buildJsonObject("supplier_id", supplierId);
97+
String respJson = shopService.post(GET_PRODUCT_LIST_URL, req);
98+
return ResponseUtils.decode(respJson, ProductListResponse.class);
99+
}
100+
101+
@Override
102+
public DropshipResponse assignOrder(DropshipAssignRequest req) throws WxErrorException {
103+
String respJson = shopService.post(ASSIGN_DROPSHIP_URL, req);
104+
return ResponseUtils.decode(respJson, DropshipResponse.class);
105+
}
106+
107+
@Override
108+
public WxChannelBaseResponse cancelDropship(String orderId) throws WxErrorException {
109+
JsonObject req = GsonHelper.buildJsonObject("order_id", orderId);
110+
String respJson = shopService.post(CANCEL_DROPSHIP_URL, req);
111+
return ResponseUtils.decode(respJson, WxChannelBaseResponse.class);
112+
}
113+
114+
@Override
115+
public DropshipDetailResponse getDropship(String orderId) throws WxErrorException {
116+
JsonObject req = GsonHelper.buildJsonObject("order_id", orderId);
117+
String respJson = shopService.post(GET_DROPSHIP_URL, req);
118+
return ResponseUtils.decode(respJson, DropshipDetailResponse.class);
119+
}
120+
121+
@Override
122+
public DropshipListResponse listDropship(DropshipListRequest req) throws WxErrorException {
123+
String respJson = shopService.post(GET_DROPSHIP_LIST_URL, req);
124+
return ResponseUtils.decode(respJson, DropshipListResponse.class);
125+
}
126+
127+
@Override
128+
public DropshipListResponse searchDropship(DropshipSearchRequest req) throws WxErrorException {
129+
String respJson = shopService.post(SEARCH_DROPSHIP_URL, req);
130+
return ResponseUtils.decode(respJson, DropshipListResponse.class);
131+
}
132+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package me.chanjar.weixin.channel.bean.supplier;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
import lombok.Data;
5+
import lombok.EqualsAndHashCode;
6+
import lombok.NoArgsConstructor;
7+
import me.chanjar.weixin.channel.bean.base.WxChannelBaseResponse;
8+
9+
/**
10+
* 分配方式响应。
11+
*
12+
* @author <a href="https://github.com/github-copilot">GitHub Copilot</a>
13+
*/
14+
@Data
15+
@NoArgsConstructor
16+
@EqualsAndHashCode(callSuper = true)
17+
public class DistributeTypeResponse extends WxChannelBaseResponse {
18+
private static final long serialVersionUID = -750860556286328053L;
19+
20+
@JsonProperty("distribute_type")
21+
private Integer distributeType;
22+
23+
@JsonProperty("supplier_info")
24+
private SupplierInfo supplierInfo;
25+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package me.chanjar.weixin.channel.bean.supplier;
2+
3+
import com.fasterxml.jackson.annotation.JsonInclude;
4+
import com.fasterxml.jackson.annotation.JsonProperty;
5+
import java.io.Serializable;
6+
import lombok.Data;
7+
import lombok.NoArgsConstructor;
8+
9+
/**
10+
* 代发单分配请求。
11+
*
12+
* @author <a href="https://github.com/github-copilot">GitHub Copilot</a>
13+
*/
14+
@Data
15+
@NoArgsConstructor
16+
@JsonInclude(JsonInclude.Include.NON_NULL)
17+
public class DropshipAssignRequest implements Serializable {
18+
private static final long serialVersionUID = 6945436332042017565L;
19+
20+
@JsonProperty("order_id")
21+
private String orderId;
22+
23+
@JsonProperty("supplier_id")
24+
private String supplierId;
25+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package me.chanjar.weixin.channel.bean.supplier;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
import lombok.Data;
5+
import lombok.EqualsAndHashCode;
6+
import lombok.NoArgsConstructor;
7+
import me.chanjar.weixin.channel.bean.base.WxChannelBaseResponse;
8+
9+
/**
10+
* 代发单详情响应。
11+
*
12+
* @author <a href="https://github.com/github-copilot">GitHub Copilot</a>
13+
*/
14+
@Data
15+
@NoArgsConstructor
16+
@EqualsAndHashCode(callSuper = true)
17+
public class DropshipDetailResponse extends WxChannelBaseResponse {
18+
private static final long serialVersionUID = 5548774863400272707L;
19+
20+
@JsonProperty("dropship_info")
21+
private DropshipInfo dropshipInfo;
22+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package me.chanjar.weixin.channel.bean.supplier;
2+
3+
import com.fasterxml.jackson.annotation.JsonInclude;
4+
import com.fasterxml.jackson.annotation.JsonProperty;
5+
import java.io.Serializable;
6+
import lombok.Data;
7+
import lombok.NoArgsConstructor;
8+
9+
/**
10+
* 代发单信息。
11+
*
12+
* @author <a href="https://github.com/github-copilot">GitHub Copilot</a>
13+
*/
14+
@Data
15+
@NoArgsConstructor
16+
@JsonInclude(JsonInclude.Include.NON_NULL)
17+
public class DropshipInfo implements Serializable {
18+
private static final long serialVersionUID = -7880364210849039278L;
19+
20+
@JsonProperty("order_id")
21+
private String orderId;
22+
23+
@JsonProperty("supplier_id")
24+
private String supplierId;
25+
26+
@JsonProperty("ds_order_id")
27+
private String dropshipId;
28+
29+
@JsonProperty("status")
30+
private Integer status;
31+
32+
@JsonProperty("create_time")
33+
private Long createTime;
34+
35+
@JsonProperty("update_time")
36+
private Long updateTime;
37+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package me.chanjar.weixin.channel.bean.supplier;
2+
3+
import com.fasterxml.jackson.annotation.JsonInclude;
4+
import com.fasterxml.jackson.annotation.JsonProperty;
5+
import java.io.Serializable;
6+
import lombok.Data;
7+
import lombok.NoArgsConstructor;
8+
9+
/**
10+
* 代发单列表请求。
11+
*
12+
* @author <a href="https://github.com/github-copilot">GitHub Copilot</a>
13+
*/
14+
@Data
15+
@NoArgsConstructor
16+
@JsonInclude(JsonInclude.Include.NON_NULL)
17+
public class DropshipListRequest implements Serializable {
18+
private static final long serialVersionUID = 2638071229335192596L;
19+
20+
@JsonProperty("supplier_id")
21+
private String supplierId;
22+
23+
@JsonProperty("status")
24+
private Integer status;
25+
26+
@JsonProperty("create_time_start")
27+
private Long createTimeStart;
28+
29+
@JsonProperty("create_time_end")
30+
private Long createTimeEnd;
31+
32+
@JsonProperty("page_size")
33+
private Integer pageSize;
34+
35+
@JsonProperty("next_key")
36+
private String nextKey;
37+
}

0 commit comments

Comments
 (0)