Skip to content

Commit af9bfa2

Browse files
committed
添加接口分析数据接口
1 parent 4a994ea commit af9bfa2

File tree

4 files changed

+169
-11
lines changed

4 files changed

+169
-11
lines changed

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpDataCubeService.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import me.chanjar.weixin.common.exception.WxErrorException;
44
import me.chanjar.weixin.mp.bean.datacube.WxDataCubeArticleResult;
55
import me.chanjar.weixin.mp.bean.datacube.WxDataCubeArticleTotal;
6+
import me.chanjar.weixin.mp.bean.datacube.WxDataCubeInterfaceResult;
67
import me.chanjar.weixin.mp.bean.datacube.WxDataCubeMsgResult;
78
import me.chanjar.weixin.mp.bean.datacube.WxDataCubeUserCumulate;
89
import me.chanjar.weixin.mp.bean.datacube.WxDataCubeUserSummary;
@@ -189,4 +190,28 @@ public interface WxMpDataCubeService {
189190
* @param endDate 最大时间跨度30天,endDate不能早于begingDate
190191
*/
191192
List<WxDataCubeMsgResult> getUpstreamMsgDistMonth(Date beginDate, Date endDate) throws WxErrorException;
193+
194+
//*******************接口分析数据接口***********************//
195+
/**
196+
* <pre>
197+
* 获取接口分析数据(getinterfacesummary)
198+
* 详情请见文档:<a href="http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141086&token=&lang=zh_CN">接口分析数据接口</a>
199+
* 接口url格式:https://api.weixin.qq.com/datacube/getinterfacesummary?access_token=ACCESS_TOKEN
200+
*
201+
* @param beginDate 开始时间
202+
* @param endDate 最大时间跨度30天,endDate不能早于begingDate
203+
*/
204+
List<WxDataCubeInterfaceResult> getInterfaceSummary(Date beginDate, Date endDate) throws WxErrorException;
205+
206+
/**
207+
* <pre>
208+
* 获取接口分析分时数据(getinterfacesummaryhour)
209+
* 详情请见文档:<a href="http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141086&token=&lang=zh_CN">接口分析数据接口</a>
210+
* 接口url格式:https://api.weixin.qq.com/datacube/getinterfacesummaryhour?access_token=ACCESS_TOKEN
211+
*
212+
* @param beginDate 开始时间
213+
* @param endDate 最大时间跨度1天,endDate不能早于begingDate
214+
*/
215+
List<WxDataCubeInterfaceResult> getInterfaceSummaryHour(Date beginDate, Date endDate) throws WxErrorException;
216+
192217
}

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpDataCubeServiceImpl.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import me.chanjar.weixin.mp.api.WxMpService;
99
import me.chanjar.weixin.mp.bean.datacube.WxDataCubeArticleResult;
1010
import me.chanjar.weixin.mp.bean.datacube.WxDataCubeArticleTotal;
11+
import me.chanjar.weixin.mp.bean.datacube.WxDataCubeInterfaceResult;
1112
import me.chanjar.weixin.mp.bean.datacube.WxDataCubeMsgResult;
1213
import me.chanjar.weixin.mp.bean.datacube.WxDataCubeUserCumulate;
1314
import me.chanjar.weixin.mp.bean.datacube.WxDataCubeUserSummary;
@@ -233,4 +234,32 @@ public List<WxDataCubeMsgResult> getUpstreamMsgDistMonth(Date beginDate,
233234
new TypeToken<List<WxDataCubeMsgResult>>() {
234235
}.getType());
235236
}
237+
238+
@Override
239+
public List<WxDataCubeInterfaceResult> getInterfaceSummary(Date beginDate,
240+
Date endDate) throws WxErrorException {
241+
String url = API_URL_PREFIX + "/getinterfacesummary";
242+
JsonObject param = new JsonObject();
243+
param.addProperty("begin_date", WxMpService.SIMPLE_DATE_FORMAT.format(beginDate));
244+
param.addProperty("end_date", WxMpService.SIMPLE_DATE_FORMAT.format(endDate));
245+
String responseContent = this.wxMpService.post(url, param.toString());
246+
this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent);
247+
return WxMpGsonBuilder.INSTANCE.create().fromJson(new JsonParser().parse(responseContent).getAsJsonObject().get("list"),
248+
new TypeToken<List<WxDataCubeInterfaceResult>>() {
249+
}.getType());
250+
}
251+
252+
@Override
253+
public List<WxDataCubeInterfaceResult> getInterfaceSummaryHour(Date beginDate,
254+
Date endDate) throws WxErrorException {
255+
String url = API_URL_PREFIX + "/getinterfacesummaryhour";
256+
JsonObject param = new JsonObject();
257+
param.addProperty("begin_date", WxMpService.SIMPLE_DATE_FORMAT.format(beginDate));
258+
param.addProperty("end_date", WxMpService.SIMPLE_DATE_FORMAT.format(endDate));
259+
String responseContent = this.wxMpService.post(url, param.toString());
260+
this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent);
261+
return WxMpGsonBuilder.INSTANCE.create().fromJson(new JsonParser().parse(responseContent).getAsJsonObject().get("list"),
262+
new TypeToken<List<WxDataCubeInterfaceResult>>() {
263+
}.getType());
264+
}
236265
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
package me.chanjar.weixin.mp.bean.datacube;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
5+
/**
6+
* 接口分析数据接口返回结果对象
7+
* @author binarywang(https://github.com/binarywang)
8+
* Created by Binary Wang on 2016/8/30.
9+
*/
10+
public class WxDataCubeInterfaceResult extends WxDataCubeBaseResult {
11+
12+
/**
13+
* ref_hour
14+
* 数据的小时,包括从000到2300,分别代表的是[000,100)到[2300,2400),即每日的第1小时和最后1小时
15+
*/
16+
@SerializedName("ref_hour")
17+
private Integer refHour;
18+
19+
/**
20+
* callback_count
21+
* 通过服务器配置地址获得消息后,被动回复用户消息的次数
22+
*/
23+
@SerializedName("callback_count")
24+
private Integer callbackCount;
25+
26+
/**
27+
* fail_count
28+
* 上述动作的失败次数
29+
*/
30+
@SerializedName("fail_count")
31+
private Integer failCount;
32+
33+
/**
34+
* total_time_cost
35+
* 总耗时,除以callback_count即为平均耗时
36+
*/
37+
@SerializedName("total_time_cost")
38+
private Integer totalTimeCost;
39+
40+
/**
41+
* max_time_cost
42+
* 最大耗时
43+
*/
44+
@SerializedName("max_time_cost")
45+
private Integer maxTimeCost;
46+
47+
public Integer getRefHour() {
48+
return this.refHour;
49+
}
50+
51+
public void setRefHour(Integer refHour) {
52+
this.refHour = refHour;
53+
}
54+
55+
public Integer getCallbackCount() {
56+
return this.callbackCount;
57+
}
58+
59+
public void setCallbackCount(Integer callbackCount) {
60+
this.callbackCount = callbackCount;
61+
}
62+
63+
public Integer getFailCount() {
64+
return this.failCount;
65+
}
66+
67+
public void setFailCount(Integer failCount) {
68+
this.failCount = failCount;
69+
}
70+
71+
public Integer getTotalTimeCost() {
72+
return this.totalTimeCost;
73+
}
74+
75+
public void setTotalTimeCost(Integer totalTimeCost) {
76+
this.totalTimeCost = totalTimeCost;
77+
}
78+
79+
public Integer getMaxTimeCost() {
80+
return this.maxTimeCost;
81+
}
82+
83+
public void setMaxTimeCost(Integer maxTimeCost) {
84+
this.maxTimeCost = maxTimeCost;
85+
}
86+
87+
}

weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpDataCubeServiceImplTest.java

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
11
package me.chanjar.weixin.mp.api.impl;
22

3+
import java.text.ParseException;
4+
import java.text.SimpleDateFormat;
5+
import java.util.Date;
6+
import java.util.List;
7+
8+
import org.testng.Assert;
9+
import org.testng.annotations.DataProvider;
10+
import org.testng.annotations.Guice;
11+
import org.testng.annotations.Test;
12+
313
import com.google.inject.Inject;
14+
415
import me.chanjar.weixin.common.exception.WxErrorException;
516
import me.chanjar.weixin.mp.api.ApiTestModule;
617
import me.chanjar.weixin.mp.bean.datacube.WxDataCubeArticleResult;
718
import me.chanjar.weixin.mp.bean.datacube.WxDataCubeArticleTotal;
19+
import me.chanjar.weixin.mp.bean.datacube.WxDataCubeInterfaceResult;
820
import me.chanjar.weixin.mp.bean.datacube.WxDataCubeMsgResult;
921
import me.chanjar.weixin.mp.bean.datacube.WxDataCubeUserCumulate;
1022
import me.chanjar.weixin.mp.bean.datacube.WxDataCubeUserSummary;
11-
import org.testng.Assert;
12-
import org.testng.annotations.DataProvider;
13-
import org.testng.annotations.Guice;
14-
import org.testng.annotations.Test;
15-
16-
import static org.junit.Assert.fail;
17-
18-
import java.text.ParseException;
19-
import java.text.SimpleDateFormat;
20-
import java.util.Date;
21-
import java.util.List;
2223

2324
/**
2425
* 测试统计分析相关的接口
@@ -194,4 +195,20 @@ public void testGetUpstreamMsgDistMonth(Date beginDate, Date endDate) throws WxE
194195
Assert.assertNotNull(results);
195196
System.out.println(results);
196197
}
198+
199+
@Test(dataProvider = "thirtyDays")
200+
public void testGetInterfaceSummary(Date beginDate, Date endDate) throws WxErrorException {
201+
List<WxDataCubeInterfaceResult> results = this.wxService.getDataCubeService()
202+
.getInterfaceSummary(beginDate, endDate);
203+
Assert.assertNotNull(results);
204+
System.out.println(results);
205+
}
206+
207+
@Test(dataProvider = "oneDay")
208+
public void testGetInterfaceSummaryHour(Date date) throws WxErrorException {
209+
List<WxDataCubeInterfaceResult> results = this.wxService.getDataCubeService()
210+
.getInterfaceSummaryHour(date, date);
211+
Assert.assertNotNull(results);
212+
System.out.println(results);
213+
}
197214
}

0 commit comments

Comments
 (0)