Skip to content

Commit 22a6f33

Browse files
authored
feat(channel): 实现视频号小店缺失的14个商品相关API
1 parent 1be31c6 commit 22a6f33

35 files changed

Lines changed: 1504 additions & 0 deletions
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
package me.chanjar.weixin.channel.api;
2+
3+
import me.chanjar.weixin.channel.bean.base.WxChannelBaseResponse;
4+
import me.chanjar.weixin.channel.bean.gift.GiftGetResponse;
5+
import me.chanjar.weixin.channel.bean.gift.GiftProductInfo;
6+
import me.chanjar.weixin.channel.bean.gift.GiftProductListResponse;
7+
import me.chanjar.weixin.channel.bean.gift.GiftProductResponse;
8+
import me.chanjar.weixin.channel.bean.gift.GiftProductUpdateInfo;
9+
import me.chanjar.weixin.channel.bean.gift.GiftSetParam;
10+
import me.chanjar.weixin.common.error.WxErrorException;
11+
12+
/**
13+
* 视频号小店 赠品管理服务接口
14+
*
15+
* @author <a href="https://github.com/features/copilot">GitHub Copilot</a>
16+
* @see <a href="https://developers.weixin.qq.com/doc/store/shop/API/channels-shop-product/gift/api_addgiftproduct.html">赠品管理接口文档</a>
17+
*/
18+
public interface WxChannelGiftService {
19+
20+
/**
21+
* 添加非卖商品(赠品)
22+
*
23+
* @param info 赠品信息
24+
* @return GiftProductResponse
25+
* @throws WxErrorException 异常
26+
*/
27+
GiftProductResponse addGiftProduct(GiftProductInfo info) throws WxErrorException;
28+
29+
/**
30+
* 更新非卖商品(赠品)
31+
*
32+
* @param info 赠品更新信息
33+
* @return GiftProductResponse
34+
* @throws WxErrorException 异常
35+
*/
36+
GiftProductResponse updateGiftProduct(GiftProductUpdateInfo info) throws WxErrorException;
37+
38+
/**
39+
* 在售商品转赠品(设置在售商品为赠品)
40+
*
41+
* @param param 请求参数(product_id + skus 列表)
42+
* @return GiftProductListResponse
43+
* @throws WxErrorException 异常
44+
*/
45+
GiftProductListResponse setProductAsGift(GiftSetParam param) throws WxErrorException;
46+
47+
/**
48+
* 获取赠品详情
49+
*
50+
* @param productId 赠品商品ID
51+
* @param dataType 数据类型。1: 仅获取线上数据;2: 仅获取草稿数据;3: 同时获取(默认)
52+
* @return GiftGetResponse
53+
* @throws WxErrorException 异常
54+
*/
55+
GiftGetResponse getGiftProduct(String productId, Integer dataType) throws WxErrorException;
56+
57+
/**
58+
* 获取赠品列表
59+
*
60+
* @param pageSize 每页数量
61+
* @param nextKey 翻页上下文,不传默认获取第一页
62+
* @param status 赠品状态过滤
63+
* @return GiftProductListResponse
64+
* @throws WxErrorException 异常
65+
*/
66+
GiftProductListResponse listGiftProduct(Integer pageSize, String nextKey, Integer status)
67+
throws WxErrorException;
68+
69+
/**
70+
* 更新赠品库存
71+
*
72+
* @param productId 赠品商品ID
73+
* @param skuId SKU ID
74+
* @param diffType 差量类型。1: 增加;2: 减少
75+
* @param num 变更数量
76+
* @return WxChannelBaseResponse
77+
* @throws WxErrorException 异常
78+
*/
79+
WxChannelBaseResponse updateGiftStock(String productId, String skuId, Integer diffType, Integer num)
80+
throws WxErrorException;
81+
}

