Skip to content

Commit 14fb63d

Browse files
committed
添加图文分析数据接口
1 parent f0cd7dd commit 14fb63d

File tree

11 files changed

+566
-128
lines changed

11 files changed

+566
-128
lines changed

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

Lines changed: 79 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
package me.chanjar.weixin.mp.api;
22

33
import me.chanjar.weixin.common.exception.WxErrorException;
4-
import me.chanjar.weixin.mp.bean.result.WxMpUserCumulate;
5-
import me.chanjar.weixin.mp.bean.result.WxMpUserSummary;
4+
import me.chanjar.weixin.mp.bean.datacube.WxDataCubeArticleResult;
5+
import me.chanjar.weixin.mp.bean.datacube.WxDataCubeArticleTotal;
6+
import me.chanjar.weixin.mp.bean.datacube.WxDataCubeUserCumulate;
7+
import me.chanjar.weixin.mp.bean.datacube.WxDataCubeUserSummary;
68

79
import java.util.Date;
810
import java.util.List;
911

1012
/**
11-
* 统计分析相关接口
13+
* 统计分析相关接口
1214
* Created by Binary Wang on 2016/8/23.
1315
* @author binarywang (https://github.com/binarywang)
1416
*/
1517
public interface WxMpDataCubeService {
18+
//*******************用户分析数据接口***********************//
19+
1620
/**
1721
* <pre>
1822
* 获取用户增减数据
@@ -23,7 +27,7 @@ public interface WxMpDataCubeService {
2327
* @param beginDate 开始时间
2428
* @param endDate 最大时间跨度7天,endDate不能早于begingDate
2529
*/
26-
List<WxMpUserSummary> getUserSummary(Date beginDate, Date endDate) throws WxErrorException;
30+
List<WxDataCubeUserSummary> getUserSummary(Date beginDate, Date endDate) throws WxErrorException;
2731

2832
/**
2933
* <pre>
@@ -35,5 +39,75 @@ public interface WxMpDataCubeService {
3539
* @param beginDate 开始时间
3640
* @param endDate 最大时间跨度7天,endDate不能早于begingDate
3741
*/
38-
List<WxMpUserCumulate> getUserCumulate(Date beginDate, Date endDate) throws WxErrorException;
42+
List<WxDataCubeUserCumulate> getUserCumulate(Date beginDate, Date endDate) throws WxErrorException;
43+
44+
//*******************图文分析数据接口***********************//
45+
46+
/**
47+
* <pre>
48+
* 获取图文群发每日数据(getarticlesummary)
49+
* 详情请见文档:<a href="http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141084&token=&lang=zh_CN">图文分析数据接口</a>
50+
* 接口url格式:https://api.weixin.qq.com/datacube/getarticlesummary?access_token=ACCESS_TOKEN
51+
* </pre>
52+
*
53+
* @param beginDate 开始时间
54+
* @param endDate 最大时间跨度1天,endDate不能早于begingDate
55+
*/
56+
List<WxDataCubeArticleResult> getArticleSummary(Date beginDate, Date endDate) throws WxErrorException;
57+
58+
/**
59+
* <pre>
60+
* 获取图文群发总数据(getarticletotal)
61+
* 详情请见文档:<a href="http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141084&token=&lang=zh_CN">图文分析数据接口</a>
62+
* 接口url格式:https://api.weixin.qq.com/datacube/getarticletotal?access_token=ACCESS_TOKEN
63+
*
64+
* @param beginDate 开始时间
65+
* @param endDate 最大时间跨度1天,endDate不能早于begingDate
66+
*/
67+
List<WxDataCubeArticleTotal> getArticleTotal(Date beginDate, Date endDate) throws WxErrorException;
68+
69+
/**
70+
* <pre>
71+
* 获取图文统计数据(getuserread)
72+
* 详情请见文档:<a href="http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141084&token=&lang=zh_CN">图文分析数据接口</a>
73+
* 接口url格式:https://api.weixin.qq.com/datacube/getuserread?access_token=ACCESS_TOKEN
74+
*
75+
* @param beginDate 开始时间
76+
* @param endDate 最大时间跨度3天,endDate不能早于begingDate
77+
*/
78+
List<WxDataCubeArticleResult> getUserRead(Date beginDate, Date endDate) throws WxErrorException;
79+
80+
/**
81+
* <pre>
82+
* 获取图文统计分时数据(getuserreadhour)
83+
* 详情请见文档:<a href="http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141084&token=&lang=zh_CN">图文分析数据接口</a>
84+
* 接口url格式:https://api.weixin.qq.com/datacube/getuserreadhour?access_token=ACCESS_TOKEN
85+
*
86+
* @param beginDate 开始时间
87+
* @param endDate 最大时间跨度1天,endDate不能早于begingDate
88+
*/
89+
List<WxDataCubeArticleResult> getUserReadHour(Date beginDate, Date endDate) throws WxErrorException;
90+
91+
/**
92+
* <pre>
93+
* 获取图文分享转发数据(getusershare)
94+
* 详情请见文档:<a href="http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141084&token=&lang=zh_CN">图文分析数据接口</a>
95+
* 接口url格式:https://api.weixin.qq.com/datacube/getusershare?access_token=ACCESS_TOKEN
96+
*
97+
* @param beginDate 开始时间
98+
* @param endDate 最大时间跨度7天,endDate不能早于begingDate
99+
*/
100+
List<WxDataCubeArticleResult> getUserShare(Date beginDate, Date endDate) throws WxErrorException;
101+
102+
/**
103+
* <pre>
104+
* 获取图文分享转发分时数据(getusersharehour)
105+
* 详情请见文档:<a href="http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141084&token=&lang=zh_CN">图文分析数据接口</a>
106+
* 接口url格式:https://api.weixin.qq.com/datacube/getusersharehour?access_token=ACCESS_TOKEN
107+
*
108+
* @param beginDate 开始时间
109+
* @param endDate 最大时间跨度1天,endDate不能早于begingDate
110+
*/
111+
List<WxDataCubeArticleResult> getUserShareHour(Date beginDate, Date endDate) throws WxErrorException;
112+
39113
}
Lines changed: 95 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,29 @@
11
package me.chanjar.weixin.mp.api.impl;
22

