Skip to content

Commit 0f7ed5c

Browse files
committed
feat(channel): 支持商品辅助接口
1 parent 93e0629 commit 0f7ed5c

16 files changed

Lines changed: 623 additions & 0 deletions
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,77 @@
11
package me.chanjar.weixin.channel.api;
22

3+
import me.chanjar.weixin.channel.bean.base.WxChannelBaseResponse;
4+
import me.chanjar.weixin.channel.bean.product.assistant.BeginTimingSaleParam;
5+
import me.chanjar.weixin.channel.bean.product.assistant.CancelTimingSaleParam;
6+
import me.chanjar.weixin.channel.bean.product.assistant.CategoryPreCheckParam;
7+
import me.chanjar.weixin.channel.bean.product.assistant.CategoryPreCheckResponse;
8+
import me.chanjar.weixin.channel.bean.product.assistant.ExternalProductMappingNewParam;
9+
import me.chanjar.weixin.channel.bean.product.assistant.ExternalProductMappingNewResponse;
10+
import me.chanjar.weixin.channel.bean.product.assistant.ExternalProductMappingParam;
11+
import me.chanjar.weixin.channel.bean.product.assistant.ExternalProductMappingResponse;
12+
import me.chanjar.weixin.channel.bean.product.assistant.ProductBrandRecommendParam;
13+
import me.chanjar.weixin.channel.bean.product.assistant.ProductBrandRecommendResponse;
14+
import me.chanjar.weixin.common.error.WxErrorException;
15+
316
/**
417
* 微信小店商品辅助功能服务。
518
*/
619
public interface WxChannelProductAssistantService {
20+
21+
/**
22+
* 发品前校验。
23+
*
24+
* @param param 校验参数
25+
* @return 校验结果
26+
* @throws WxErrorException 异常
27+
*/
28+
CategoryPreCheckResponse categoryPreCheck(CategoryPreCheckParam param) throws WxErrorException;
29+
30+
/**
31+
* 获取商品品牌推荐。
32+
*
33+
* @param param 推荐参数
34+
* @return 推荐结果
35+
* @throws WxErrorException 异常
36+
*/
37+
ProductBrandRecommendResponse getProductBrandRecommend(ProductBrandRecommendParam param)
38+
throws WxErrorException;
39+
40+
/**
41+
* 获取站内外商品属性映射。
42+
*
43+
* @param param 映射参数
44+
* @return 映射结果
45+
* @throws WxErrorException 异常
46+
*/
47+
ExternalProductMappingResponse externalProductMapping(ExternalProductMappingParam param)
48+
throws WxErrorException;
49+
50+
/**
51+
* 获取商品属性映射及推荐。
52+
*
53+
* @param param 映射参数
54+
* @return 映射结果
55+
* @throws WxErrorException 异常
56+
*/
57+
ExternalProductMappingNewResponse externalProductMappingNew(ExternalProductMappingNewParam param)
58+
throws WxErrorException;
59+
60+
/**
61+
* 将定时开售商品改为立即开售。
62+
*
63+
* @param param 开售参数
64+
* @return 操作结果
65+
* @throws WxErrorException 异常
66+
*/
67+
WxChannelBaseResponse beginTimingSale(BeginTimingSaleParam param) throws WxErrorException;
68+
69+
/**
70+
* 取消商品定时开售。
71+
*
72+
* @param param 取消参数
73+
* @return 操作结果
74+
* @throws WxErrorException 异常
75+
*/
76+
WxChannelBaseResponse cancelTimingSale(CancelTimingSaleParam param) throws WxErrorException;
777
}

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

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,27 @@
11
package me.chanjar.weixin.channel.api.impl;
22

3+
import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Spu.BEGIN_TIMING_SALE_URL;
4+
import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Spu.CANCEL_TIMING_SALE_URL;
5+
import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Spu.CATEGORY_PRE_CHECK_URL;
6+
import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Spu.EXTERNAL_PRODUCT_MAPPING_NEW_URL;
7+
import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Spu.EXTERNAL_PRODUCT_MAPPING_URL;
8+
import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Spu.PRODUCT_BRAND_RECOMMEND_URL;
9+
310
import me.chanjar.weixin.channel.api.WxChannelProductAssistantService;
11+
import me.chanjar.weixin.channel.bean.base.WxChannelBaseResponse;
12+
import me.chanjar.weixin.channel.bean.product.assistant.BeginTimingSaleParam;
13+
import me.chanjar.weixin.channel.bean.product.assistant.CancelTimingSaleParam;
14+
import me.chanjar.weixin.channel.bean.product.assistant.CategoryPreCheckParam;
15+
import me.chanjar.weixin.channel.bean.product.assistant.CategoryPreCheckResponse;
16+
import me.chanjar.weixin.channel.bean.product.assistant.ExternalProductMappingNewParam;
17+
import me.chanjar.weixin.channel.bean.product.assistant.ExternalProductMappingNewResponse;
18+
import me.chanjar.weixin.channel.bean.product.assistant.ExternalProductMappingParam;
19+
import me.chanjar.weixin.channel.bean.product.assistant.ExternalProductMappingResponse;
20+
import me.chanjar.weixin.channel.bean.product.assistant.ProductBrandRecommendParam;
21+
import me.chanjar.weixin.channel.bean.product.assistant.ProductBrandRecommendResponse;
22+
import me.chanjar.weixin.channel.util.JsonUtils;
23+
import me.chanjar.weixin.channel.util.ResponseUtils;
24+
import me.chanjar.weixin.common.error.WxErrorException;
425