weixin-java-channel/src/main/java/me/chanjar/weixin/channel/api/WxChannelProductService.java

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@
66
import me.chanjar.weixin.channel.bean.limit.LimitTaskAddResponse;
77
import me.chanjar.weixin.channel.bean.limit.LimitTaskListResponse;
88
import me.chanjar.weixin.channel.bean.limit.LimitTaskParam;
9+
import me.chanjar.weixin.channel.bean.limit.LimitTaskUpdateParam;
10+
import me.chanjar.weixin.channel.bean.limit.LimitTaskUpdateResponse;
11+
import me.chanjar.weixin.channel.bean.product.CategoryPreCheckResponse;
12+
import me.chanjar.weixin.channel.bean.product.ExternalProductMappingNewParam;
13+
import me.chanjar.weixin.channel.bean.product.ExternalProductMappingNewResponse;
14+
import me.chanjar.weixin.channel.bean.product.ExternalProductMappingParam;
15+
import me.chanjar.weixin.channel.bean.product.ExternalProductMappingResponse;
16+
import me.chanjar.weixin.channel.bean.product.ProductBrandRecommendParam;
17+
import me.chanjar.weixin.channel.bean.product.ProductBrandRecommendResponse;
918
import me.chanjar.weixin.channel.bean.product.SkuStockBatchResponse;
1019
import me.chanjar.weixin.channel.bean.product.SkuStockResponse;
1120
import me.chanjar.weixin.channel.bean.product.SpuFastInfo;
@@ -14,6 +23,8 @@
1423
import me.chanjar.weixin.channel.bean.product.SpuListResponse;
1524
import me.chanjar.weixin.channel.bean.product.SpuUpdateInfo;
1625
import me.chanjar.weixin.channel.bean.product.SpuUpdateResponse;
26+
import me.chanjar.weixin.channel.bean.product.StockFlowParam;
27+
import me.chanjar.weixin.channel.bean.product.StockFlowResponse;
1728
import me.chanjar.weixin.channel.bean.product.link.ProductH5UrlResponse;
1829
import me.chanjar.weixin.channel.bean.product.link.ProductQrCodeResponse;
1930
import me.chanjar.weixin.channel.bean.product.link.ProductTagLinkResponse;
@@ -247,4 +258,80 @@ WxChannelBaseResponse updateStock(String productId, String skuId, Integer diffTy
247258
* @throws WxErrorException 异常
248259
*/
249260
WxChannelBaseResponse deleteLimitTask(String taskId) throws WxErrorException;
261+
262+
/**
263+
* 更新限时抢购任务
264+
*
265+
* @param param 更新参数
266+
* @return LimitTaskUpdateResponse
267+
* @throws WxErrorException 异常
268+
*/
269+
LimitTaskUpdateResponse updateLimitTask(LimitTaskUpdateParam param) throws WxErrorException;
270+
271+
/**
272+
* 获取库存流水
273+
*
274+
* @param param 查询参数
275+
* @return StockFlowResponse
276+
* @throws WxErrorException 异常
277+
*/
278+
StockFlowResponse getStockFlow(StockFlowParam param) throws WxErrorException;
279+
280+
/**
281+
* 发品前校验(校验当前商家是否具备在指定类目发品的资质)
282+
*
283+
* @param catId 叶子类目id
284+
* @return CategoryPreCheckResponse
285+
* @throws WxErrorException 异常
286+
*/
287+
CategoryPreCheckResponse categoryPreCheck(Long catId) throws WxErrorException;
288+
289+
/**
290+
* 商品品牌推荐(根据商品信息推荐品牌)
291+
*
292+
* @param param 请求参数
293+
* @return ProductBrandRecommendResponse
294+
* @throws WxErrorException 异常
295+
*/
296+
ProductBrandRecommendResponse getProductBrandRecommend(ProductBrandRecommendParam param)
297+
throws WxErrorException;
298+
299+
/**
300+
* 站内外商品属性映射
301+
*
302+
* @param param 请求参数
303+
* @return ExternalProductMappingResponse
304+
* @throws WxErrorException 异常
305+
*/
306+
ExternalProductMappingResponse externalProductMapping(ExternalProductMappingParam param)
307+
throws WxErrorException;
308+
309+
/**
310+
* 站内外商品属性映射(新版)
311+
*
312+
* @param param 请求参数
313+
* @return ExternalProductMappingNewResponse
314+
* @throws WxErrorException 异常
315+
*/
316+
ExternalProductMappingNewResponse externalProductMappingNew(ExternalProductMappingNewParam param)
317+
throws WxErrorException;
318+
319+
/**
320+
* 商品立即开售(结束预售)
321+
*
322+
* @param productId 商品ID
323+
* @param taskId 预售任务ID
324+
* @return WxChannelBaseResponse
325+
* @throws WxErrorException 异常
326+
*/
327+
WxChannelBaseResponse beginTimingSale(String productId, String taskId) throws WxErrorException;
328+
329+
/**
330+
* 取消商品开售(取消预售)
331+
*
332+
* @param productId 商品ID
333+
* @return WxChannelBaseResponse
334+
* @throws WxErrorException 异常
335+
*/
336+
WxChannelBaseResponse cancelTimingSale(String productId) throws WxErrorException;
250337
}

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
@@ -182,4 +182,11 @@ public interface WxChannelService extends BaseWxChannelService {
182182
*/
183183
WxChannelLiveDashboardService getLiveDashboardService();
184184

185+
/**
186+
* 赠品管理服务
187+
*
188+
* @return 赠品管理服务
189+
*/
190+
WxChannelGiftService getGiftService();
191+
185192
}

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
@@ -60,6 +60,7 @@ public abstract class BaseWxChannelServiceImpl<H, P> implements WxChannelService
6060
private WxChannelVipService vipService = null;
6161
private WxChannelCompassFinderService compassFinderService = null;
6262
private WxChannelLiveDashboardService liveDashboardService = null;
63+
private WxChannelGiftService giftService = null;
6364

6465
protected WxChannelConfig config;
6566
private int retrySleepMillis = 1000;
@@ -473,4 +474,12 @@ public synchronized WxChannelLiveDashboardService getLiveDashboardService() {
473474
return liveDashboardService;
474475
}
475476

