Skip to content

Commit 5f9fe24

Browse files
authored
🆕 #4030 【视频号】新增微信小店赠品与买赠活动模块接口支持
1 parent 5d14948 commit 5f9fe24

12 files changed

Lines changed: 542 additions & 0 deletions

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

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@
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.product.GiftActivityAddResponse;
10+
import me.chanjar.weixin.channel.bean.product.GiftActivityInfo;
11+
import me.chanjar.weixin.channel.bean.product.GiftProductAddResponse;
12+
import me.chanjar.weixin.channel.bean.product.GiftProductGetResponse;
13+
import me.chanjar.weixin.channel.bean.product.GiftProductInfo;
14+
import me.chanjar.weixin.channel.bean.product.GiftProductListParam;
15+
import me.chanjar.weixin.channel.bean.product.GiftProductListResponse;
916
import me.chanjar.weixin.channel.bean.product.SkuStockBatchResponse;
1017
import me.chanjar.weixin.channel.bean.product.SkuStockResponse;
1118
import me.chanjar.weixin.channel.bean.product.SpuFastInfo;
@@ -206,6 +213,92 @@ WxChannelBaseResponse updateStock(String productId, String skuId, Integer diffTy
206213
*/
207214
ProductTagLinkResponse getProductTagLink(String productId) throws WxErrorException;
208215

216+
/**
217+
* 添加非卖商品
218+
*
219+
* @param info 赠品信息
220+
* @return 添加赠品响应
221+
* @throws WxErrorException 异常
222+
*/
223+
GiftProductAddResponse addGiftProduct(GiftProductInfo info) throws WxErrorException;
224+
225+
/**
226+
* 更新非卖商品
227+
*
228+
* @param info 赠品信息
229+
* @return 操作响应
230+
* @throws WxErrorException 异常
231+
*/
232+
WxChannelBaseResponse updateGiftProduct(GiftProductInfo info) throws WxErrorException;
233+
234+
/**
235+
* 在售商品转赠品
236+
*
237+
* @param productId 商品ID
238+
* @return 操作响应
239+
* @throws WxErrorException 异常
240+
*/
241+
WxChannelBaseResponse setProductAsGift(String productId) throws WxErrorException;
242+
243+
/**
244+
* 获取赠品
245+
*
246+
* @param productId 赠品商品ID
247+
* @return 赠品详情响应
248+
* @throws WxErrorException 异常
249+
*/
250+
GiftProductGetResponse getGiftProduct(String productId) throws WxErrorException;
251+
252+
/**
253+
* 获取赠品列表
254+
*
255+
* @param param 查询参数
256+
* @return 赠品列表
257+
* @throws WxErrorException 异常
258+
*/
259+
GiftProductListResponse listGiftProduct(GiftProductListParam param) throws WxErrorException;
260+
261+
/**
262+
* 更新赠品库存
263+
*
264+
* @param productId 赠品商品ID
265+
* @param skuId 赠品sku_id
266+
* @param diffType 修改类型 1增加 2减少 3设置
267+
* 建议使用1或2,不建议使用3,因为使用3在高并发场景可能会出现预期外表现
268+
* @param num 增加、减少或者设置的库存值
269+
* @return 操作响应
270+
* @throws WxErrorException 异常
271+
*/
272+
WxChannelBaseResponse updateGiftStock(String productId, String skuId, Integer diffType, Integer num)
273+
throws WxErrorException;
274+
275+
/**
276+
* 创建赠品活动
277+
*
278+
* @param info 活动信息
279+
* @return 创建赠品活动响应
280+
* @throws WxErrorException 异常
281+
*/
282+
GiftActivityAddResponse addGiftActivity(GiftActivityInfo info) throws WxErrorException;
283+
284+
/**
285+
* 删除赠品活动
286+
*
287+
* @param activityId 活动ID
288+
* @return 操作响应
289+
* @throws WxErrorException 异常
290+
*/
291+
WxChannelBaseResponse deleteGiftActivity(String activityId) throws WxErrorException;
292+
293+
/**
294+
* 停止赠品活动
295+
*
296+
* @param activityId 活动ID
297+
* @return 操作响应
298+
* @throws WxErrorException 异常
299+
*/
300+
WxChannelBaseResponse stopGiftActivity(String activityId) throws WxErrorException;
301+
209302
/**
210303
* 添加限时抢购任务
211304
*

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

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@
44
import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Spu.ADD_LIMIT_TASK_URL;
55
import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Spu.CANCEL_AUDIT_URL;
66
import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Spu.DELETE_LIMIT_TASK_URL;
7+
import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Spu.GIFT_ACTIVITY_ADD_URL;
8+
import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Spu.GIFT_ACTIVITY_DELETE_URL;
9+
import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Spu.GIFT_ACTIVITY_STOP_URL;
10+
import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Spu.GIFT_PRODUCT_ADD_URL;
11+
import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Spu.GIFT_PRODUCT_GET_URL;
12+
import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Spu.GIFT_PRODUCT_LIST_URL;
13+
import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Spu.GIFT_PRODUCT_ON_SALE_SET_URL;
14+
import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Spu.GIFT_PRODUCT_STOCK_UPDATE_URL;
15+
import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Spu.GIFT_PRODUCT_UPDATE_URL;
716
import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Spu.LIST_LIMIT_TASK_URL;
817
import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Spu.SPU_ADD_URL;
918
import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Spu.SPU_AUDIT_FREE_UPDATE_URL;
@@ -29,6 +38,14 @@
2938
import me.chanjar.weixin.channel.bean.limit.LimitTaskListParam;
3039
import me.chanjar.weixin.channel.bean.limit.LimitTaskListResponse;
3140
import me.chanjar.weixin.channel.bean.limit.LimitTaskParam;
41+
import me.chanjar.weixin.channel.bean.product.GiftActivityAddParam;
42+
import me.chanjar.weixin.channel.bean.product.GiftActivityAddResponse;
43+
import me.chanjar.weixin.channel.bean.product.GiftActivityInfo;
44+
import me.chanjar.weixin.channel.bean.product.GiftProductAddResponse;
45+
import me.chanjar.weixin.channel.bean.product.GiftProductGetResponse;
46+
import me.chanjar.weixin.channel.bean.product.GiftProductInfo;
47+
import me.chanjar.weixin.channel.bean.product.GiftProductListParam;
48+
import me.chanjar.weixin.channel.bean.product.GiftProductListResponse;
3249
import me.chanjar.weixin.channel.bean.product.SkuStockBatchParam;
3350
import me.chanjar.weixin.channel.bean.product.SkuStockBatchResponse;
3451
import me.chanjar.weixin.channel.bean.product.SkuStockParam;
@@ -211,6 +228,72 @@ public ProductTagLinkResponse getProductTagLink(String productId) throws WxError
211228
return ResponseUtils.decode(resJson, ProductTagLinkResponse.class);
212229
}
213230

231+
@Override
232+
public GiftProductAddResponse addGiftProduct(GiftProductInfo info) throws WxErrorException {
233+
String reqJson = JsonUtils.encode(info);
234+
String resJson = shopService.post(GIFT_PRODUCT_ADD_URL, reqJson);
235+
return ResponseUtils.decode(resJson, GiftProductAddResponse.class);
236+
}
237+
238+
@Override
239+
public WxChannelBaseResponse updateGiftProduct(GiftProductInfo info) throws WxErrorException {
240+
String reqJson = JsonUtils.encode(info);
241+
String resJson = shopService.post(GIFT_PRODUCT_UPDATE_URL, reqJson);
242+
return ResponseUtils.decode(resJson, WxChannelBaseResponse.class);
243+
}
244+
245+
@Override
246+
public WxChannelBaseResponse setProductAsGift(String productId) throws WxErrorException {
247+
String reqJson = "{\"product_id\":\"" + productId + "\"}";
248+
String resJson = shopService.post(GIFT_PRODUCT_ON_SALE_SET_URL, reqJson);
249+
return ResponseUtils.decode(resJson, WxChannelBaseResponse.class);
250+
}
251+
252+
@Override
253+
public GiftProductGetResponse getGiftProduct(String productId) throws WxErrorException {
254+
String reqJson = "{\"product_id\":\"" + productId + "\"}";
255+
String resJson = shopService.post(GIFT_PRODUCT_GET_URL, reqJson);
256+
return ResponseUtils.decode(resJson, GiftProductGetResponse.class);
257+
}
258+
259+
@Override
260+
public GiftProductListResponse listGiftProduct(GiftProductListParam param) throws WxErrorException {
261+
String reqJson = JsonUtils.encode(param);
262+
String resJson = shopService.post(GIFT_PRODUCT_LIST_URL, reqJson);
263+
return ResponseUtils.decode(resJson, GiftProductListResponse.class);
264+
}
265+
266+
@Override
267+
public WxChannelBaseResponse updateGiftStock(String productId, String skuId, Integer diffType, Integer num)
268+
throws WxErrorException {
269+
SkuStockParam param = new SkuStockParam(productId, skuId, diffType, num);
270+
String reqJson = JsonUtils.encode(param);
271+
String resJson = shopService.post(GIFT_PRODUCT_STOCK_UPDATE_URL, reqJson);
272+
return ResponseUtils.decode(resJson, WxChannelBaseResponse.class);
273+
}
274+
275+
@Override
276+
public GiftActivityAddResponse addGiftActivity(GiftActivityInfo info) throws WxErrorException {
277+
GiftActivityAddParam param = new GiftActivityAddParam(info);
278+
String reqJson = JsonUtils.encode(param);
279+
String resJson = shopService.post(GIFT_ACTIVITY_ADD_URL, reqJson);
280+
return ResponseUtils.decode(resJson, GiftActivityAddResponse.class);
281+
}
282+
283+
@Override
284+
public WxChannelBaseResponse deleteGiftActivity(String activityId) throws WxErrorException {
285+
String reqJson = "{\"activity_id\":\"" + activityId + "\"}";
286+
String resJson = shopService.post(GIFT_ACTIVITY_DELETE_URL, reqJson);
287+
return ResponseUtils.decode(resJson, WxChannelBaseResponse.class);
288+
}
289+
290+
@Override
291+
public WxChannelBaseResponse stopGiftActivity(String activityId) throws WxErrorException {
292+
String reqJson = "{\"activity_id\":\"" + activityId + "\"}";
293+
String resJson = shopService.post(GIFT_ACTIVITY_STOP_URL, reqJson);
294+
return ResponseUtils.decode(resJson, WxChannelBaseResponse.class);
295+
}
296+
214297
@Override
215298
public LimitTaskAddResponse addLimitTask(LimitTaskParam param) throws WxErrorException {
216299
String reqJson = JsonUtils.encode(param);
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package me.chanjar.weixin.channel.bean.product;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
import java.io.Serializable;
5+
import lombok.AllArgsConstructor;
6+
import lombok.Data;
7+
import lombok.NoArgsConstructor;
8+
9+
/**
10+
* 创建买赠活动参数
11+
*
12+
* @author GitHub Copilot
13+
*/
14+
@Data
15+
@NoArgsConstructor
16+
@AllArgsConstructor
17+
public class GiftActivityAddParam implements Serializable {
18+
19+
private static final long serialVersionUID = -3332952823917162308L;
20+
21+
@JsonProperty("gift_activity")
22+
private GiftActivityInfo giftActivity;
23+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package me.chanjar.weixin.channel.bean.product;
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 GitHub Copilot
13+
*/
14+
@Data
15+
@NoArgsConstructor
16+
@EqualsAndHashCode(callSuper = true)
17+
public class GiftActivityAddResponse extends WxChannelBaseResponse {
18+
19+
private static final long serialVersionUID = -4527079816331082871L;
20+
21+
@JsonProperty("activity_id")
22+
private String activityId;
23+
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
package me.chanjar.weixin.channel.bean.product;
2+
3+
import com.fasterxml.jackson.annotation.JsonInclude;
4+
import com.fasterxml.jackson.annotation.JsonProperty;
5+
import java.io.Serializable;
6+
import java.util.List;
7+
import lombok.Data;
8+
9+
/**
10+
* 买赠活动信息
11+
*
12+
* @author GitHub Copilot
13+
*/
14+
@Data
15+
@JsonInclude(JsonInclude.Include.NON_NULL)
16+
public class GiftActivityInfo implements Serializable {
17+
18+
private static final long serialVersionUID = 3970308144375119175L;
19+
20+
@JsonProperty("activity_id")
21+
private String activityId;
22+
23+
@JsonProperty("title")
24+
private String title;
25+
26+
@JsonProperty("start_time")
27+
private Long startTime;
28+
29+
@JsonProperty("end_time")
30+
private Long endTime;
31+
32+
@JsonProperty("detail")
33+
private Detail detail;
34+
35+
@Data
36+
public static class Detail implements Serializable {
37+
private static final long serialVersionUID = 1019081831733485084L;
38+
39+
@JsonProperty("show_scene")
40+
private Integer showScene;
41+
42+
@JsonProperty("receive_limit")
43+
private ReceiveLimit receiveLimit;
44+
45+
@JsonProperty("main_products")
46+
private List<MainProduct> mainProducts;
47+
48+
@JsonProperty("gift_set")
49+
private GiftSet giftSet;
50+
}
51+
52+
@Data
53+
public static class ReceiveLimit implements Serializable {
54+
private static final long serialVersionUID = 3332293571373311829L;
55+
56+
@JsonProperty("is_limited")
57+
private Boolean limited;
58+
59+
@JsonProperty("limit_num")
60+
private Integer limitNum;
61+
}
62+
63+
@Data
64+
public static class MainProduct implements Serializable {
65+
private static final long serialVersionUID = 6368866030784193437L;
66+
67+
@JsonProperty("product_id")
68+
private String productId;
69+
}
70+
71+
@Data
72+
public static class GiftSet implements Serializable {
73+
private static final long serialVersionUID = 8473755235926932739L;
74+
75+
@JsonProperty("gift_items")
76+
private List<GiftItem> giftItems;
77+
78+
@JsonProperty("gift_set_num")
79+
private Integer giftSetNum;
80+
}
81+
82+
@Data
83+
public static class GiftItem implements Serializable {
84+
private static final long serialVersionUID = -4130391476834450014L;
85+
86+
@JsonProperty("gift_id")
87+
private String giftId;
88+
89+
@JsonProperty("give_num")
90+
private Integer giveNum;
91+
}
92+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package me.chanjar.weixin.channel.bean.product;
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 GitHub Copilot
13+
*/
14+
@Data
15+
@NoArgsConstructor
16+
@EqualsAndHashCode(callSuper = true)
17+
public class GiftProductAddResponse extends WxChannelBaseResponse {
18+
19+
private static final long serialVersionUID = -5971026809157610975L;
20+
21+
/** 赠品商品ID */
22+
@JsonProperty("product_id")
23+
private String productId;
24+
}

0 commit comments

Comments
 (0)