3-
import java.util.Date;
4-
import java.util.List;
5-
63
import com.google.gson.JsonObject;
74
import com.google.gson.JsonParser;
85
import com.google.gson.reflect.TypeToken;
9-
106
import me.chanjar.weixin.common.exception.WxErrorException;
117
import me.chanjar.weixin.mp.api.WxMpDataCubeService;
128
import me.chanjar.weixin.mp.api.WxMpService;
13-
import me.chanjar.weixin.mp.bean.result.WxMpUserCumulate;
14-
import me.chanjar.weixin.mp.bean.result.WxMpUserSummary;
9+
import me.chanjar.weixin.mp.bean.datacube.WxDataCubeArticleResult;
10+
import me.chanjar.weixin.mp.bean.datacube.WxDataCubeArticleTotal;
11+
import me.chanjar.weixin.mp.bean.datacube.WxDataCubeUserCumulate;
12+
import me.chanjar.weixin.mp.bean.datacube.WxDataCubeUserSummary;
1513
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
14+
import org.slf4j.Logger;
15+
import org.slf4j.LoggerFactory;
16+
17+
import java.util.Date;
18+
import java.util.List;
1619

1720
/**
1821
* Created by Binary Wang on 2016/8/23.
1922
* @author binarywang (https://github.com/binarywang)
2023
*/
2124
public class WxMpDataCubeServiceImpl implements WxMpDataCubeService {
25+
protected final Logger log = LoggerFactory.getLogger(WxMpServiceImpl.class);
26+
2227
private static final String API_URL_PREFIX = "https://api.weixin.qq.com/datacube";
2328
private WxMpService wxMpService;
2429

@@ -27,26 +32,106 @@ public WxMpDataCubeServiceImpl(WxMpService wxMpService) {
2732
}
2833

2934
@Override
30-
public List<WxMpUserSummary> getUserSummary(Date beginDate, Date endDate) throws WxErrorException {
35+
public List<WxDataCubeUserSummary> getUserSummary(Date beginDate, Date endDate) throws WxErrorException {
3136
String url = API_URL_PREFIX + "/getusersummary";
3237
JsonObject param = new JsonObject();
3338
param.addProperty("begin_date", WxMpService.SIMPLE_DATE_FORMAT.format(beginDate));
3439
param.addProperty("end_date", WxMpService.SIMPLE_DATE_FORMAT.format(endDate));
3540
String responseContent = this.wxMpService.post(url, param.toString());
41+
this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent);
3642
return WxMpGsonBuilder.INSTANCE.create().fromJson(new JsonParser().parse(responseContent).getAsJsonObject().get("list"),
37-
new TypeToken<List<WxMpUserSummary>>() {
43+
new TypeToken<List<WxDataCubeUserSummary>>() {
3844
}.getType());
3945
}
4046

4147
@Override
42-
public List<WxMpUserCumulate> getUserCumulate(Date beginDate, Date endDate) throws WxErrorException {
48+
public List<WxDataCubeUserCumulate> getUserCumulate(Date beginDate, Date endDate) throws WxErrorException {
4349
String url = API_URL_PREFIX + "/getusercumulate";
4450
JsonObject param = new JsonObject();
4551
param.addProperty("begin_date", WxMpService.SIMPLE_DATE_FORMAT.format(beginDate));
4652
param.addProperty("end_date", WxMpService.SIMPLE_DATE_FORMAT.format(endDate));
4753
String responseContent = this.wxMpService.post(url, param.toString());
54+
this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent);
55+
return WxMpGsonBuilder.INSTANCE.create().fromJson(new JsonParser().parse(responseContent).getAsJsonObject().get("list"),
56+
new TypeToken<List<WxDataCubeUserCumulate>>() {
57+
}.getType());
58+
}
59+
60+
@Override
61+
public List<WxDataCubeArticleResult> getArticleSummary(Date beginDate, Date endDate) throws WxErrorException {
62+
String url = API_URL_PREFIX + "/getarticlesummary";
63+
JsonObject param = new JsonObject();
64+
param.addProperty("begin_date", WxMpService.SIMPLE_DATE_FORMAT.format(beginDate));
65+
param.addProperty("end_date", WxMpService.SIMPLE_DATE_FORMAT.format(endDate));
66+
String responseContent = this.wxMpService.post(url, param.toString());
67+
this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent);
68+
return WxMpGsonBuilder.INSTANCE.create().fromJson(new JsonParser().parse(responseContent).getAsJsonObject().get("list"),
69+
new TypeToken<List<WxDataCubeArticleResult>>() {
70+
}.getType());
71+
}
72+
73+
@Override
74+
public List<WxDataCubeArticleTotal> getArticleTotal(Date beginDate, Date endDate) throws WxErrorException {
75+
String url = API_URL_PREFIX + "/getarticletotal";
76+
JsonObject param = new JsonObject();
77+
param.addProperty("begin_date", WxMpService.SIMPLE_DATE_FORMAT.format(beginDate));
78+
param.addProperty("end_date", WxMpService.SIMPLE_DATE_FORMAT.format(endDate));
79+
String responseContent = this.wxMpService.post(url, param.toString());
80+
this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent);
81+
return WxMpGsonBuilder.INSTANCE.create().fromJson(new JsonParser().parse(responseContent).getAsJsonObject().get("list"),
82+
new TypeToken<List<WxDataCubeArticleTotal>>() {
83+
}.getType());
84+
}
85+
86+
@Override
87+
public List<WxDataCubeArticleResult> getUserRead(Date beginDate, Date endDate) throws WxErrorException {
88+
String url = API_URL_PREFIX + "/getuserread";
89+
JsonObject param = new JsonObject();
90+
param.addProperty("begin_date", WxMpService.SIMPLE_DATE_FORMAT.format(beginDate));
91+
param.addProperty("end_date", WxMpService.SIMPLE_DATE_FORMAT.format(endDate));
92+
String responseContent = this.wxMpService.post(url, param.toString());
93+
this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent);
94+
return WxMpGsonBuilder.INSTANCE.create().fromJson(new JsonParser().parse(responseContent).getAsJsonObject().get("list"),
95+
new TypeToken<List<WxDataCubeArticleResult>>() {
96+
}.getType());
97+
}
98+
99+
@Override
100+
public List<WxDataCubeArticleResult> getUserReadHour(Date beginDate, Date endDate) throws WxErrorException {
101+
String url = API_URL_PREFIX + "/getuserreadhour";
102+
JsonObject param = new JsonObject();
103+
param.addProperty("begin_date", WxMpService.SIMPLE_DATE_FORMAT.format(beginDate));
104+
param.addProperty("end_date", WxMpService.SIMPLE_DATE_FORMAT.format(endDate));
105+
String responseContent = this.wxMpService.post(url, param.toString());
106+
this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent);
107+
return WxMpGsonBuilder.INSTANCE.create().fromJson(new JsonParser().parse(responseContent).getAsJsonObject().get("list"),
108+
new TypeToken<List<WxDataCubeArticleResult>>() {
109+
}.getType());
110+
}
111+
112+
@Override
113+
public List<WxDataCubeArticleResult> getUserShare(Date beginDate, Date endDate) throws WxErrorException {
114+
String url = API_URL_PREFIX + "/getusershare";
115+
JsonObject param = new JsonObject();
116+
param.addProperty("begin_date", WxMpService.SIMPLE_DATE_FORMAT.format(beginDate));
117+
param.addProperty("end_date", WxMpService.SIMPLE_DATE_FORMAT.format(endDate));
118+
String responseContent = this.wxMpService.post(url, param.toString());
119+
this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent);
120+
return WxMpGsonBuilder.INSTANCE.create().fromJson(new JsonParser().parse(responseContent).getAsJsonObject().get("list"),
121+
new TypeToken<List<WxDataCubeArticleResult>>() {
122+
}.getType());
123+
}
124+
125+
@Override
126+
public List<WxDataCubeArticleResult> getUserShareHour(Date beginDate, Date endDate) throws WxErrorException {
127+
String url = API_URL_PREFIX + "/getusersharehour";
128+
JsonObject param = new JsonObject();
129+
param.addProperty("begin_date", WxMpService.SIMPLE_DATE_FORMAT.format(beginDate));
130+
param.addProperty("end_date", WxMpService.SIMPLE_DATE_FORMAT.format(endDate));
131+
String responseContent = this.wxMpService.post(url, param.toString());
132+
this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent);
48133
return WxMpGsonBuilder.INSTANCE.create().fromJson(new JsonParser().parse(responseContent).getAsJsonObject().get("list"),
49-
new TypeToken<List<WxMpUserCumulate>>() {
134+
new TypeToken<List<WxDataCubeArticleResult>>() {
50135
}.getType());
51136
}
52137
}
Lines changed: 95 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,102 @@
11
package me.chanjar.weixin.mp.bean.datacube;
22

