Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package me.chanjar.weixin.channel.api;

import me.chanjar.weixin.channel.bean.base.WxChannelBaseResponse;
import me.chanjar.weixin.channel.bean.gift.GiftGetResponse;
import me.chanjar.weixin.channel.bean.gift.GiftProductInfo;
import me.chanjar.weixin.channel.bean.gift.GiftProductListResponse;
import me.chanjar.weixin.channel.bean.gift.GiftProductResponse;
import me.chanjar.weixin.channel.bean.gift.GiftProductUpdateInfo;
import me.chanjar.weixin.channel.bean.gift.GiftSetParam;
import me.chanjar.weixin.common.error.WxErrorException;

/**
* 视频号小店 赠品管理服务接口
*
* @author <a href="https://github.com/features/copilot">GitHub Copilot</a>
* @see <a href="https://developers.weixin.qq.com/doc/store/shop/API/channels-shop-product/gift/api_addgiftproduct.html">赠品管理接口文档</a>
*/
public interface WxChannelGiftService {

/**
* 添加非卖商品(赠品)
*
* @param info 赠品信息
* @return GiftProductResponse
* @throws WxErrorException 异常
*/
GiftProductResponse addGiftProduct(GiftProductInfo info) throws WxErrorException;

/**
* 更新非卖商品(赠品)
*
* @param info 赠品更新信息
* @return GiftProductResponse
* @throws WxErrorException 异常
*/
GiftProductResponse updateGiftProduct(GiftProductUpdateInfo info) throws WxErrorException;

/**
* 在售商品转赠品(设置在售商品为赠品)
*
* @param param 请求参数(product_id + skus 列表)
* @return GiftProductListResponse
* @throws WxErrorException 异常
*/
GiftProductListResponse setProductAsGift(GiftSetParam param) throws WxErrorException;

/**
* 获取赠品详情
*
* @param productId 赠品商品ID
* @param dataType 数据类型。1: 仅获取线上数据;2: 仅获取草稿数据;3: 同时获取(默认)
* @return GiftGetResponse
* @throws WxErrorException 异常
*/
GiftGetResponse getGiftProduct(String productId, Integer dataType) throws WxErrorException;

/**
* 获取赠品列表
*
* @param pageSize 每页数量
* @param nextKey 翻页上下文,不传默认获取第一页
* @param status 赠品状态过滤
* @return GiftProductListResponse
* @throws WxErrorException 异常
*/
GiftProductListResponse listGiftProduct(Integer pageSize, String nextKey, Integer status)
throws WxErrorException;

/**
* 更新赠品库存
*
* @param productId 赠品商品ID
* @param skuId SKU ID
* @param diffType 差量类型。1: 增加;2: 减少
* @param num 变更数量
* @return WxChannelBaseResponse
* @throws WxErrorException 异常
*/
WxChannelBaseResponse updateGiftStock(String productId, String skuId, Integer diffType, Integer num)
throws WxErrorException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@
import me.chanjar.weixin.channel.bean.limit.LimitTaskAddResponse;
import me.chanjar.weixin.channel.bean.limit.LimitTaskListResponse;
import me.chanjar.weixin.channel.bean.limit.LimitTaskParam;
import me.chanjar.weixin.channel.bean.limit.LimitTaskUpdateParam;
import me.chanjar.weixin.channel.bean.limit.LimitTaskUpdateResponse;
import me.chanjar.weixin.channel.bean.product.CategoryPreCheckResponse;
import me.chanjar.weixin.channel.bean.product.ExternalProductMappingNewParam;
import me.chanjar.weixin.channel.bean.product.ExternalProductMappingNewResponse;
import me.chanjar.weixin.channel.bean.product.ExternalProductMappingParam;
import me.chanjar.weixin.channel.bean.product.ExternalProductMappingResponse;
import me.chanjar.weixin.channel.bean.product.ProductBrandRecommendParam;
import me.chanjar.weixin.channel.bean.product.ProductBrandRecommendResponse;
import me.chanjar.weixin.channel.bean.product.SkuStockBatchResponse;
import me.chanjar.weixin.channel.bean.product.SkuStockResponse;
import me.chanjar.weixin.channel.bean.product.SpuFastInfo;
Expand All @@ -14,6 +23,8 @@
import me.chanjar.weixin.channel.bean.product.SpuListResponse;
import me.chanjar.weixin.channel.bean.product.SpuUpdateInfo;
import me.chanjar.weixin.channel.bean.product.SpuUpdateResponse;
import me.chanjar.weixin.channel.bean.product.StockFlowParam;
import me.chanjar.weixin.channel.bean.product.StockFlowResponse;
import me.chanjar.weixin.channel.bean.product.link.ProductH5UrlResponse;
import me.chanjar.weixin.channel.bean.product.link.ProductQrCodeResponse;
import me.chanjar.weixin.channel.bean.product.link.ProductTagLinkResponse;
Expand Down Expand Up @@ -247,4 +258,80 @@ WxChannelBaseResponse updateStock(String productId, String skuId, Integer diffTy
* @throws WxErrorException 异常
*/
WxChannelBaseResponse deleteLimitTask(String taskId) throws WxErrorException;

/**
* 更新限时抢购任务
*
* @param param 更新参数
* @return LimitTaskUpdateResponse
* @throws WxErrorException 异常
*/
LimitTaskUpdateResponse updateLimitTask(LimitTaskUpdateParam param) throws WxErrorException;

/**
* 获取库存流水
*
* @param param 查询参数
* @return StockFlowResponse
* @throws WxErrorException 异常
*/
StockFlowResponse getStockFlow(StockFlowParam param) throws WxErrorException;

/**
* 发品前校验(校验当前商家是否具备在指定类目发品的资质)
*
* @param catId 叶子类目id
* @return CategoryPreCheckResponse
* @throws WxErrorException 异常
*/
CategoryPreCheckResponse categoryPreCheck(Long catId) throws WxErrorException;

/**
* 商品品牌推荐(根据商品信息推荐品牌)
*
* @param param 请求参数
* @return ProductBrandRecommendResponse
* @throws WxErrorException 异常
*/
ProductBrandRecommendResponse getProductBrandRecommend(ProductBrandRecommendParam param)
throws WxErrorException;

/**
* 站内外商品属性映射
*
* @param param 请求参数
* @return ExternalProductMappingResponse
* @throws WxErrorException 异常
*/
ExternalProductMappingResponse externalProductMapping(ExternalProductMappingParam param)
throws WxErrorException;

/**
* 站内外商品属性映射(新版)
*
* @param param 请求参数
* @return ExternalProductMappingNewResponse
* @throws WxErrorException 异常
*/
ExternalProductMappingNewResponse externalProductMappingNew(ExternalProductMappingNewParam param)
throws WxErrorException;

/**
* 商品立即开售(结束预售)
*
* @param productId 商品ID
* @param taskId 预售任务ID
* @return WxChannelBaseResponse
* @throws WxErrorException 异常
*/
WxChannelBaseResponse beginTimingSale(String productId, String taskId) throws WxErrorException;

/**
* 取消商品开售(取消预售)
*
* @param productId 商品ID
* @return WxChannelBaseResponse
* @throws WxErrorException 异常
*/
WxChannelBaseResponse cancelTimingSale(String productId) throws WxErrorException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -182,4 +182,11 @@ public interface WxChannelService extends BaseWxChannelService {
*/
WxChannelLiveDashboardService getLiveDashboardService();

/**
* 赠品管理服务
*
* @return 赠品管理服务
*/
WxChannelGiftService getGiftService();

}
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public abstract class BaseWxChannelServiceImpl<H, P> implements WxChannelService
private WxChannelVipService vipService = null;
private WxChannelCompassFinderService compassFinderService = null;
private WxChannelLiveDashboardService liveDashboardService = null;
private WxChannelGiftService giftService = null;

protected WxChannelConfig config;
private int retrySleepMillis = 1000;
Expand Down Expand Up @@ -473,4 +474,12 @@ public synchronized WxChannelLiveDashboardService getLiveDashboardService() {
return liveDashboardService;
}

@Override
public synchronized WxChannelGiftService getGiftService() {
if (giftService == null) {
giftService = new WxChannelGiftServiceImpl(this);
}
return giftService;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package me.chanjar.weixin.channel.api.impl;

import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Gift.ADD_GIFT_PRODUCT_URL;
import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Gift.GET_GIFT_PRODUCT_URL;
import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Gift.LIST_GIFT_PRODUCT_URL;
import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Gift.SET_PRODUCT_AS_GIFT_URL;
import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Gift.UPDATE_GIFT_PRODUCT_URL;
import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Gift.UPDATE_GIFT_STOCK_URL;

import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.channel.api.WxChannelGiftService;
import me.chanjar.weixin.channel.bean.base.WxChannelBaseResponse;
import me.chanjar.weixin.channel.bean.gift.GiftGetResponse;
import me.chanjar.weixin.channel.bean.gift.GiftListParam;
import me.chanjar.weixin.channel.bean.gift.GiftProductInfo;
import me.chanjar.weixin.channel.bean.gift.GiftProductListResponse;
import me.chanjar.weixin.channel.bean.gift.GiftProductResponse;
import me.chanjar.weixin.channel.bean.gift.GiftProductUpdateInfo;
import me.chanjar.weixin.channel.bean.gift.GiftSetParam;
import me.chanjar.weixin.channel.util.JsonUtils;
import me.chanjar.weixin.channel.util.ResponseUtils;
import me.chanjar.weixin.common.error.WxErrorException;

/**
* 视频号小店 赠品管理服务实现
*
* @author <a href="https://github.com/features/copilot">GitHub Copilot</a>
*/
@Slf4j
public class WxChannelGiftServiceImpl implements WxChannelGiftService {

/** 微信商店服务 */
private final BaseWxChannelServiceImpl<?, ?> shopService;

public WxChannelGiftServiceImpl(BaseWxChannelServiceImpl<?, ?> shopService) {
this.shopService = shopService;
}

@Override
public GiftProductResponse addGiftProduct(GiftProductInfo info) throws WxErrorException {
String reqJson = JsonUtils.encode(info);
String resJson = shopService.post(ADD_GIFT_PRODUCT_URL, reqJson);
return ResponseUtils.decode(resJson, GiftProductResponse.class);
}

@Override
public GiftProductResponse updateGiftProduct(GiftProductUpdateInfo info) throws WxErrorException {
String reqJson = JsonUtils.encode(info);
String resJson = shopService.post(UPDATE_GIFT_PRODUCT_URL, reqJson);
return ResponseUtils.decode(resJson, GiftProductResponse.class);
}

@Override
public GiftProductListResponse setProductAsGift(GiftSetParam param) throws WxErrorException {
String reqJson = JsonUtils.encode(param);
String resJson = shopService.post(SET_PRODUCT_AS_GIFT_URL, reqJson);
return ResponseUtils.decode(resJson, GiftProductListResponse.class);
}

@Override
public GiftGetResponse getGiftProduct(String productId, Integer dataType) throws WxErrorException {
String reqJson = "{\"product_id\":\"" + productId + "\",\"data_type\":" + dataType + "}";
String resJson = shopService.post(GET_GIFT_PRODUCT_URL, reqJson);
return ResponseUtils.decode(resJson, GiftGetResponse.class);
}

@Override
public GiftProductListResponse listGiftProduct(Integer pageSize, String nextKey, Integer status)
throws WxErrorException {
GiftListParam param = new GiftListParam(pageSize, nextKey, status);
String reqJson = JsonUtils.encode(param);
String resJson = shopService.post(LIST_GIFT_PRODUCT_URL, reqJson);
return ResponseUtils.decode(resJson, GiftProductListResponse.class);
}

@Override
public WxChannelBaseResponse updateGiftStock(String productId, String skuId, Integer diffType, Integer num)
throws WxErrorException {
String reqJson = "{\"product_id\":\"" + productId + "\",\"sku_id\":\"" + skuId
+ "\",\"diff_type\":" + diffType + ",\"num\":" + num + "}";
String resJson = shopService.post(UPDATE_GIFT_STOCK_URL, reqJson);
return ResponseUtils.decode(resJson, WxChannelBaseResponse.class);
}
}
Loading