8000 【视频号】新增视频号助手-直播大屏数据、罗盘达人版API接口相关内容。 by Winnie-by996 · Pull Request #3368 · binarywang/WxJava · GitHub
[go: up one dir, main page]

Skip to content

【视频号】新增视频号助手-直播大屏数据、罗盘达人版API接口相关内容。 #3368

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
【视频号】新增视频号助手-直播大屏数据、罗盘达人版API接口相关内容。
  • Loading branch information
Winnie-by996 committed Sep 10, 2024
commit 6d48a6b5b05f0b4bf711dd8da7361f2095e81821
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package me.chanjar.weixin.channel.api;

import me.chanjar.weixin.channel.bean.compass.finder.OverallResponse;
import me.chanjar.weixin.channel.bean.compass.finder.ProductDataResponse;
import me.chanjar.weixin.channel.bean.compass.finder.ProductListResponse;
import me.chanjar.weixin.channel.bean.compass.finder.SaleProfileDataResponse;
import me.chanjar.weixin.common.error.WxErrorException;

/**
* 视频号助手 罗盘达人版服务
*
* @author <a href="https://github.com/Winnie-by996">Winnie</a>
*/
public interface WxChannelCompassFinderService {

/**
* 获取电商概览数据
*
* @param ds 日期,格式 yyyyMMdd
* @return 电商概览数据
*
* @throws WxErrorException 异常
*/
OverallResponse getOverall(String ds) throws WxErrorException;

/**
* 获取带货商品数据
*
* @param ds 日期,格式 yyyyMMdd
* @param productId 商品id
* @return 带货商品数据
*
* @throws WxErrorException 异常
*/
ProductDataResponse getProductData(String ds, String productId) throws WxErrorException;

/**
* 获取带货商品列表
*
* @param ds 日期,格式 yyyyMMdd
* @return 带货商品列表
*
* @throws WxErrorException 异常
*/
ProductListResponse getProductList(String ds) throws WxErrorException;

/**
* 获取带货人群数据
*
* @param ds 日期,格式 yyyyMMdd
* @param type 用户类型,1=商品曝光用户, 2=商品点击用户, 3=购买用户, 4=首购用户, 5=复购用户, 6=直播观看用户
* @return 带货人群数据
*
* @throws WxErrorException 异常
*/
SaleProfileDataResponse getSaleProfileData(String ds, Integer type) throws WxErrorException;

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

import me.chanjar.weixin.channel.bean.live.dashboard.LiveDataResponse;
import me.chanjar.weixin.channel.bean.live.dashboard.LiveListResponse;
import me.chanjar.weixin.common.error.WxErrorException;

/**
* 视频号助手 直播大屏数据服务
*
* @author <a href="https://github.com/Winnie-by996">Winnie</a>
*/
public interface WxChannelLiveDashboardService {

/**
* 获取直播大屏直播列表
*
* @param ds 日期,格式 yyyyMMdd
* @return 播大屏直播列表
*
* @throws WxErrorException 异常
*/
LiveListResponse getLiveList(Long ds) throws WxErrorException;

/**
* 获取直播大屏数据
*
* @param exportId 直播唯一ID
* @return 播大屏数据
*
* @throws WxErrorException 异常
*/
LiveDataResponse getLiveData(String exportId) throws WxErrorException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,19 @@ public interface WxChannelService extends BaseWxChannelService {
* @return 会员服务
*/
WxChannelVipService getVipService();

/**
* 视频号助手-罗盘达人版服务
*
* @return 罗盘达人版服务
*/
WxChannelCompassFinderService getCompassFinderService();

/**
* 视频号助手-直播大屏数据服务
*
* @return 直播大屏数据服务
*/
WxChannelLiveDashboardService getLiveDashboardService();

}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ public abstract class BaseWxChannelServiceImpl<H, P> implements WxChannelService
private WxFinderLiveService finderLiveService = null;
private WxAssistantService assistantService = null;
private WxChannelVipService vipService = new WxChannelVipServiceImpl(this);
private final WxChannelCompassFinderService compassFinderService =
new WxChannelCompassFinderServiceImpl(this);
private final WxChannelLiveDashboardService liveDashboardService =
new WxChannelLiveDashboardServiceImpl(this);

protected WxChannelConfig config;
private int retrySleepMillis = 1000;
Expand Down Expand Up @@ -411,4 +415,11 @@ public WxAssistantService getAssistantService() {
public WxChannelVipService getVipService() {
return vipService;
}

@Override
public WxChannelCompassFinderService getCompassFinderService() { return compassFinderService; }

@Override
public WxChannelLiveDashboardService getLiveDashboardService() { return liveDashboardService; }

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

import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.channel.api.WxChannelCompassFinderService;
import me.chanjar.weixin.channel.bean.compass.finder.*;
import me.chanjar.weixin.channel.util.ResponseUtils;
import me.chanjar.weixin.common.error.WxErrorException;

import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.CompassFinder.*;

/**
* 视频号助手 罗盘达人版服务实现
*
* @author <a href="https://github.com/Winnie-by996">Winnie</a>
*/
@Slf4j
public class WxChannelCompassFinderServiceImpl implements WxChannelCompassFinderService {

/**
* 微信商店服务
*/
private final BaseWxChannelServiceImpl shopService;

public WxChannelCompassFinderServiceImpl(BaseWxChannelServiceImpl shopService) {this.shopService = shopService;}

@Override
public OverallResponse getOverall(String ds) throws WxErrorException {
CompassFinderBaseParam param = new CompassFinderBaseParam(ds);
String resJson = shopService.post(GET_OVERALL_URL, param);
return ResponseUtils.decode(resJson, OverallResponse.class);
}

@Override
public ProductDataResponse getProductData(String ds, String productId) throws WxErrorException {
ProductDataParam param = new ProductDataParam(ds, productId);
String resJson = shopService.post(GET_PRODUCT_DATA_URL, param);
return ResponseUtils.decode(resJson, ProductDataResponse.class);
}

@Override
public ProductListResponse getProductList(String ds) throws WxErrorException {
CompassFinderBaseParam param = new CompassFinderBaseParam(ds);
String resJson = shopService.post(GET_PRODUCT_LIST_URL, param);
return ResponseUtils.decode(resJson, ProductListResponse.class);
}

@Override
public SaleProfileDataResponse getSaleProfileData(String ds, Integer type) throws WxErrorException {
SaleProfileDataParam param = new SaleProfileDataParam(ds, type);
String resJson = shopService.post(GET_SALE_PROFILE_DATA_URL, param);
return ResponseUtils.decode(resJson, SaleProfileDataResponse.class);
}

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

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.channel.api.WxChannelLiveDashboardService;
import me.chanjar.weixin.channel.bean.live.dashboard.LiveDataParam;
import me.chanjar.weixin.channel.bean.live.dashboard.LiveDataResponse;
import me.chanjar.weixin.channel.bean.live.dashboard.LiveListParam;
import me.chanjar.weixin.channel.bean.live.dashboard.LiveListResponse;
import me.chanjar.weixin.channel.util.ResponseUtils;
import me.chanjar.weixin.common.error.WxErrorException;
import org.apache.commons.lang3.ObjectUtils;

import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.LiveDashboard.*;

/**
* 视频号助手 直播大屏数据服务实现
*
* @author <a href="https://github.com/Winnie-by996">Winnie</a>
*/
@Slf4j
public class WxChannelLiveDashboardServiceImpl implements WxChannelLiveDashboardService {

/**
* 微信商店服务
*/
private final BaseWxChannelServiceImpl shopService;
private final ObjectMapper objectMapper = new ObjectMapper();

public WxChannelLiveDashboardServiceImpl(BaseWxChannelServiceImpl shopService) {this.shopService = shopService;}

@Override
public LiveListResponse getLiveList(Long ds) throws WxErrorException {
LiveListParam param = new LiveListParam(ds);
String resJson = shopService.post(GET_LIVE_LIST_URL, param);
return ResponseUtils.decode(resJson, LiveListResponse.class);
}

@Override
public LiveDataResponse getLiveData(String exportId) throws WxErrorException {
LiveDataParam param = new LiveDataParam(exportId);
String resJson = shopService.post(GET_LIVE_DATA_URL, param);
return this.convertLiveDataResponse(resJson);
}

/**
* 微信接口获取直播数据中存在非标准JSON,方便业务处理返回前做好解析
* 处理参数:
* live_dashboard_data,live_comparison_index,live_ec_data_summary,live_ec_conversion_metric,
* live_ec_profile,live_distribution_channel,single_live_ec_spu_data_page_v2
*
* @param resJson 直播数据返回JSON
* @return LiveDataResponse
*
* @throws WxErrorException 异常
*/
private LiveDataResponse convertLiveDataResponse(String resJson) throws WxErrorException {
try {
ObjectNode rootNode = (ObjectNode) objectMapper.readTree(resJson);
String[] dataKeyArray = new String[] {
"live_dashboard_data", "live_comparison_index", "live_ec_data_summary", "live_ec_conversion_metric",
"live_ec_profile", "live_distribution_channel", "single_live_ec_spu_data_page_v2"
};
for(String dataKey : dataKeyArray) {
JsonNode jsonNode = rootNode.get(dataKey);
if (ObjectUtils.isNotEmpty(jsonNode)) {
JsonNode dataJsonNode = objectMapper.readTree(jsonNode.asText());
rootNode.set(dataKey, dataJsonNode);
}
}
String json = objectMapper.writeValueAsString(rootNode);
return ResponseUtils.decode(json, LiveDataResponse.class);
} catch (JsonProcessingException e) {
throw new WxErrorException(e);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package 8000 me.chanjar.weixin.channel.bean.compass.finder;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
* 获取达人罗盘数据通用请求参数
*
* @author <a href="https://github.com/Winnie-by996">Winnie</a>
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL)
public class CompassFinderBaseParam implements Serializable {

private static final long serialVersionUID = - 4900361041041434435L;

/**
* 日期,格式 yyyyMMdd
*/
@JsonProperty("ds")
private String ds;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package me.chanjar.weixin.channel.bean.compass.finder;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.List;

/**
* 维度数据
*
* @author <a href="https://github.com/Winnie-by996">Winnie</a>
*/
@Data
@NoArgsConstructor
public class Field implements Serializable {

private static final long serialVersionUID = - 4243469984232948689L;

/**
* 维度类别名
*/
@JsonProperty("field_name")
private String fieldName;

/**
* 维度指标数据列表
*/
@JsonProperty("data_list")
private List<FieldData> dataList;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package me.chanjar.weixin.channel.bean.compass.finder;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
* 维度指标数据
*
* @author <a href="https://github.com/Winnie-by996">Winnie</a>
*/
@Data
@NoArgsConstructor
public class FieldData implements Serializable {

private static final long serialVersionUID = - 4022953139259283599L;

/**
* 维度指标名
*/
@JsonProperty("dim_key")
private String dimKey;

/**
* 维度指标值
*/
@JsonProperty("dim_value")
private String dimValue;

}
Loading
0