1
1
package me .chanjar .weixin .mp .api .impl ;
2
2
3
- import java .util .Date ;
4
- import java .util .List ;
5
-
6
3
import com .google .gson .JsonObject ;
7
4
import com .google .gson .JsonParser ;
8
5
import com .google .gson .reflect .TypeToken ;
9
-
10
6
import me .chanjar .weixin .common .exception .WxErrorException ;
11
7
import me .chanjar .weixin .mp .api .WxMpDataCubeService ;
12
8
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 ;
15
13
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 ;
16
19
17
20
/**
18
21
* Created by Binary Wang on 2016/8/23.
19
22
* @author binarywang (https://github.com/binarywang)
20
23
*/
21
24
public class WxMpDataCubeServiceImpl implements WxMpDataCubeService {
25
+ protected final Logger log = LoggerFactory .getLogger (WxMpServiceImpl .class );
26
+
22
27
private static final String API_URL_PREFIX = "https://api.weixin.qq.com/datacube" ;
23
28
private WxMpService wxMpService ;
24
29
@@ -27,26 +32,106 @@ public WxMpDataCubeServiceImpl(WxMpService wxMpService) {
27
32
}
28
33
29
34
@ Override
30
- public List <WxMpUserSummary > getUserSummary (Date beginDate , Date endDate ) throws WxErrorException {
35
+ public List <WxDataCubeUserSummary > getUserSummary (Date beginDate , Date endDate ) throws WxErrorException {
31
36
String url = API_URL_PREFIX + "/getusersummary" ;
32
37
JsonObject param = new JsonObject ();
33
38
param .addProperty ("begin_date" , WxMpService .SIMPLE_DATE_FORMAT .format (beginDate ));
34
39
param .addProperty ("end_date" , WxMpService .SIMPLE_DATE_FORMAT .format (endDate ));
35
40
String responseContent = this .wxMpService .post (url , param .toString ());
41
+ this .log .debug ("\n url:{}\n params:{}\n response:{}" ,url , param , responseContent );
36
42
return WxMpGsonBuilder .INSTANCE .create ().fromJson (new JsonParser ().parse (responseContent ).getAsJsonObject ().get ("list" ),
37
- new TypeToken <List <WxMpUserSummary >>() {
43
+ new TypeToken <List <WxDataCubeUserSummary >>() {
38
44
}.getType ());
39
45
}
40
46
41
47
@ Override
42
- public List <WxMpUserCumulate > getUserCumulate (Date beginDate , Date endDate ) throws WxErrorException {
48
+ public List <WxDataCubeUserCumulate > getUserCumulate (Date beginDate , Date endDate ) throws WxErrorException {
43
49
String url = API_URL_PREFIX + "/getusercumulate" ;
44
50
JsonObject param = new JsonObject ();
45
51
param .addProperty ("begin_date" , WxMpService .SIMPLE_DATE_FORMAT .format (beginDate ));
46
52
param .addProperty ("end_date" , WxMpService .SIMPLE_DATE_FORMAT .format (endDate ));
47
53
String responseContent = this .wxMpService .post (url , param .toString ());
54
+ this .log .debug ("\n url:{}\n params:{}\n response:{}" ,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 ("\n url:{}\n params:{}\n response:{}" ,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 ("\n url:{}\n params:{}\n response:{}" ,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 ("\n url:{}\n params:{}\n response:{}" ,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 ("\n url:{}\n params:{}\n response:{}" ,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 ("\n url:{}\n params:{}\n response:{}" ,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 ("\n url:{}\n params:{}\n response:{}" ,url , param , responseContent );
48
133
return WxMpGsonBuilder .INSTANCE .create ().fromJson (new JsonParser ().parse (responseContent ).getAsJsonObject ().get ("list" ),
49
- new TypeToken <List <WxMpUserCumulate >>() {
134
+ new TypeToken <List <WxDataCubeArticleResult >>() {
50
135
}.getType ());
51
136
}
52
137
}
0 commit comments