Skip to content

Commit 5fabd7c

Browse files
authored
新增微信小店赠品与买赠活动接口支持
1 parent 2978a7a commit 5fabd7c

12 files changed

Lines changed: 517 additions & 0 deletions

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

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
import me.chanjar.weixin.channel.bean.product.SkuStockResponse;
1111
import me.chanjar.weixin.channel.bean.product.SpuFastInfo;
1212
import me.chanjar.weixin.channel.bean.product.SpuGetResponse;
13+
import me.chanjar.weixin.channel.bean.product.GiftActivityInfo;
14+
import me.chanjar.weixin.channel.bean.product.GiftProductInfo;
15+
import me.chanjar.weixin.channel.bean.product.GiftProductListParam;
16+
import me.chanjar.weixin.channel.bean.product.GiftProductListResponse;
1317
import me.chanjar.weixin.channel.bean.product.SpuInfo;
1418
import me.chanjar.weixin.channel.bean.product.SpuListResponse;
1519
import me.chanjar.weixin.channel.bean.product.SpuUpdateInfo;
@@ -206,6 +210,84 @@ WxChannelBaseResponse updateStock(String productId, String skuId, Integer diffTy
206210
*/
207211
ProductTagLinkResponse getProductTagLink(String productId) throws WxErrorException;
208212

213+
/**
214+
* 添加非卖商品
215+
*
216+
* @param info 赠品信息
217+
* @return 赠品商品ID
218+
* @throws WxErrorException 异常
219+
*/
220+
String addGiftProduct(GiftProductInfo info) throws WxErrorException;
221+
222+
/**
223+
* 更新非卖商品
224+
*
225+
* @param info 赠品信息
226+
* @throws WxErrorException 异常
227+
*/
228+
void updateGiftProduct(GiftProductInfo info) throws WxErrorException;
229+
230+
/**
231+
* 在售商品转赠品
232+
*
233+
* @param productId 商品ID
234+
* @throws WxErrorException 异常
235+
*/
236+
void setProductAsGift(String productId) throws WxErrorException;
237+
238+
/**
239+
* 获取赠品
240+
*
241+
* @param productId 赠品商品ID
242+
* @return 赠品信息
243+
* @throws WxErrorException 异常
244+
*/
245+
GiftProductInfo getGiftProduct(String productId) throws WxErrorException;
246+
247+
/**
248+
* 获取赠品列表
249+
*
250+
* @param param 查询参数
251+
* @return 赠品列表
252+
* @throws WxErrorException 异常
253+
*/
254+
GiftProductListResponse listGiftProduct(GiftProductListParam param) throws WxErrorException;
255+
256+
/**
257+
* 更新赠品库存
258+
*
259+
* @param productId 赠品商品ID
260+
* @param skuId 赠品sku_id
261+
* @param stock 库存值
262+
* @throws WxErrorException 异常
263+
*/
264+
void updateGiftStock(String productId, String skuId, Integer stock) throws WxErrorException;
265+
266+
/**
267+
* 创建赠品活动
268+
*
269+
* @param info 活动信息
270+
* @return 活动ID
271+
* @throws WxErrorException 异常
272+
*/
273+
String addGiftActivity(GiftActivityInfo info) throws WxErrorException;
274+
275+
/**
276+
* 删除赠品活动
277+
*
278+
* @param activityId 活动ID
279+
* @throws WxErrorException 异常
280+
*/
281+
void deleteGiftActivity(String activityId) throws WxErrorException;
282+
283+
/**
284+
* 停止赠品活动
285+
*
286+
* @param activityId 活动ID
287+
* @throws WxErrorException 异常
288+
*/
289+
void stopGiftActivity(String activityId) throws WxErrorException;
290+
209291
/**
210292
* 添加限时抢购任务
211293
*

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

Lines changed: 85 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,74 @@ public ProductTagLinkResponse getProductTagLink(String productId) throws WxError
211228
return ResponseUtils.decode(resJson, ProductTagLinkResponse.class);
212229
}
213230

231+
@Override
232+
public String addGiftProduct(GiftProductInfo info) throws WxErrorException {
233+
String reqJson = JsonUtils.encode(info);
234+
String resJson = shopService.post(GIFT_PRODUCT_ADD_URL, reqJson);
235+
GiftProductAddResponse response = ResponseUtils.decode(resJson, GiftProductAddResponse.class);
236+
return response.getProductId();
237+
}
238+
239+
@Override
240+
public void updateGiftProduct(GiftProductInfo info) throws WxErrorException {
241+
String reqJson = JsonUtils.encode(info);
242+
String resJson = shopService.post(GIFT_PRODUCT_UPDATE_URL, reqJson);
243+
ResponseUtils.decode(resJson, WxChannelBaseResponse.class);
244+
}
245+
246+
@Override
247+
public void setProductAsGift(String productId) throws WxErrorException {
248+
String reqJson = "{\"product_id\":\"" + productId + "\"}";
249+
String resJson = shopService.post(GIFT_PRODUCT_ON_SALE_SET_URL, reqJson);
250+
ResponseUtils.decode(resJson, WxChannelBaseResponse.class);
251+
}
252+
253+
@Override
254+
public GiftProductInfo getGiftProduct(String productId) throws WxErrorException {
255+
String reqJson = "{\"product_id\":\"" + productId + "\"}";
256+
String resJson = shopService.post(GIFT_PRODUCT_GET_URL, reqJson);
257+
GiftProductGetResponse response = ResponseUtils.decode(resJson, GiftProductGetResponse.class);
258+
return response.getProduct() != null ? response.getProduct() : response.getEditProduct();
259+
}
260+
261+
@Override
262+
public GiftProductListResponse listGiftProduct(GiftProductListParam param) throws WxErrorException {
263+
String reqJson = JsonUtils.encode(param);
264+
String resJson = shopService.post(GIFT_PRODUCT_LIST_URL, reqJson);
265+
return ResponseUtils.decode(resJson, GiftProductListResponse.class);
266+
}
267+
268+
@Override
269+
public void updateGiftStock(String productId, String skuId, Integer stock) throws WxErrorException {
270+
SkuStockParam param = new SkuStockParam(productId, skuId, 3, stock);
271+
String reqJson = JsonUtils.encode(param);
272+
String resJson = shopService.post(GIFT_PRODUCT_STOCK_UPDATE_URL, reqJson);
273+
ResponseUtils.decode(resJson, WxChannelBaseResponse.class);
274+
}
275+
276+
@Override
277+
public String addGiftActivity(GiftActivityInfo info) throws WxErrorException {
278+
GiftActivityAddParam param = new GiftActivityAddParam(info);
279+
String reqJson = JsonUtils.encode(param);
280+
String resJson = shopService.post(GIFT_ACTIVITY_ADD_URL, reqJson);
281+
GiftActivityAddResponse response = ResponseUtils.decode(resJson, GiftActivityAddResponse.class);
282+
return response.getActivityId();
283+
}
284+
285+
@Override
286+
public void deleteGiftActivity(String activityId) throws WxErrorException {
287+
String reqJson = "{\"activity_id\":\"" + activityId + "\"}";
288+
String resJson = shopService.post(GIFT_ACTIVITY_DELETE_URL, reqJson);
289+
ResponseUtils.decode(resJson, WxChannelBaseResponse.class);
290+
}
291+
292+
@Override
293+
public void stopGiftActivity(String activityId) throws WxErrorException {
294+
String reqJson = "{\"activity_id\":\"" + activityId + "\"}";
295+
String resJson = shopService.post(GIFT_ACTIVITY_STOP_URL, reqJson);
296+
ResponseUtils.decode(resJson, WxChannelBaseResponse.class);
297+
}
298+
214299
@Override
215300
public LimitTaskAddResponse addLimitTask(LimitTaskParam param) throws WxErrorException {
216301
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+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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 GiftProductGetResponse extends WxChannelBaseResponse {
18+
19+
private static final long serialVersionUID = 5331169221157446692L;
20+
21+
/** 赠品线上数据 */
22+
@JsonProperty("product")
23+
private GiftProductInfo product;
24+
25+
/** 赠品草稿数据 */
26+
@JsonProperty("edit_product")
27+
private GiftProductInfo editProduct;
28+
}

0 commit comments

Comments
 (0)