8000 :new: #3368 【视频号】新增视频号助手-直播大屏数据、罗盘达人版API相关接口 · binarywang/WxJava@31d2f72 · GitHub
[go: up one dir, main page]

Skip to content

Commit 31d2f72

Browse files
authored
🆕 #3368 【视频号】新增视频号助手-直播大屏数据、罗盘达人版API相关接口
1 parent 0b9444d commit 31d2f72

File tree

64 files changed

+3475
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+3475
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package me.chanjar.weixin.channel.api;
2+
3+
import me.chanjar.weixin.channel.bean.compass.finder.OverallResponse;
4+
import me.chanjar.weixin.channel.bean.compass.finder.ProductDataResponse;
5+
import me.chanjar.weixin.channel.bean.compass.finder.ProductListResponse;
6+
import me.chanjar.weixin.channel.bean.compass.finder.SaleProfileDataResponse;
7+
import me.chanjar.weixin.common.error.WxErrorException;
8+
9+
/**
10+
* 视频号助手 罗盘达人版服务
11+
*
12+
* @author <a href="https://github.com/Winnie-by996">Winnie</a>
13+
*/
14+
public interface WxChannelCompassFinderService {
15+
16+
/**
17+
* 获取电商概览数据
18+
*
19+
* @param ds 日期,格式 yyyyMMdd
20+
* @return 电商概览数据
21+
*
22+
* @throws WxErrorException 异常
23+
*/
24+
OverallResponse getOverall(String ds) throws WxErrorException;
25+
26+
/**
27+
* 获取带货商品数据
28+
*
29+
* @param ds 日期,格式 yyyyMMdd
30+
* @param productId 商品id
31+
* @return 带货商品数据
32+
*
33+
* @throws WxErrorException 异常
34+
*/
35+
ProductDataResponse getProductData(String ds, String productId) throws WxErrorException;
36+
37+
/**
38+
* 获取带货商品列表
39+
*
40+
* @param ds 日期,格式 yyyyMMdd
41+
* @return 带货商品列表
42+
*
43+
* @throws WxErrorException 异常
44+
*/
45+
ProductListResponse getProductList(String ds) throws WxErrorException;
46+
47+
/**
48+
* 获取带货人群数据
49+
*
50+
* @param ds 日期,格式 yyyyMMdd
51+
* @param type 用户类型,1=商品曝光用户, 2=商品点击用户, 3=购买用户, 4=首购用户, 5=复购用户, 6=直播观看用户
52+
* @return 带货人群数据
53+
*
54+
* @throws WxErrorException 异常
55+
*/
56+
SaleProfileDataResponse getSaleProfileData(String ds, Integer type) throws WxErrorException;
57+
58+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package me.chanjar.weixin.channel.api;
2+
3+
import me.chanjar.weixin.channel.bean.live.dashboard.LiveDataResponse;
4+
import me.chanjar.weixin.channel.bean.live.dashboard.LiveListResponse;
5+
import me.chanjar.weixin.common.error.WxErrorException;
6+
7+
/**
8+
* 视频号助手 直播大屏数据服务
9+
*
10+
* @author <a href="https://github.com/Winnie-by996">Winnie</a>
11+
*/
12+
public interface WxChannelLiveDashboardService {
13+
14+
/**
15+
* 获取直播大屏直播列表
16+
*
17+
* @param ds 日期,格式 yyyyMMdd
18+
* @return 播大屏直播列表
19+
*
20+
* @throws WxErrorException 异常
21+
*/
22+
LiveListResponse getLiveList(Long ds) throws WxErrorException;
23+
24+
/**
25+
* 获取直播大屏数据
26+
*
27+
* @param exportId 直播唯一ID
28+
* @return 播大屏数据
29+
*
30+
* @throws WxErrorException 异常
31+
*/
32+
LiveDataResponse getLiveData(String exportId) throws WxErrorException;
33+
34+
}

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,4 +147,19 @@ public interface WxChannelService extends BaseWxChannelService {
147147
* @return 会员服务
148148
*/
149149
WxChannelVipService getVipService();
150+
151+
/**
152+
* 视频号助手-罗盘达人版服务
153+
*
154+
* @return 罗盘达人版服务
155+
*/
156+
WxChannelCompassFinderService getCompassFinderService();
157+
158+
/**
159+
* 视频号助手-直播大屏数据服务
160+
*
161+
* @return 直播大屏数据服务
162+
*/
163+
WxChannelLiveDashboardService getLiveDashboardService();
164+
150165
}

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ public abstract class BaseWxChannelServiceImpl<H, P> implements WxChannelService
5555
private WxFinderLiveService finderLiveService = null;
5656
private WxAssistantService assistantService = null;
5757
private WxChannelVipService vipService = new WxChannelVipServiceImpl(this);
58+
private final WxChannelCompassFinderService compassFinderService =
59+
new WxChannelCompassFinderServiceImpl(this);
60+
private final WxChannelLiveDashboardService liveDashboardService =
61+
new WxChannelLiveDashboardServiceImpl(this);
5862

5963
protected WxChannelConfig config;
6064
private int retrySleepMillis = 1000;
@@ -411,4 +415,11 @@ public WxAssistantService getAssistantService() {
411415
public WxChannelVipService getVipService() {
412416
return vipService;
413417
}
418+
419+
@Override
420+
public WxChannelCompassFinderService getCompassFinderService() { return compassFinderService; }
421+
422+
@Override
423+
public WxChannelLiveDashboardService getLiveDashboardService() { return liveDashboardService; }
424+
414425
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package me.chanjar.weixin.channel.api.impl;
2+
3+
import lombok.extern.slf4j.Slf4j;
4+
import me.chanjar.weixin.channel.api.WxChannelCompassFinderService;
5+
import me.chanjar.weixin.channel.bean.compass.finder.*;
6+
import me.chanjar.weixin.channel.util.ResponseUtils;
7+
import me.chanjar.weixin.common.error.WxErrorException;
8+
9+
import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.CompassFinder.*;
10+
11+
/**
12+
* 视频号助手 罗盘达人版服务实现
13+
*
14+
* @author <a href="https://github.com/Winnie-by996">Winnie</a>
15+
*/
16+
@Slf4j
17+
public class WxChannelCompassFinderServiceImpl implements WxChannelCompassFinderService {
18+
19+
/**
20+
* 微信商店服务
21+
*/
22+
private final BaseWxChannelServiceImpl shopService;
23+
24+
public WxChannelCompassFinderServiceImpl(BaseWxChannelServiceImpl shopService) {this.shopService = shopService;}
25+
26+
@Override
27+
public OverallResponse getOverall(String ds) throws WxErrorException {
28+
CompassFinderBaseParam param = new CompassFinderBaseParam(ds);
29+
String resJson = shopService.post(GET_OVERALL_URL, param);
30+
return ResponseUtils.decode(resJson, OverallResponse.class);
31+
}
32+
33+
@Override
34+
public ProductDataResponse getProductData(String ds, String productId) throws WxErrorException {
35+
ProductDataParam param = new ProductDataParam(ds, productId);
36+
String resJson = shopService.post(GET_PRODUCT_DATA_URL, param);
37+
return ResponseUtils.decode(resJson, ProductDataResponse.class);
38+
}
39+
40+
@Override
41+
public ProductListResponse getProductList(String ds) throws WxErrorException {
42+
CompassFinderBaseParam param = new CompassFinderBaseParam(ds);
43+
String resJson = shopService.post(GET_PRODUCT_LIST_URL, param);
44+
return ResponseUtils.decode(resJson, ProductListResponse.class);
45+
}
46+
47+
@Override
48+
public SaleProfileDataResponse getSaleProfileData(String ds, Integer type) throws WxErrorException {
49+
SaleProfileDataParam param = new SaleProfileDataParam(ds, type);
50+
String resJson = shopService.post(GET_SALE_PROFILE_DATA_URL, param);
51+
return ResponseUtils.decode(resJson, SaleProfileDataResponse.class);
52+
}
53+
54+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
package me.chanjar.weixin.channel.api.impl;
2+
3+
import com.fasterxml.jackson.core.JsonProcessingException;
4+
import com.fasterxml.jackson.databind.JsonNode;
5+
import com.fasterxml.jackson.databind.ObjectMapper;
6+
import com.fasterxml.jackson.databind.node.ObjectNode;
7+
import lombok.extern.slf4j.Slf4j;
8+
import me.chanjar.weixin.channel.api.WxChannelLiveDashboardService;
9+
import me.chanjar.weixin.channel.bean.live.dashboard.LiveDataParam;
10+
import me.chanjar.weixin.channel.bean.live.dashboard.LiveDataResponse;
11+
import me.chanjar.weixin.channel.bean.live.dashboard.LiveListParam;
12+
import me.chanjar.weixin.channel.bean.live.dashboard.LiveListResponse;
13+
import me.chanjar.weixin.channel.util.ResponseUtils;
14+
import me.chanjar.weixin.common.error.WxErrorException;
15+
import org.apache.commons.lang3.ObjectUtils;
16+
17+
import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.LiveDashboard.*;
18+
19+
/**
20+
* 视频号助手 直播大屏数据服务实现
21+
*
22+
* @author <a href="https://github.com/Winnie-by996">Winnie</a>
23+
*/
24+
@Slf4j
25+
public class WxChannelLiveDashboardServiceImpl implements WxChannelLiveDashboardService {
26+
27+
/**
28+
* 微信商店服务
29+
*/
30+
private final BaseWxChannelServiceImpl shopService;
31+
private final ObjectMapper objectMapper = new ObjectMapper();
32+
33+
public WxChannelLiveDashboardServiceImpl(BaseWxChannelServiceImpl shopService) {this.shopService = shopService;}
34+
35+
@Override
36+
public LiveListResponse getLiveList(Long ds) throws WxErrorException {
37+
LiveListParam param = new LiveListParam(ds);
38+
String resJson = shopService.post(GET_LIVE_LIST_URL, param);
39+
return ResponseUtils.decode(resJson, LiveListResponse.class);
40+
}
41+
42+
@Override
43+
public LiveDataResponse getLiveData(String exportId) throws WxErrorException {
44+
LiveDataParam param = new LiveDataParam(exportId);
45+
String resJson = shopService.post(GET_LIVE_DATA_URL, param);
46+
return this.convertLiveDataResponse(resJson);
47+
}
48+
49+
/**
50+
* 微信接口获取直播数据中存在非标准JSON,方便业务处理返回前做好解析
51+
* 处理参数:
52+
* live_dashboard_data,live_comparison_index,live_ec_data_summary,live_ec_conversion_metric,
53+
* live_ec_profile,live_distribution_channel,single_live_ec_spu_data_page_v2
54+
*
55+
* @param resJson 直播数据返回JSON
56+
* @return LiveDataResponse
57+
*
58+
* @throws WxErrorException 异常
59+
*/
60+
private LiveDataResponse convertLiveDataResponse(String resJson) throws WxErrorException {
61+
try {
62+
ObjectNode rootNode = (ObjectNode) objectMapper.readTree(resJson);
63+
String[] dataKeyArray = new String[] {
64+
"live_dashboard_data", "live_comparison_index", "live_ec_data_summary", "live_ec_conversion_metric",
65+
"live_ec_profile", "live_distribution_channel", "single_live_ec_spu_data_page_v2"
66+
};
67+
for(String dataKey : dataKeyArray) {
68+
JsonNode jsonNode = rootNode.get(dataKey);
69+
if (ObjectUtils.isNotEmpty(jsonNode)) {
70+
JsonNode dataJsonNode = objectMapper.readTree(jsonNode.asText());
71+
rootNode.set(dataKey, dataJsonNode);
72+
}
73+
}
74+
String json = objectMapper.writeValueAsString(rootNode);
75+
return ResponseUtils.decode(json, LiveDataResponse.class);
76+
} catch (JsonProcessingException e) {
77+
throw new WxErrorException(e);
78+
}
79+
}
80+
81+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package me.chanjar.weixin.channel.bean.compass.finder;
2+
3+
import com.fasterxml.jackson.annotation.JsonInclude;
4+
import com.fasterxml.jackson.annotation.JsonProperty;
5+
import lombok.AllArgsConstructor;
6+
import lombok.Data;
7+
import lombok.NoArgsConstructor;
8+
9+
import java.io.Serializable;
10+
11+
/**
12+
* 获取达人罗盘数据通用请求参数
13+
*
14+
* @author <a href="https://github.com/Winnie-by996">Winnie</a>
15+
*/
16+
@Data
17+
@AllArgsConstructor
18+
@NoArgsConstructor
19+
@JsonInclude(JsonInclude.Include.NON_NULL)
20+
public class CompassFinderBaseParam implements Serializable {
21+
22+
private static final long serialVersionUID = - 4900361041041434435L;
23+
24+
/**
25+
* 日期,格式 yyyyMMdd
26+
*/
27+
@JsonProperty("ds")
28+
private String ds;
29+
30+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package me.chanjar.weixin.channel.bean.compass.finder;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
import lombok.Data;
5+
import lombok.NoArgsConstructor;
6+
7+
import java.io.Serializable;
8+
import java.util.List;
9+
10+
/**
11+
* 维度数据
12+
*
13+
* @author <a href="https://github.com/Winnie-by996">Winnie</a>
14+
*/
15+
@Data
16+
@NoArgsConstructor
17+
public class Field implements Serializable {
18+
19+
private static final long serialVersionUID = - 4243469984232948689L;
20+
21+
/**
22+
* 维度类别名
23+
*/
24+
@JsonProperty("field_name")
25+
private String fieldName;
26+
27+
/**
28+
* 维度指标数据列表
29+
*/
30+
@JsonProperty("data_list")
31+
private List<FieldData> dataList;
32+
33+
}
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.compass.finder;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
import lombok.Data;
5+
import lombok.NoArgsConstructor;
6+
7+
import java.io.Serializable;
8+
9+
/**
10+
* 维度指标数据
11+
*
12+
* @author <a href="https://github.com/Winnie-by996">Winnie</a>
13+
*/
14+
@Data
15+
@NoArgsConstructor
16+
public class FieldData implements Serializable {
17+
18+
private static final long serialVersionUID = - 4022953139259283599L;
19+
20+
/**
21+
* 维度指标名
22+
*/
23+
@JsonProperty("dim_key")
24+
private String dimKey;
25+
26+
/**
27+
* 维度指标值
28+
*/
29+
@JsonProperty("dim_value")
30+
private String dimValue;
31+
32+
}

0 commit comments

Comments
 (0)
0