mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2026-03-10 00:13:40 +08:00
添加图文分析数据接口
This commit is contained in:
@@ -1,18 +1,22 @@
|
||||
package me.chanjar.weixin.mp.api;
|
||||
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpUserCumulate;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpUserSummary;
|
||||
import me.chanjar.weixin.mp.bean.datacube.WxDataCubeArticleResult;
|
||||
import me.chanjar.weixin.mp.bean.datacube.WxDataCubeArticleTotal;
|
||||
import me.chanjar.weixin.mp.bean.datacube.WxDataCubeUserCumulate;
|
||||
import me.chanjar.weixin.mp.bean.datacube.WxDataCubeUserSummary;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 统计分析相关接口
|
||||
* 统计分析相关接口
|
||||
* Created by Binary Wang on 2016/8/23.
|
||||
* @author binarywang (https://github.com/binarywang)
|
||||
*/
|
||||
public interface WxMpDataCubeService {
|
||||
//*******************用户分析数据接口***********************//
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 获取用户增减数据
|
||||
@@ -23,7 +27,7 @@ public interface WxMpDataCubeService {
|
||||
* @param beginDate 开始时间
|
||||
* @param endDate 最大时间跨度7天,endDate不能早于begingDate
|
||||
*/
|
||||
List<WxMpUserSummary> getUserSummary(Date beginDate, Date endDate) throws WxErrorException;
|
||||
List<WxDataCubeUserSummary> getUserSummary(Date beginDate, Date endDate) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
@@ -35,5 +39,75 @@ public interface WxMpDataCubeService {
|
||||
* @param beginDate 开始时间
|
||||
* @param endDate 最大时间跨度7天,endDate不能早于begingDate
|
||||
*/
|
||||
List<WxMpUserCumulate> getUserCumulate(Date beginDate, Date endDate) throws WxErrorException;
|
||||
List<WxDataCubeUserCumulate> getUserCumulate(Date beginDate, Date endDate) throws WxErrorException;
|
||||
|
||||
//*******************图文分析数据接口***********************//
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 获取图文群发每日数据(getarticlesummary)
|
||||
* 详情请见文档:<a href="http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141084&token=&lang=zh_CN">图文分析数据接口</a>
|
||||
* 接口url格式:https://api.weixin.qq.com/datacube/getarticlesummary?access_token=ACCESS_TOKEN
|
||||
* </pre>
|
||||
*
|
||||
* @param beginDate 开始时间
|
||||
* @param endDate 最大时间跨度1天,endDate不能早于begingDate
|
||||
*/
|
||||
List<WxDataCubeArticleResult> getArticleSummary(Date beginDate, Date endDate) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 获取图文群发总数据(getarticletotal)
|
||||
* 详情请见文档:<a href="http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141084&token=&lang=zh_CN">图文分析数据接口</a>
|
||||
* 接口url格式:https://api.weixin.qq.com/datacube/getarticletotal?access_token=ACCESS_TOKEN
|
||||
*
|
||||
* @param beginDate 开始时间
|
||||
* @param endDate 最大时间跨度1天,endDate不能早于begingDate
|
||||
*/
|
||||
List<WxDataCubeArticleTotal> getArticleTotal(Date beginDate, Date endDate) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 获取图文统计数据(getuserread)
|
||||
* 详情请见文档:<a href="http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141084&token=&lang=zh_CN">图文分析数据接口</a>
|
||||
* 接口url格式:https://api.weixin.qq.com/datacube/getuserread?access_token=ACCESS_TOKEN
|
||||
*
|
||||
* @param beginDate 开始时间
|
||||
* @param endDate 最大时间跨度3天,endDate不能早于begingDate
|
||||
*/
|
||||
List<WxDataCubeArticleResult> getUserRead(Date beginDate, Date endDate) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 获取图文统计分时数据(getuserreadhour)
|
||||
* 详情请见文档:<a href="http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141084&token=&lang=zh_CN">图文分析数据接口</a>
|
||||
* 接口url格式:https://api.weixin.qq.com/datacube/getuserreadhour?access_token=ACCESS_TOKEN
|
||||
*
|
||||
* @param beginDate 开始时间
|
||||
* @param endDate 最大时间跨度1天,endDate不能早于begingDate
|
||||
*/
|
||||
List<WxDataCubeArticleResult> getUserReadHour(Date beginDate, Date endDate) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 获取图文分享转发数据(getusershare)
|
||||
* 详情请见文档:<a href="http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141084&token=&lang=zh_CN">图文分析数据接口</a>
|
||||
* 接口url格式:https://api.weixin.qq.com/datacube/getusershare?access_token=ACCESS_TOKEN
|
||||
*
|
||||
* @param beginDate 开始时间
|
||||
* @param endDate 最大时间跨度7天,endDate不能早于begingDate
|
||||
*/
|
||||
List<WxDataCubeArticleResult> getUserShare(Date beginDate, Date endDate) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 获取图文分享转发分时数据(getusersharehour)
|
||||
* 详情请见文档:<a href="http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141084&token=&lang=zh_CN">图文分析数据接口</a>
|
||||
* 接口url格式:https://api.weixin.qq.com/datacube/getusersharehour?access_token=ACCESS_TOKEN
|
||||
*
|
||||
* @param beginDate 开始时间
|
||||
* @param endDate 最大时间跨度1天,endDate不能早于begingDate
|
||||
*/
|
||||
List<WxDataCubeArticleResult> getUserShareHour(Date beginDate, Date endDate) throws WxErrorException;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,24 +1,29 @@
|
||||
package me.chanjar.weixin.mp.api.impl;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.mp.api.WxMpDataCubeService;
|
||||
import me.chanjar.weixin.mp.api.WxMpService;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpUserCumulate;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpUserSummary;
|
||||
import me.chanjar.weixin.mp.bean.datacube.WxDataCubeArticleResult;
|
||||
import me.chanjar.weixin.mp.bean.datacube.WxDataCubeArticleTotal;
|
||||
import me.chanjar.weixin.mp.bean.datacube.WxDataCubeUserCumulate;
|
||||
import me.chanjar.weixin.mp.bean.datacube.WxDataCubeUserSummary;
|
||||
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by Binary Wang on 2016/8/23.
|
||||
* @author binarywang (https://github.com/binarywang)
|
||||
*/
|
||||
public class WxMpDataCubeServiceImpl implements WxMpDataCubeService {
|
||||
protected final Logger log = LoggerFactory.getLogger(WxMpServiceImpl.class);
|
||||
|
||||
private static final String API_URL_PREFIX = "https://api.weixin.qq.com/datacube";
|
||||
private WxMpService wxMpService;
|
||||
|
||||
@@ -27,26 +32,106 @@ public class WxMpDataCubeServiceImpl implements WxMpDataCubeService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<WxMpUserSummary> getUserSummary(Date beginDate, Date endDate) throws WxErrorException {
|
||||
public List<WxDataCubeUserSummary> getUserSummary(Date beginDate, Date endDate) throws WxErrorException {
|
||||
String url = API_URL_PREFIX + "/getusersummary";
|
||||
JsonObject param = new JsonObject();
|
||||
param.addProperty("begin_date", WxMpService.SIMPLE_DATE_FORMAT.format(beginDate));
|
||||
param.addProperty("end_date", WxMpService.SIMPLE_DATE_FORMAT.format(endDate));
|
||||
String responseContent = this.wxMpService.post(url, param.toString());
|
||||
this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent);
|
||||
return WxMpGsonBuilder.INSTANCE.create().fromJson(new JsonParser().parse(responseContent).getAsJsonObject().get("list"),
|
||||
new TypeToken<List<WxMpUserSummary>>() {
|
||||
new TypeToken<List<WxDataCubeUserSummary>>() {
|
||||
}.getType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<WxMpUserCumulate> getUserCumulate(Date beginDate, Date endDate) throws WxErrorException {
|
||||
public List<WxDataCubeUserCumulate> getUserCumulate(Date beginDate, Date endDate) throws WxErrorException {
|
||||
String url = API_URL_PREFIX + "/getusercumulate";
|
||||
JsonObject param = new JsonObject();
|
||||
param.addProperty("begin_date", WxMpService.SIMPLE_DATE_FORMAT.format(beginDate));
|
||||
param.addProperty("end_date", WxMpService.SIMPLE_DATE_FORMAT.format(endDate));
|
||||
String responseContent = this.wxMpService.post(url, param.toString());
|
||||
this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent);
|
||||
return WxMpGsonBuilder.INSTANCE.create().fromJson(new JsonParser().parse(responseContent).getAsJsonObject().get("list"),
|
||||
new TypeToken<List<WxMpUserCumulate>>() {
|
||||
new TypeToken<List<WxDataCubeUserCumulate>>() {
|
||||
}.getType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<WxDataCubeArticleResult> getArticleSummary(Date beginDate, Date endDate) throws WxErrorException {
|
||||
String url = API_URL_PREFIX + "/getarticlesummary";
|
||||
JsonObject param = new JsonObject();
|
||||
param.addProperty("begin_date", WxMpService.SIMPLE_DATE_FORMAT.format(beginDate));
|
||||
param.addProperty("end_date", WxMpService.SIMPLE_DATE_FORMAT.format(endDate));
|
||||
String responseContent = this.wxMpService.post(url, param.toString());
|
||||
this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent);
|
||||
return WxMpGsonBuilder.INSTANCE.create().fromJson(new JsonParser().parse(responseContent).getAsJsonObject().get("list"),
|
||||
new TypeToken<List<WxDataCubeArticleResult>>() {
|
||||
}.getType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<WxDataCubeArticleTotal> getArticleTotal(Date beginDate, Date endDate) throws WxErrorException {
|
||||
String url = API_URL_PREFIX + "/getarticletotal";
|
||||
JsonObject param = new JsonObject();
|
||||
param.addProperty("begin_date", WxMpService.SIMPLE_DATE_FORMAT.format(beginDate));
|
||||
param.addProperty("end_date", WxMpService.SIMPLE_DATE_FORMAT.format(endDate));
|
||||
String responseContent = this.wxMpService.post(url, param.toString());
|
||||
this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent);
|
||||
return WxMpGsonBuilder.INSTANCE.create().fromJson(new JsonParser().parse(responseContent).getAsJsonObject().get("list"),
|
||||
new TypeToken<List<WxDataCubeArticleTotal>>() {
|
||||
}.getType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<WxDataCubeArticleResult> getUserRead(Date beginDate, Date endDate) throws WxErrorException {
|
||||
String url = API_URL_PREFIX + "/getuserread";
|
||||
JsonObject param = new JsonObject();
|
||||
param.addProperty("begin_date", WxMpService.SIMPLE_DATE_FORMAT.format(beginDate));
|
||||
param.addProperty("end_date", WxMpService.SIMPLE_DATE_FORMAT.format(endDate));
|
||||
String responseContent = this.wxMpService.post(url, param.toString());
|
||||
this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent);
|
||||
return WxMpGsonBuilder.INSTANCE.create().fromJson(new JsonParser().parse(responseContent).getAsJsonObject().get("list"),
|
||||
new TypeToken<List<WxDataCubeArticleResult>>() {
|
||||
}.getType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<WxDataCubeArticleResult> getUserReadHour(Date beginDate, Date endDate) throws WxErrorException {
|
||||
String url = API_URL_PREFIX + "/getuserreadhour";
|
||||
JsonObject param = new JsonObject();
|
||||
param.addProperty("begin_date", WxMpService.SIMPLE_DATE_FORMAT.format(beginDate));
|
||||
param.addProperty("end_date", WxMpService.SIMPLE_DATE_FORMAT.format(endDate));
|
||||
String responseContent = this.wxMpService.post(url, param.toString());
|
||||
this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent);
|
||||
return WxMpGsonBuilder.INSTANCE.create().fromJson(new JsonParser().parse(responseContent).getAsJsonObject().get("list"),
|
||||
new TypeToken<List<WxDataCubeArticleResult>>() {
|
||||
}.getType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<WxDataCubeArticleResult> getUserShare(Date beginDate, Date endDate) throws WxErrorException {
|
||||
String url = API_URL_PREFIX + "/getusershare";
|
||||
JsonObject param = new JsonObject();
|
||||
param.addProperty("begin_date", WxMpService.SIMPLE_DATE_FORMAT.format(beginDate));
|
||||
param.addProperty("end_date", WxMpService.SIMPLE_DATE_FORMAT.format(endDate));
|
||||
String responseContent = this.wxMpService.post(url, param.toString());
|
||||
this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent);
|
||||
return WxMpGsonBuilder.INSTANCE.create().fromJson(new JsonParser().parse(responseContent).getAsJsonObject().get("list"),
|
||||
new TypeToken<List<WxDataCubeArticleResult>>() {
|
||||
}.getType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<WxDataCubeArticleResult> getUserShareHour(Date beginDate, Date endDate) throws WxErrorException {
|
||||
String url = API_URL_PREFIX + "/getusersharehour";
|
||||
JsonObject param = new JsonObject();
|
||||
param.addProperty("begin_date", WxMpService.SIMPLE_DATE_FORMAT.format(beginDate));
|
||||
param.addProperty("end_date", WxMpService.SIMPLE_DATE_FORMAT.format(endDate));
|
||||
String responseContent = this.wxMpService.post(url, param.toString());
|
||||
this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent);
|
||||
return WxMpGsonBuilder.INSTANCE.create().fromJson(new JsonParser().parse(responseContent).getAsJsonObject().get("list"),
|
||||
new TypeToken<List<WxDataCubeArticleResult>>() {
|
||||
}.getType());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user