11package me .chanjar .weixin .mp .api .impl ;
22
3+ import java .text .Format ;
4+ import java .util .Date ;
5+ import java .util .List ;
6+
7+ import org .apache .commons .lang3 .time .FastDateFormat ;
8+ import org .slf4j .Logger ;
9+ import org .slf4j .LoggerFactory ;
10+
311import com .google .gson .JsonObject ;
412import com .google .gson .JsonParser ;
513import com .google .gson .reflect .TypeToken ;
14+
615import me .chanjar .weixin .common .exception .WxErrorException ;
716import me .chanjar .weixin .mp .api .WxMpDataCubeService ;
817import me .chanjar .weixin .mp .api .WxMpService ;
1322import me .chanjar .weixin .mp .bean .datacube .WxDataCubeUserCumulate ;
1423import me .chanjar .weixin .mp .bean .datacube .WxDataCubeUserSummary ;
1524import me .chanjar .weixin .mp .util .json .WxMpGsonBuilder ;
16- import org .slf4j .Logger ;
17- import org .slf4j .LoggerFactory ;
18-
19- import java .util .Date ;
20- import java .util .List ;
2125
2226/**
2327 * Created by Binary Wang on 2016/8/23.
@@ -27,6 +31,9 @@ public class WxMpDataCubeServiceImpl implements WxMpDataCubeService {
2731 protected final Logger log = LoggerFactory .getLogger (WxMpDataCubeServiceImpl .class );
2832
2933 private static final String API_URL_PREFIX = "https://api.weixin.qq.com/datacube" ;
34+
35+ private final Format dateFormat = FastDateFormat .getInstance ("yyyy-MM-dd" );
36+
3037 private WxMpService wxMpService ;
3138
3239 public WxMpDataCubeServiceImpl (WxMpService wxMpService ) {
@@ -37,8 +44,8 @@ public WxMpDataCubeServiceImpl(WxMpService wxMpService) {
3744 public List <WxDataCubeUserSummary > getUserSummary (Date beginDate , Date endDate ) throws WxErrorException {
3845 String url = API_URL_PREFIX + "/getusersummary" ;
3946 JsonObject param = new JsonObject ();
40- param .addProperty ("begin_date" , WxMpService . SIMPLE_DATE_FORMAT .format (beginDate ));
41- param .addProperty ("end_date" , WxMpService . SIMPLE_DATE_FORMAT .format (endDate ));
47+ param .addProperty ("begin_date" , this . dateFormat .format (beginDate ));
48+ param .addProperty ("end_date" , this . dateFormat .format (endDate ));
4249 String responseContent = this .wxMpService .post (url , param .toString ());
4350 this .log .debug ("\n url:{}\n params:{}\n response:{}" ,url , param , responseContent );
4451 return WxMpGsonBuilder .INSTANCE .create ().fromJson (new JsonParser ().parse (responseContent ).getAsJsonObject ().get ("list" ),
@@ -50,8 +57,8 @@ public List<WxDataCubeUserSummary> getUserSummary(Date beginDate, Date endDate)
5057 public List <WxDataCubeUserCumulate > getUserCumulate (Date beginDate , Date endDate ) throws WxErrorException {
5158 String url = API_URL_PREFIX + "/getusercumulate" ;
5259 JsonObject param = new JsonObject ();
53- param .addProperty ("begin_date" , WxMpService . SIMPLE_DATE_FORMAT .format (beginDate ));
54- param .addProperty ("end_date" , WxMpService . SIMPLE_DATE_FORMAT .format (endDate ));
60+ param .addProperty ("begin_date" , this . dateFormat .format (beginDate ));
61+ param .addProperty ("end_date" , this . dateFormat .format (endDate ));
5562 String responseContent = this .wxMpService .post (url , param .toString ());
5663 this .log .debug ("\n url:{}\n params:{}\n response:{}" ,url , param , responseContent );
5764 return WxMpGsonBuilder .INSTANCE .create ().fromJson (new JsonParser ().parse (responseContent ).getAsJsonObject ().get ("list" ),
@@ -63,8 +70,8 @@ public List<WxDataCubeUserCumulate> getUserCumulate(Date beginDate, Date endDate
6370 public List <WxDataCubeArticleResult > getArticleSummary (Date beginDate , Date endDate ) throws WxErrorException {
6471 String url = API_URL_PREFIX + "/getarticlesummary" ;
6572 JsonObject param = new JsonObject ();
66- param .addProperty ("begin_date" , WxMpService . SIMPLE_DATE_FORMAT .format (beginDate ));
67- param .addProperty ("end_date" , WxMpService . SIMPLE_DATE_FORMAT .format (endDate ));
73+ param .addProperty ("begin_date" , this . dateFormat .format (beginDate ));
74+ param .addProperty ("end_date" , this . dateFormat .format (endDate ));
6875 String responseContent = this .wxMpService .post (url , param .toString ());
6976 this .log .debug ("\n url:{}\n params:{}\n response:{}" ,url , param , responseContent );
7077 return WxMpGsonBuilder .INSTANCE .create ().fromJson (new JsonParser ().parse (responseContent ).getAsJsonObject ().get ("list" ),
@@ -76,8 +83,8 @@ public List<WxDataCubeArticleResult> getArticleSummary(Date beginDate, Date endD
7683 public List <WxDataCubeArticleTotal > getArticleTotal (Date beginDate , Date endDate ) throws WxErrorException {
7784 String url = API_URL_PREFIX + "/getarticletotal" ;
7885 JsonObject param = new JsonObject ();
79- param .addProperty ("begin_date" , WxMpService . SIMPLE_DATE_FORMAT .format (beginDate ));
80- param .addProperty ("end_date" , WxMpService . SIMPLE_DATE_FORMAT .format (endDate ));
86+ param .addProperty ("begin_date" , this . dateFormat .format (beginDate ));
87+ param .addProperty ("end_date" , this . dateFormat .format (endDate ));
8188 String responseContent = this .wxMpService .post (url , param .toString ());
8289 this .log .debug ("\n url:{}\n params:{}\n response:{}" ,url , param , responseContent );
8390 return WxMpGsonBuilder .INSTANCE .create ().fromJson (new JsonParser ().parse (responseContent ).getAsJsonObject ().get ("list" ),
@@ -89,8 +96,8 @@ public List<WxDataCubeArticleTotal> getArticleTotal(Date beginDate, Date endDate
8996 public List <WxDataCubeArticleResult > getUserRead (Date beginDate , Date endDate ) throws WxErrorException {
9097 String url = API_URL_PREFIX + "/getuserread" ;
9198 JsonObject param = new JsonObject ();
92- param .addProperty ("begin_date" , WxMpService . SIMPLE_DATE_FORMAT .format (beginDate ));
93- param .addProperty ("end_date" , WxMpService . SIMPLE_DATE_FORMAT .format (endDate ));
99+ param .addProperty ("begin_date" , this . dateFormat .format (beginDate ));
100+ param .addProperty ("end_date" , this . dateFormat .format (endDate ));
94101 String responseContent = this .wxMpService .post (url , param .toString ());
95102 this .log .debug ("\n url:{}\n params:{}\n response:{}" ,url , param , responseContent );
96103 return WxMpGsonBuilder .INSTANCE .create ().fromJson (new JsonParser ().parse (responseContent ).getAsJsonObject ().get ("list" ),
@@ -102,8 +109,8 @@ public List<WxDataCubeArticleResult> getUserRead(Date beginDate, Date endDate) t
102109 public List <WxDataCubeArticleResult > getUserReadHour (Date beginDate , Date endDate ) throws WxErrorException {
103110 String url = API_URL_PREFIX + "/getuserreadhour" ;
104111 JsonObject param = new JsonObject ();
105- param .addProperty ("begin_date" , WxMpService . SIMPLE_DATE_FORMAT .format (beginDate ));
106- param .addProperty ("end_date" , WxMpService . SIMPLE_DATE_FORMAT .format (endDate ));
112+ param .addProperty ("begin_date" , this . dateFormat .format (beginDate ));
113+ param .addProperty ("end_date" , this . dateFormat .format (endDate ));
107114 String responseContent = this .wxMpService .post (url , param .toString ());
108115 this .log .debug ("\n url:{}\n params:{}\n response:{}" ,url , param , responseContent );
109116 return WxMpGsonBuilder .INSTANCE .create ().fromJson (new JsonParser ().parse (responseContent ).getAsJsonObject ().get ("list" ),
@@ -115,8 +122,8 @@ public List<WxDataCubeArticleResult> getUserReadHour(Date beginDate, Date endDat
115122 public List <WxDataCubeArticleResult > getUserShare (Date beginDate , Date endDate ) throws WxErrorException {
116123 String url = API_URL_PREFIX + "/getusershare" ;
117124 JsonObject param = new JsonObject ();
118- param .addProperty ("begin_date" , WxMpService . SIMPLE_DATE_FORMAT .format (beginDate ));
119- param .addProperty ("end_date" , WxMpService . SIMPLE_DATE_FORMAT .format (endDate ));
125+ param .addProperty ("begin_date" , this . dateFormat .format (beginDate ));
126+ param .addProperty ("end_date" , this . dateFormat .format (endDate ));
120127 String responseContent = this .wxMpService .post (url , param .toString ());
121128 this .log .debug ("\n url:{}\n params:{}\n response:{}" ,url , param , responseContent );
122129 return WxMpGsonBuilder .INSTANCE .create ().fromJson (new JsonParser ().parse (responseContent ).getAsJsonObject ().get ("list" ),
@@ -128,8 +135,8 @@ public List<WxDataCubeArticleResult> getUserShare(Date beginDate, Date endDate)
128135 public List <WxDataCubeArticleResult > getUserShareHour (Date beginDate , Date endDate ) throws WxErrorException {
129136 String url = API_URL_PREFIX + "/getusersharehour" ;
130137 JsonObject param = new JsonObject ();
131- param .addProperty ("begin_date" , WxMpService . SIMPLE_DATE_FORMAT .format (beginDate ));
132- param .addProperty ("end_date" , WxMpService . SIMPLE_DATE_FORMAT .format (endDate ));
138+ param .addProperty ("begin_date" , this . dateFormat .format (beginDate ));
139+ param .addProperty ("end_date" , this . dateFormat .format (endDate ));
133140 String responseContent = this .wxMpService .post (url , param .toString ());
134141 this .log .debug ("\n url:{}\n params:{}\n response:{}" ,url , param , responseContent );
135142 return WxMpGsonBuilder .INSTANCE .create ().fromJson (new JsonParser ().parse (responseContent ).getAsJsonObject ().get ("list" ),
@@ -142,8 +149,8 @@ public List<WxDataCubeMsgResult> getUpstreamMsg(Date beginDate, Date endDate)
142149 throws WxErrorException {
143150 String url = API_URL_PREFIX + "/getupstreammsg" ;
144151 JsonObject param = new JsonObject ();
145- param .addProperty ("begin_date" , WxMpService . SIMPLE_DATE_FORMAT .format (beginDate ));
146- param .addProperty ("end_date" , WxMpService . SIMPLE_DATE_FORMAT .format (endDate ));
152+ param .addProperty ("begin_date" , this . dateFormat .format (beginDate ));
153+ param .addProperty ("end_date" , this . dateFormat .format (endDate ));
147154 String responseContent = this .wxMpService .post (url , param .toString ());
148155 this .log .debug ("\n url:{}\n params:{}\n response:{}" ,url , param , responseContent );
149156 return WxMpGsonBuilder .INSTANCE .create ().fromJson (new JsonParser ().parse (responseContent ).getAsJsonObject ().get ("list" ),
@@ -156,8 +163,8 @@ public List<WxDataCubeMsgResult> getUpstreamMsgHour(Date beginDate,
156163 Date endDate ) throws WxErrorException {
157164 String url = API_URL_PREFIX + "/getupstreammsghour" ;
158165 JsonObject param = new JsonObject ();
159- param .addProperty ("begin_date" , WxMpService . SIMPLE_DATE_FORMAT .format (beginDate ));
160- param .addProperty ("end_date" , WxMpService . SIMPLE_DATE_FORMAT .format (endDate ));
166+ param .addProperty ("begin_date" , this . dateFormat .format (beginDate ));
167+ param .addProperty ("end_date" , this . dateFormat .format (endDate ));
161168 String responseContent = this .wxMpService .post (url , param .toString ());
162169 this .log .debug ("\n url:{}\n params:{}\n response:{}" ,url , param , responseContent );
163170 return WxMpGsonBuilder .INSTANCE .create ().fromJson (new JsonParser ().parse (responseContent ).getAsJsonObject ().get ("list" ),
@@ -170,8 +177,8 @@ public List<WxDataCubeMsgResult> getUpstreamMsgWeek(Date beginDate,
170177 Date endDate ) throws WxErrorException {
171178 String url = API_URL_PREFIX + "/getupstreammsgweek" ;
172179 JsonObject param = new JsonObject ();
173- param .addProperty ("begin_date" , WxMpService . SIMPLE_DATE_FORMAT .format (beginDate ));
174- param .addProperty ("end_date" , WxMpService . SIMPLE_DATE_FORMAT .format (endDate ));
180+ param .addProperty ("begin_date" , this . dateFormat .format (beginDate ));
181+ param .addProperty ("end_date" , this . dateFormat .format (endDate ));
175182 String responseContent = this .wxMpService .post (url , param .toString ());
176183 this .log .debug ("\n url:{}\n params:{}\n response:{}" ,url , param , responseContent );
177184 return WxMpGsonBuilder .INSTANCE .create ().fromJson (new JsonParser ().parse (responseContent ).getAsJsonObject ().get ("list" ),
@@ -184,8 +191,8 @@ public List<WxDataCubeMsgResult> getUpstreamMsgMonth(Date beginDate,
184191 Date endDate ) throws WxErrorException {
185192 String url = API_URL_PREFIX + "/getupstreammsgmonth" ;
186193 JsonObject param = new JsonObject ();
187- param .addProperty ("begin_date" , WxMpService . SIMPLE_DATE_FORMAT .format (beginDate ));
188- param .addProperty ("end_date" , WxMpService . SIMPLE_DATE_FORMAT .format (endDate ));
194+ param .addProperty ("begin_date" , this . dateFormat .format (beginDate ));
195+ param .addProperty ("end_date" , this . dateFormat .format (endDate ));
189196 String responseContent = this .wxMpService .post (url , param .toString ());
190197 this .log .debug ("\n url:{}\n params:{}\n response:{}" ,url , param , responseContent );
191198 return WxMpGsonBuilder .INSTANCE .create ().fromJson (new JsonParser ().parse (responseContent ).getAsJsonObject ().get ("list" ),
@@ -198,8 +205,8 @@ public List<WxDataCubeMsgResult> getUpstreamMsgDist(Date beginDate,
198205 Date endDate ) throws WxErrorException {
199206 String url = API_URL_PREFIX + "/getupstreammsgdist" ;
200207 JsonObject param = new JsonObject ();
201- param .addProperty ("begin_date" , WxMpService . SIMPLE_DATE_FORMAT .format (beginDate ));
202- param .addProperty ("end_date" , WxMpService . SIMPLE_DATE_FORMAT .format (endDate ));
208+ param .addProperty ("begin_date" , this . dateFormat .format (beginDate ));
209+ param .addProperty ("end_date" , this . dateFormat .format (endDate ));
203210 String responseContent = this .wxMpService .post (url , param .toString ());
204211 this .log .debug ("\n url:{}\n params:{}\n response:{}" ,url , param , responseContent );
205212 return WxMpGsonBuilder .INSTANCE .create ().fromJson (new JsonParser ().parse (responseContent ).getAsJsonObject ().get ("list" ),
@@ -212,8 +219,8 @@ public List<WxDataCubeMsgResult> getUpstreamMsgDistWeek(Date beginDate,
212219 Date endDate ) throws WxErrorException {
213220 String url = API_URL_PREFIX + "/getupstreammsgdistweek" ;
214221 JsonObject param = new JsonObject ();
215- param .addProperty ("begin_date" , WxMpService . SIMPLE_DATE_FORMAT .format (beginDate ));
216- param .addProperty ("end_date" , WxMpService . SIMPLE_DATE_FORMAT .format (endDate ));
222+ param .addProperty ("begin_date" , this . dateFormat .format (beginDate ));
223+ param .addProperty ("end_date" , this . dateFormat .format (endDate ));
217224 String responseContent = this .wxMpService .post (url , param .toString ());
218225 this .log .debug ("\n url:{}\n params:{}\n response:{}" ,url , param , responseContent );
219226 return WxMpGsonBuilder .INSTANCE .create ().fromJson (new JsonParser ().parse (responseContent ).getAsJsonObject ().get ("list" ),
@@ -226,8 +233,8 @@ public List<WxDataCubeMsgResult> getUpstreamMsgDistMonth(Date beginDate,
226233 Date endDate ) throws WxErrorException {
227234 String url = API_URL_PREFIX + "/getupstreammsgdistmonth" ;
228235 JsonObject param = new JsonObject ();
229- param .addProperty ("begin_date" , WxMpService . SIMPLE_DATE_FORMAT .format (beginDate ));
230- param .addProperty ("end_date" , WxMpService . SIMPLE_DATE_FORMAT .format (endDate ));
236+ param .addProperty ("begin_date" , this . dateFormat .format (beginDate ));
237+ param .addProperty ("end_date" , this . dateFormat .format (endDate ));
231238 String responseContent = this .wxMpService .post (url , param .toString ());
232239 this .log .debug ("\n url:{}\n params:{}\n response:{}" ,url , param , responseContent );
233240 return WxMpGsonBuilder .INSTANCE .create ().fromJson (new JsonParser ().parse (responseContent ).getAsJsonObject ().get ("list" ),
@@ -240,8 +247,8 @@ public List<WxDataCubeInterfaceResult> getInterfaceSummary(Date beginDate,
240247 Date endDate ) throws WxErrorException {
241248 String url = API_URL_PREFIX + "/getinterfacesummary" ;
242249 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 ));
250+ param .addProperty ("begin_date" , this . dateFormat .format (beginDate ));
251+ param .addProperty ("end_date" , this . dateFormat .format (endDate ));
245252 String responseContent = this .wxMpService .post (url , param .toString ());
246253 this .log .debug ("\n url:{}\n params:{}\n response:{}" ,url , param , responseContent );
247254 return WxMpGsonBuilder .INSTANCE .create ().fromJson (new JsonParser ().parse (responseContent ).getAsJsonObject ().get ("list" ),
@@ -254,8 +261,8 @@ public List<WxDataCubeInterfaceResult> getInterfaceSummaryHour(Date beginDate,
254261 Date endDate ) throws WxErrorException {
255262 String url = API_URL_PREFIX + "/getinterfacesummaryhour" ;
256263 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 ));
264+ param .addProperty ("begin_date" , this . dateFormat .format (beginDate ));
265+ param .addProperty ("end_date" , this . dateFormat .format (endDate ));
259266 String responseContent = this .wxMpService .post (url , param .toString ());
260267 this .log .debug ("\n url:{}\n params:{}\n response:{}" ,url , param , responseContent );
261268 return WxMpGsonBuilder .INSTANCE .create ().fromJson (new JsonParser ().parse (responseContent ).getAsJsonObject ().get ("list" ),
0 commit comments