mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-04-23 23:58:44 +08:00
添加接口分析数据接口
This commit is contained in:
parent
4a994ea4c3
commit
af9bfa2156
@ -3,6 +3,7 @@ package me.chanjar.weixin.mp.api;
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.mp.bean.datacube.WxDataCubeArticleResult;
|
||||
import me.chanjar.weixin.mp.bean.datacube.WxDataCubeArticleTotal;
|
||||
import me.chanjar.weixin.mp.bean.datacube.WxDataCubeInterfaceResult;
|
||||
import me.chanjar.weixin.mp.bean.datacube.WxDataCubeMsgResult;
|
||||
import me.chanjar.weixin.mp.bean.datacube.WxDataCubeUserCumulate;
|
||||
import me.chanjar.weixin.mp.bean.datacube.WxDataCubeUserSummary;
|
||||
@ -189,4 +190,28 @@ public interface WxMpDataCubeService {
|
||||
* @param endDate 最大时间跨度30天,endDate不能早于begingDate
|
||||
*/
|
||||
List<WxDataCubeMsgResult> getUpstreamMsgDistMonth(Date beginDate, Date endDate) throws WxErrorException;
|
||||
|
||||
//*******************接口分析数据接口***********************//
|
||||
/**
|
||||
* <pre>
|
||||
* 获取接口分析数据(getinterfacesummary)
|
||||
* 详情请见文档:<a href="http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141086&token=&lang=zh_CN">接口分析数据接口</a>
|
||||
* 接口url格式:https://api.weixin.qq.com/datacube/getinterfacesummary?access_token=ACCESS_TOKEN
|
||||
*
|
||||
* @param beginDate 开始时间
|
||||
* @param endDate 最大时间跨度30天,endDate不能早于begingDate
|
||||
*/
|
||||
List<WxDataCubeInterfaceResult> getInterfaceSummary(Date beginDate, Date endDate) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 获取接口分析分时数据(getinterfacesummaryhour)
|
||||
* 详情请见文档:<a href="http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141086&token=&lang=zh_CN">接口分析数据接口</a>
|
||||
* 接口url格式:https://api.weixin.qq.com/datacube/getinterfacesummaryhour?access_token=ACCESS_TOKEN
|
||||
*
|
||||
* @param beginDate 开始时间
|
||||
* @param endDate 最大时间跨度1天,endDate不能早于begingDate
|
||||
*/
|
||||
List<WxDataCubeInterfaceResult> getInterfaceSummaryHour(Date beginDate, Date endDate) throws WxErrorException;
|
||||
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import me.chanjar.weixin.mp.api.WxMpDataCubeService;
|
||||
import me.chanjar.weixin.mp.api.WxMpService;
|
||||
import me.chanjar.weixin.mp.bean.datacube.WxDataCubeArticleResult;
|
||||
import me.chanjar.weixin.mp.bean.datacube.WxDataCubeArticleTotal;
|
||||
import me.chanjar.weixin.mp.bean.datacube.WxDataCubeInterfaceResult;
|
||||
import me.chanjar.weixin.mp.bean.datacube.WxDataCubeMsgResult;
|
||||
import me.chanjar.weixin.mp.bean.datacube.WxDataCubeUserCumulate;
|
||||
import me.chanjar.weixin.mp.bean.datacube.WxDataCubeUserSummary;
|
||||
@ -233,4 +234,32 @@ public class WxMpDataCubeServiceImpl implements WxMpDataCubeService {
|
||||
new TypeToken<List<WxDataCubeMsgResult>>() {
|
||||
}.getType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<WxDataCubeInterfaceResult> getInterfaceSummary(Date beginDate,
|
||||
Date endDate) throws WxErrorException {
|
||||
String url = API_URL_PREFIX + "/getinterfacesummary";
|
||||
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<WxDataCubeInterfaceResult>>() {
|
||||
}.getType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<WxDataCubeInterfaceResult> getInterfaceSummaryHour(Date beginDate,
|
||||
Date endDate) throws WxErrorException {
|
||||
String url = API_URL_PREFIX + "/getinterfacesummaryhour";
|
||||
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<WxDataCubeInterfaceResult>>() {
|
||||
}.getType());
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,87 @@
|
||||
package me.chanjar.weixin.mp.bean.datacube;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
/**
|
||||
* 接口分析数据接口返回结果对象
|
||||
* @author binarywang(https://github.com/binarywang)
|
||||
* Created by Binary Wang on 2016/8/30.
|
||||
*/
|
||||
public class WxDataCubeInterfaceResult extends WxDataCubeBaseResult {
|
||||
|
||||
/**
|
||||
* ref_hour
|
||||
* 数据的小时,包括从000到2300,分别代表的是[000,100)到[2300,2400),即每日的第1小时和最后1小时
|
||||
*/
|
||||
@SerializedName("ref_hour")
|
||||
private Integer refHour;
|
||||
|
||||
/**
|
||||
* callback_count
|
||||
* 通过服务器配置地址获得消息后,被动回复用户消息的次数
|
||||
*/
|
||||
@SerializedName("callback_count")
|
||||
private Integer callbackCount;
|
||||
|
||||
/**
|
||||
* fail_count
|
||||
* 上述动作的失败次数
|
||||
*/
|
||||
@SerializedName("fail_count")
|
||||
private Integer failCount;
|
||||
|
||||
/**
|
||||
* total_time_cost
|
||||
* 总耗时,除以callback_count即为平均耗时
|
||||
*/
|
||||
@SerializedName("total_time_cost")
|
||||
private Integer totalTimeCost;
|
||||
|
||||
/**
|
||||
* max_time_cost
|
||||
* 最大耗时
|
||||
*/
|
||||
@SerializedName("max_time_cost")
|
||||
private Integer maxTimeCost;
|
||||
|
||||
public Integer getRefHour() {
|
||||
return this.refHour;
|
||||
}
|
||||
|
||||
public void setRefHour(Integer refHour) {
|
||||
this.refHour = refHour;
|
||||
}
|
||||
|
||||
public Integer getCallbackCount() {
|
||||
return this.callbackCount;
|
||||
}
|
||||
|
||||
public void setCallbackCount(Integer callbackCount) {
|
||||
this.callbackCount = callbackCount;
|
||||
}
|
||||
|
||||
public Integer getFailCount() {
|
||||
return this.failCount;
|
||||
}
|
||||
|
||||
public void setFailCount(Integer failCount) {
|
||||
this.failCount = failCount;
|
||||
}
|
||||
|
||||
public Integer getTotalTimeCost() {
|
||||
return this.totalTimeCost;
|
||||
}
|
||||
|
||||
public void setTotalTimeCost(Integer totalTimeCost) {
|
||||
this.totalTimeCost = totalTimeCost;
|
||||
}
|
||||
|
||||
public Integer getMaxTimeCost() {
|
||||
return this.maxTimeCost;
|
||||
}
|
||||
|
||||
public void setMaxTimeCost(Integer maxTimeCost) {
|
||||
this.maxTimeCost = maxTimeCost;
|
||||
}
|
||||
|
||||
}
|
@ -1,25 +1,26 @@
|
||||
package me.chanjar.weixin.mp.api.impl;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.mp.api.ApiTestModule;
|
||||
import me.chanjar.weixin.mp.bean.datacube.WxDataCubeArticleResult;
|
||||
import me.chanjar.weixin.mp.bean.datacube.WxDataCubeArticleTotal;
|
||||
import me.chanjar.weixin.mp.bean.datacube.WxDataCubeMsgResult;
|
||||
import me.chanjar.weixin.mp.bean.datacube.WxDataCubeUserCumulate;
|
||||
import me.chanjar.weixin.mp.bean.datacube.WxDataCubeUserSummary;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Guice;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Guice;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.mp.api.ApiTestModule;
|
||||
import me.chanjar.weixin.mp.bean.datacube.WxDataCubeArticleResult;
|
||||
import me.chanjar.weixin.mp.bean.datacube.WxDataCubeArticleTotal;
|
||||
import me.chanjar.weixin.mp.bean.datacube.WxDataCubeInterfaceResult;
|
||||
import me.chanjar.weixin.mp.bean.datacube.WxDataCubeMsgResult;
|
||||
import me.chanjar.weixin.mp.bean.datacube.WxDataCubeUserCumulate;
|
||||
import me.chanjar.weixin.mp.bean.datacube.WxDataCubeUserSummary;
|
||||
|
||||
/**
|
||||
* 测试统计分析相关的接口
|
||||
* Created by Binary Wang on 2016/8/23.
|
||||
@ -194,4 +195,20 @@ public class WxMpDataCubeServiceImplTest {
|
||||
Assert.assertNotNull(results);
|
||||
System.out.println(results);
|
||||
}
|
||||
|
||||
@Test(dataProvider = "thirtyDays")
|
||||
public void testGetInterfaceSummary(Date beginDate, Date endDate) throws WxErrorException {
|
||||
List<WxDataCubeInterfaceResult> results = this.wxService.getDataCubeService()
|
||||
.getInterfaceSummary(beginDate, endDate);
|
||||
Assert.assertNotNull(results);
|
||||
System.out.println(results);
|
||||
}
|
||||
|
||||
@Test(dataProvider = "oneDay")
|
||||
public void testGetInterfaceSummaryHour(Date date) throws WxErrorException {
|
||||
List<WxDataCubeInterfaceResult> results = this.wxService.getDataCubeService()
|
||||
.getInterfaceSummaryHour(date, date);
|
||||
Assert.assertNotNull(results);
|
||||
System.out.println(results);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user