477+
@Override
478+
public synchronized WxChannelGiftService getGiftService() {
479+
if (giftService == null) {
480+
giftService = new WxChannelGiftServiceImpl(this);
481+
}
482+
return giftService;
483+
}
484+
476485
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
package me.chanjar.weixin.channel.api.impl;
2+
3+
import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Gift.ADD_GIFT_PRODUCT_URL;
4+
import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Gift.GET_GIFT_PRODUCT_URL;
5+
import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Gift.LIST_GIFT_PRODUCT_URL;
6+
import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Gift.SET_PRODUCT_AS_GIFT_URL;
7+
import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Gift.UPDATE_GIFT_PRODUCT_URL;
8+
import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Gift.UPDATE_GIFT_STOCK_URL;
9+
10+
import lombok.extern.slf4j.Slf4j;
11+
import me.chanjar.weixin.channel.api.WxChannelGiftService;
12+
import me.chanjar.weixin.channel.bean.base.WxChannelBaseResponse;
13+
import me.chanjar.weixin.channel.bean.gift.GiftGetResponse;
14+
import me.chanjar.weixin.channel.bean.gift.GiftListParam;
15+
import me.chanjar.weixin.channel.bean.gift.GiftProductInfo;
16+
import me.chanjar.weixin.channel.bean.gift.GiftProductListResponse;
17+
import me.chanjar.weixin.channel.bean.gift.GiftProductResponse;
18+
import me.chanjar.weixin.channel.bean.gift.GiftProductUpdateInfo;
19+
import me.chanjar.weixin.channel.bean.gift.GiftSetParam;
20+
import me.chanjar.weixin.channel.util.JsonUtils;
21+
import me.chanjar.weixin.channel.util.ResponseUtils;
22+
import me.chanjar.weixin.common.error.WxErrorException;
23+
24+
/**
25+
* 视频号小店 赠品管理服务实现
26+
*
27+
* @author <a href="https://github.com/features/copilot">GitHub Copilot</a>
28+
*/
29+
@Slf4j
30+
public class WxChannelGiftServiceImpl implements WxChannelGiftService {
31+
32+
/** 微信商店服务 */
33+
private final BaseWxChannelServiceImpl<?, ?> shopService;
34+
35+
public WxChannelGiftServiceImpl(BaseWxChannelServiceImpl<?, ?> shopService) {
36+
this.shopService = shopService;
37+
}
38+
39+
@Override
40+
public GiftProductResponse addGiftProduct(GiftProductInfo info) throws WxErrorException {
41+
String reqJson = JsonUtils.encode(info);
42+
String resJson = shopService.post(ADD_GIFT_PRODUCT_URL, reqJson);
43+
return ResponseUtils.decode(resJson, GiftProductResponse.class);
44+
}
45+
46+
@Override
47+
public GiftProductResponse updateGiftProduct(GiftProductUpdateInfo info) throws WxErrorException {
48+
String reqJson = JsonUtils.encode(info);
49+
String resJson = shopService.post(UPDATE_GIFT_PRODUCT_URL, reqJson);
50+
return ResponseUtils.decode(resJson, GiftProductResponse.class);
51+
}
52+
53+
@Override
54+
public GiftProductListResponse setProductAsGift(GiftSetParam param) throws WxErrorException {
55+
String reqJson = JsonUtils.encode(param);
56+
String resJson = shopService.post(SET_PRODUCT_AS_GIFT_URL, reqJson);
57+
return ResponseUtils.decode(resJson, GiftProductListResponse.class);
58+
}
59+
60+
@Override
61+
public GiftGetResponse getGiftProduct(String productId, Integer dataType) throws WxErrorException {
62+
String reqJson = "{\"product_id\":\"" + productId + "\",\"data_type\":" + dataType + "}";
63+
String resJson = shopService.post(GET_GIFT_PRODUCT_URL, reqJson);
64+
return ResponseUtils.decode(resJson, GiftGetResponse.class);
65+
}
66+
67+
@Override
68+
public GiftProductListResponse listGiftProduct(Integer pageSize, String nextKey, Integer status)
69+
throws WxErrorException {
70+
GiftListParam param = new GiftListParam(pageSize, nextKey, status);
71+
String reqJson = JsonUtils.encode(param);
72+
String resJson = shopService.post(LIST_GIFT_PRODUCT_URL, reqJson);
73+
return ResponseUtils.decode(resJson, GiftProductListResponse.class);
74+
}
75+
76+
@Override
77+
public WxChannelBaseResponse updateGiftStock(String productId, String skuId, Integer diffType, Integer num)
78+
throws WxErrorException {
79+
String reqJson = "{\"product_id\":\"" + productId + "\",\"sku_id\":\"" + skuId
80+
+ "\",\"diff_type\":" + diffType + ",\"num\":" + num + "}";
81+
String resJson = shopService.post(UPDATE_GIFT_STOCK_URL, reqJson);
82+
return ResponseUtils.decode(resJson, WxChannelBaseResponse.class);
83+
}
84+
}

0 commit comments

Comments
 (0)