526
/**
627
* 微信小店商品辅助功能服务实现。
@@ -13,4 +34,44 @@ public class WxChannelProductAssistantServiceImpl implements WxChannelProductAss
1334
public WxChannelProductAssistantServiceImpl(BaseWxChannelServiceImpl<?, ?> shopService) {
1435
this.shopService = shopService;
1536
}
37+
38+
@Override
39+
public CategoryPreCheckResponse categoryPreCheck(CategoryPreCheckParam param) throws WxErrorException {
40+
return post(CATEGORY_PRE_CHECK_URL, param, CategoryPreCheckResponse.class);
41+
}
42+
43+
@Override
44+
public ProductBrandRecommendResponse getProductBrandRecommend(ProductBrandRecommendParam param)
45+
throws WxErrorException {
46+
return post(PRODUCT_BRAND_RECOMMEND_URL, param, ProductBrandRecommendResponse.class);
47+
}
48+
49+
@Override
50+
public ExternalProductMappingResponse externalProductMapping(ExternalProductMappingParam param)
51+
throws WxErrorException {
52+
return post(EXTERNAL_PRODUCT_MAPPING_URL, param, ExternalProductMappingResponse.class);
53+
}
54+
55+
@Override
56+
public ExternalProductMappingNewResponse externalProductMappingNew(ExternalProductMappingNewParam param)
57+
throws WxErrorException {
58+
return post(EXTERNAL_PRODUCT_MAPPING_NEW_URL, param, ExternalProductMappingNewResponse.class);
59+
}
60+
61+
@Override
62+
public WxChannelBaseResponse beginTimingSale(BeginTimingSaleParam param) throws WxErrorException {
63+
return post(BEGIN_TIMING_SALE_URL, param, WxChannelBaseResponse.class);
64+
}
65+
66+
@Override
67+
public WxChannelBaseResponse cancelTimingSale(CancelTimingSaleParam param) throws WxErrorException {
68+
return post(CANCEL_TIMING_SALE_URL, param, WxChannelBaseResponse.class);
69+
}
70+
71+
private <T extends WxChannelBaseResponse> T post(String url, Object param, Class<T> responseType)
72+
throws WxErrorException {
73+
String reqJson = JsonUtils.encode(param);
74+
String resJson = shopService.post(url, reqJson);
75+
return ResponseUtils.decode(resJson, responseType);
76+
}
1677
}
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.assistant;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
import java.io.Serializable;
5+
import lombok.Data;
6+
import lombok.NoArgsConstructor;
7+
8+
/**
9+
* 商品立即开售参数。
10+
*/
11+
@Data
12+
@NoArgsConstructor
13+
public class BeginTimingSaleParam implements Serializable {
14+
15+
private static final long serialVersionUID = -1525220756273987016L;
16+
17+
/** 商品 ID。 */
18+
@JsonProperty("product_id")
19+
private String productId;
20+
21+
/** 定时开售任务 ID。 */
22+
@JsonProperty("task_id")
23+
private String taskId;
24+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package me.chanjar.weixin.channel.bean.product.assistant;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
import java.io.Serializable;
5+
import lombok.Data;
6+
import lombok.NoArgsConstructor;
7+
8+
/**
9+
* 取消商品开售参数。
10+
*/
11+
@Data
12+
@NoArgsConstructor
13+
public class CancelTimingSaleParam implements Serializable {
14+
15+
private static final long serialVersionUID = -3750831026611057323L;
16+
17+
/** 商品 ID。 */
18+
@JsonProperty("product_id")
19+
private String productId;
20+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package me.chanjar.weixin.channel.bean.product.assistant;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
import java.io.Serializable;
5+
import lombok.Data;
6+
import lombok.NoArgsConstructor;
7+
8+
/**
9+
* 发品前校验参数。
10+
*/
11+
@Data
12+
@NoArgsConstructor
13+
public class CategoryPreCheckParam implements Serializable {
14+
15+
private static final long serialVersionUID = 3616569394767815856L;
16+
17+
/** 叶子类目 ID,不传时只校验店铺相关条件。 */
18+
@JsonProperty("cat_id")
19+
private Long catId;
20+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package me.chanjar.weixin.channel.bean.product.assistant;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
import java.util.List;
5+
import lombok.Data;
6+
import lombok.EqualsAndHashCode;
7+
import lombok.NoArgsConstructor;
8+
import me.chanjar.weixin.channel.bean.base.WxChannelBaseResponse;
9+
10+
/**
11+
* 发品前校验响应。
12+
*/
13+
@Data
14+
@NoArgsConstructor
15+
@EqualsAndHashCode(callSuper = true)
16+
public class CategoryPreCheckResponse extends WxChannelBaseResponse {
17+
18+
private static final long serialVersionUID = 8912798390684239592L;
19+
20+
/** 是否全部校验通过。 */
21+
@JsonProperty("all_pass")
22+
private Boolean allPass;
23+
24+
/** 校验不通过的原因。 */
25+
@JsonProperty("fail_reasons")
26+
private List<String> failReasons;
27+
}
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.assistant;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
import java.io.Serializable;
5+
import lombok.Data;
6+
import lombok.NoArgsConstructor;
7+
8+
/**
9+
* 商品属性键值对。
10+
*/
11+
@Data
12+
@NoArgsConstructor
13+
public class ExternalAttribute implements Serializable {
14+
15+
private static final long serialVersionUID = -8639178782951125101L;
16+
17+
/** 属性名。 */
18+
@JsonProperty("key")
19+
private String key;
20+
21+
/** 属性值。 */
22+
@JsonProperty("value")
23+
private String value;
24+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package me.chanjar.weixin.channel.bean.product.assistant;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
import java.io.Serializable;
5+
import java.util.List;
6+
import lombok.Data;
7+
import lombok.NoArgsConstructor;
8+
9+
/**
10+
* 商品属性映射及推荐参数。
11+
*/
12+
@Data
13+
@NoArgsConstructor
14+
public class ExternalProductMappingNewParam implements Serializable {
15+
16+
private static final long serialVersionUID = -4942505655791636645L;
17+
18+
/** 叶子类目 ID。 */
19+
@JsonProperty("cat_id")
20+
private Long catId;
21+
22+
/** 外部商品类目名称。 */
23+
@JsonProperty("external_category_name")
24+
private String externalCategoryName;
25+
26+
/** 商品主图,至少一张。 */
27+
@JsonProperty("head_imgs")
28+
private List<String> headImgs;
29+
30+
/** 商品详情图。 */
31+
@JsonProperty("detail_imgs")
32+
private List<String> detailImgs;
33+
34+
/** 商品标题。 */
35+
@JsonProperty("title")
36+
private String title;
37+
38+
/** 外部商品属性列表。 */
39+
@JsonProperty("external_attributes")
40+
private List<ExternalAttribute> externalAttributes;
41+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package me.chanjar.weixin.channel.bean.product.assistant;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
import java.util.List;
5+
import lombok.Data;
6+
import lombok.EqualsAndHashCode;
7+
import lombok.NoArgsConstructor;
8+
import me.chanjar.weixin.channel.bean.base.WxChannelBaseResponse;
9+
10+
/**
11+
* 商品属性映射及推荐响应。
12+
*/
13+
@Data
14+
@NoArgsConstructor
15+
@EqualsAndHashCode(callSuper = true)
16+
public class ExternalProductMappingNewResponse extends WxChannelBaseResponse {
17+
18+
private static final long serialVersionUID = -6192580254142696913L;
19+
20+
/** 映射属性结果。 */
21+
@JsonProperty("attributes")
22+
private List<ExternalAttribute> attributes;
23+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package me.chanjar.weixin.channel.bean.product.assistant;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
import java.io.Serializable;
5+
import lombok.Data;
6+
import lombok.NoArgsConstructor;
7+
8+
/**
9+
* 站内外商品属性映射参数。
10+
*/
11+
@Data
12+
@NoArgsConstructor
13+
public class ExternalProductMappingParam implements Serializable {
14+
15+
private static final long serialVersionUID = 1944528166283981889L;
16+
17+
/** 叶子类目 ID。 */
18+
@JsonProperty("cat_id")
19+
private Long catId;
20+
21+
/** 外部商品属性名。 */
22+
@JsonProperty("external_attribute_name")
23+
private String externalAttributeName;
24+
25+
/** 外部商品属性值。 */
26+
@JsonProperty("external_attribute_value")
27+
private String externalAttributeValue;
28+
29+
/** 外部商品类目名称。 */
30+
@JsonProperty("external_category_name")
31+
private String externalCategoryName;
32+
}

0 commit comments

Comments
 (0)