3+
import com.google.gson.annotations.SerializedName;
4+
35
/**
6+
* 图文分析数据接口返回结果对象
47
* @author binarywang(https://github.com/binarywang)
58
* Created by Binary Wang on 2016/8/24.
69
*/
7-
public class WxDataCubeArticleResult {
10+
public class WxDataCubeArticleResult 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+
* msgid
21+
* 请注意:这里的msgid实际上是由msgid(图文消息id,这也就是群发接口调用后返回的msg_data_id)和index(消息次序索引)组成, 例如12003_3, 其中12003是msgid,即一次群发的消息的id; 3为index,假设该次群发的图文消息共5个文章(因为可能为多图文),3表示5个中的第3个
22+
*/
23+
@SerializedName("msgid")
24+
private String msgId;
25+
26+
/**
27+
* title
28+
* 图文消息的标题
29+
*/
30+
@SerializedName("title")
31+
private String title;
32+
33+
/**
34+
* int_page_read_user
35+
* 图文页(点击群发图文卡片进入的页面)的阅读人数
36+
*/
37+
@SerializedName("int_page_read_user")
38+
private Integer intPageReadUser;
39+
40+
/**
41+
* int_page_read_count
42+
* 图文页的阅读次数
43+
*/
44+
@SerializedName("int_page_read_count")
45+
private Integer intPageReadCount;
46+
47+
/**
48+
* ori_page_read_user
49+
* 原文页(点击图文页“阅读原文”进入的页面)的阅读人数,无原文页时此处数据为0
50+
*/
51+
@SerializedName("ori_page_read_user")
52+
private Integer oriPageReadUser;
53+
54+
/**
55+
* ori_page_read_count
56+
* 原文页的阅读次数
57+
*/
58+
@SerializedName("ori_page_read_count")
59+
private Integer oriPageReadCount;
60+
61+
/**
62+
* share_scene
63+
* 分享的场景 1代表好友转发 2代表朋友圈 3代表腾讯微博 255代表其他
64+
*/
65+
@SerializedName("share_scene")
66+
private Integer shareScene;
67+
68+
/**
69+
* share_user
70+
* 分享的人数
71+
*/
72+
@SerializedName("share_user")
73+
private Integer shareUser;
74+
75+
/**
76+
* share_count
77+
* 分享的次数
78+
*/
79+
@SerializedName("share_count")
80+
private Integer shareCount;
81+
82+
/**
83+
* add_to_fav_user
84+
* 收藏的人数
85+
*/
86+
@SerializedName("add_to_fav_user")
87+
private Integer addToFavUser;
88+
89+
/**
90+
* add_to_fav_count
91+
* 收藏的次数
92+
*/
93+
@SerializedName("add_to_fav_count")
94+
private Integer addToFavCount;
95+
96+
/**
97+
* user_source
98+
* 在获取图文阅读分时数据时才有该字段,代表用户从哪里进入来阅读该图文。0:会话;1.好友;2.朋友圈;3.腾讯微博;4.历史消息页;5.其他
99+
*/
100+
@SerializedName("user_source")
101+
private Integer userSource;
8102
}

0 commit comments

Comments
 (0)