diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpDataCubeService.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpDataCubeService.java index 84dd59783..32f219d51 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpDataCubeService.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpDataCubeService.java @@ -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 getUpstreamMsgDistMonth(Date beginDate, Date endDate) throws WxErrorException; + + //*******************接口分析数据接口***********************// + /** + *
+   * 获取接口分析数据(getinterfacesummary)
+   * 详情请见文档:接口分析数据接口
+   * 接口url格式:https://api.weixin.qq.com/datacube/getinterfacesummary?access_token=ACCESS_TOKEN
+   *
+   * @param beginDate 开始时间
+   * @param endDate   最大时间跨度30天,endDate不能早于begingDate
+   */
+  List getInterfaceSummary(Date beginDate, Date endDate) throws WxErrorException;
+
+  /**
+   * 
+   * 获取接口分析分时数据(getinterfacesummaryhour)
+   * 详情请见文档:接口分析数据接口
+   * 接口url格式:https://api.weixin.qq.com/datacube/getinterfacesummaryhour?access_token=ACCESS_TOKEN
+   *
+   * @param beginDate 开始时间
+   * @param endDate   最大时间跨度1天,endDate不能早于begingDate
+   */
+  List getInterfaceSummaryHour(Date beginDate, Date endDate) throws WxErrorException;
+
 }
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpDataCubeServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpDataCubeServiceImpl.java
index a9e8fa50e..092d6af16 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpDataCubeServiceImpl.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpDataCubeServiceImpl.java
@@ -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>() {
             }.getType());
   }
+
+  @Override
+  public List 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>() {
+            }.getType());
+  }
+
+  @Override
+  public List 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>() {
+            }.getType());
+  }
 }
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/datacube/WxDataCubeInterfaceResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/datacube/WxDataCubeInterfaceResult.java
new file mode 100644
index 000000000..4abbe2779
--- /dev/null
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/datacube/WxDataCubeInterfaceResult.java
@@ -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;
+  }
+ 
+}
diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpDataCubeServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpDataCubeServiceImplTest.java
index 39221eab0..bfb8cf584 100644
--- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpDataCubeServiceImplTest.java
+++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpDataCubeServiceImplTest.java
@@ -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 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 results = this.wxService.getDataCubeService()
+        .getInterfaceSummaryHour(date, date);
+    Assert.assertNotNull(results);
+    System.out.println(results);
+  }
 }