11package me .chanjar .weixin .mp .api .impl ;
22
3- import java .util .Date ;
4- import java .util .List ;
5-
63import com .google .gson .JsonObject ;
74import com .google .gson .JsonParser ;
85import com .google .gson .reflect .TypeToken ;
9-
106import me .chanjar .weixin .common .exception .WxErrorException ;
117import me .chanjar .weixin .mp .api .WxMpDataCubeService ;
128import 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 ;
1513import 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 */
2124public 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 ("\n url:{}\n params:{}\n response:{}" ,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 ("\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 );
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}
0 commit comments