77import org .joor .Reflect ;
88
99import com .google .common .collect .Lists ;
10+ import com .google .gson .JsonObject ;
1011
1112import me .chanjar .weixin .common .annotation .Required ;
1213import me .chanjar .weixin .common .bean .result .WxError ;
1314import me .chanjar .weixin .common .exception .WxErrorException ;
1415import me .chanjar .weixin .mp .api .WxMpService ;
1516import me .chanjar .weixin .mp .api .WxMpStoreService ;
16- import me .chanjar .weixin .mp .bean .WxMpStoreBaseInfo ;
17+ import me .chanjar .weixin .mp .bean .store .WxMpStoreBaseInfo ;
18+ import me .chanjar .weixin .mp .bean .store .WxMpStoreInfo ;
19+ import me .chanjar .weixin .mp .bean .store .WxMpStoreListResult ;
1720
1821/**
1922 * Created by Binary Wang on 2016/9/26.
2023 * @author binarywang (https://github.com/binarywang)
2124 *
2225 */
2326public class WxMpStoreServiceImpl implements WxMpStoreService {
27+ private static final String API_BASE_URL = "http://api.weixin.qq.com/cgi-bin/poi" ;
2428
2529 private WxMpService wxMpService ;
2630
@@ -32,10 +36,8 @@ public WxMpStoreServiceImpl(WxMpService wxMpService) {
3236 public void add (WxMpStoreBaseInfo request ) throws WxErrorException {
3337 checkParameters (request );
3438
35- String url = "http://api.weixin.qq.com/cgi-bin/poi/addpoi" ;
36- // String data = "{\"business\":{\"base_info\":{\"business_name\":\"haha\",\"branch_name\":\"abc\",\"province\":\"aaa\",\"city\":\"aaa\",\"district\":\"aaa\",\"telephone\":\"122\",\"categories\":\"adsdas\",\"offset_type\":\"1\",\"longitude\":\"115.32375\",\"latitude\":\"25.097486\"}}}";
39+ String url = API_BASE_URL + "/addpoi" ;
3740 String response = this .wxMpService .post (url , request .toJson ());
38- // String response = this.wxMpService.post(url, data);
3941 WxError wxError = WxError .fromJson (response );
4042 if (wxError .getErrorCode () != 0 ) {
4143 throw new WxErrorException (wxError );
@@ -64,4 +66,50 @@ private void checkParameters(WxMpStoreBaseInfo request) {
6466
6567 }
6668
69+ @ Override
70+ public List <WxMpStoreInfo > list (int begin , int limit )
71+ throws WxErrorException {
72+ String url = API_BASE_URL + "/getpoilist" ;
73+ JsonObject params = new JsonObject ();
74+ params .addProperty ("begin" , begin );
75+ params .addProperty ("limit" , limit );
76+ String response = this .wxMpService .post (url , params .toString ());
77+
78+ WxError wxError = WxError .fromJson (response );
79+ if (wxError .getErrorCode () != 0 ) {
80+ throw new WxErrorException (wxError );
81+ }
82+
83+ return WxMpStoreListResult .fromJson (response ).getBusinessList ();
84+ }
85+
86+ @ Override
87+ 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 ());
110+ }
111+
112+ return stores ;
113+ }
114+
67115}
0 commit comments