@@ -67,7 +67,7 @@ private void checkParameters(WxMpStoreBaseInfo request) {
6767 }
6868
6969 @ Override
70- public List < WxMpStoreInfo > list (int begin , int limit )
70+ public WxMpStoreListResult list (int begin , int limit )
7171 throws WxErrorException {
7272 String url = API_BASE_URL + "/getpoilist" ;
7373 JsonObject params = new JsonObject ();
@@ -80,33 +80,25 @@ public List<WxMpStoreInfo> list(int begin, int limit)
8080 throw new WxErrorException (wxError );
8181 }
8282
83- return WxMpStoreListResult .fromJson (response ). getBusinessList () ;
83+ return WxMpStoreListResult .fromJson (response );
8484 }
8585
8686 @ Override
8787 public List <WxMpStoreInfo > listAll () throws WxErrorException {
88- int limit = 10 ;
89- String url = API_BASE_URL + "/getpoilist" ;
90- JsonObject params = new JsonObject ();
91- params .addProperty ("begin" , 0 );
92- params .addProperty ("limit" , limit );//返回数据条数,最大允许50,默认为20
93- String response = this .wxMpService .post (url , params .toString ());
94-
95- WxError wxError = WxError .fromJson (response );
96- if (wxError .getErrorCode () != 0 ) {
97- throw new WxErrorException (wxError );
98- }
99-
100- WxMpStoreListResult listResult = WxMpStoreListResult .fromJson (response );
101- List <WxMpStoreInfo > stores = Lists
102- .newArrayList (listResult .getBusinessList ());
103- if (listResult .getTotalCount () > limit ) {
104- params = new JsonObject ();
105- params .addProperty ("begin" , limit );
106- params .addProperty ("limit" , listResult .getTotalCount () - limit );
107- stores .addAll (WxMpStoreListResult
108- .fromJson (this .wxMpService .post (url , params .toString ()))
109- .getBusinessList ());
88+ int limit = 50 ;
89+ WxMpStoreListResult list = this .list (0 , limit );
90+ List <WxMpStoreInfo > stores = list .getBusinessList ();
91+ if (list .getTotalCount () > limit ) {
92+ int begin = limit ;
93+ WxMpStoreListResult followingList = this .list (begin , limit );
94+ while (followingList .getBusinessList ().size () > 0 ) {
95+ stores .addAll (followingList .getBusinessList ());
96+ begin += limit ;
97+ if (begin >= list .getTotalCount ()) {
98+ break ;
99+ }
100+ followingList = this .list (begin , limit );
101+ }
110102 }
111103
112104 return stores ;
0 commit comments