From 972b07a20f4c800dc6262579dfad4a51331c610b Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Wed, 27 Sep 2017 11:27:54 +0800 Subject: [PATCH] =?UTF-8?q?#195=20=E6=8A=BD=E5=8F=96=E9=97=A8=E5=BA=97?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E7=9B=B8=E5=85=B3=E6=8E=A5=E5=8F=A3=E8=AF=B7?= =?UTF-8?q?=E6=B1=82URL=E4=B8=BA=E5=B8=B8=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../weixin/mp/api/WxMpStoreService.java | 16 +++++++-------- .../mp/api/impl/WxMpStoreServiceImpl.java | 20 ++++++------------- .../mp/api/impl/WxMpStoreServiceImplTest.java | 7 +++---- 3 files changed, 16 insertions(+), 27 deletions(-) diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpStoreService.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpStoreService.java index d996759b0..26958c9fe 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpStoreService.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpStoreService.java @@ -15,6 +15,13 @@ import java.util.List; * @author Binary Wang */ public interface WxMpStoreService { + String POI_GET_WX_CATEGORY_URL = "https://api.weixin.qq.com/cgi-bin/poi/getwxcategory"; + String POI_UPDATE_URL = "https://api.weixin.qq.com/cgi-bin/poi/updatepoi"; + String POI_LIST_URL = "https://api.weixin.qq.com/cgi-bin/poi/getpoilist"; + String POI_DEL_URL = "https://api.weixin.qq.com/cgi-bin/poi/delpoi"; + String POI_GET_URL = "https://api.weixin.qq.com/cgi-bin/poi/getpoi"; + String POI_ADD_URL = "https://api.weixin.qq.com/cgi-bin/poi/addpoi"; + /** *
    * 创建门店
@@ -40,7 +47,6 @@ public interface WxMpStoreService {
    * 
* * @param poiId 门店Id - * @throws WxErrorException */ WxMpStoreBaseInfo get(String poiId) throws WxErrorException; @@ -53,7 +59,6 @@ public interface WxMpStoreService { * * * @param poiId 门店Id - * @throws WxErrorException */ void delete(String poiId) throws WxErrorException; @@ -67,7 +72,6 @@ public interface WxMpStoreService { * * @param begin 开始位置,0 即为从第一条开始查询 * @param limit 返回数据条数,最大允许50,默认为20 - * @throws WxErrorException */ WxMpStoreListResult list(int begin, int limit) throws WxErrorException; @@ -78,8 +82,6 @@ public interface WxMpStoreService { * 详情请见: 微信门店接口 * 接口格式:http://api.weixin.qq.com/cgi-bin/poi/getpoilist?access_token=TOKEN * - * - * @throws WxErrorException */ List listAll() throws WxErrorException; @@ -90,8 +92,6 @@ public interface WxMpStoreService { * 详情请见: 微信门店接口 * 接口格式:http://api.weixin.qq.com/cgi-bin/poi/updatepoi?access_token=TOKEN * - * - * @throws WxErrorException */ void update(WxMpStoreBaseInfo info) throws WxErrorException; @@ -102,8 +102,6 @@ public interface WxMpStoreService { * 详情请见: 微信门店接口 * 接口格式:http://api.weixin.qq.com/cgi-bin/poi/getwxcategory?access_token=TOKEN * - * - * @throws WxErrorException */ List listCategories() throws WxErrorException; diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpStoreServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpStoreServiceImpl.java index 5f1b5f2a8..00c0c1097 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpStoreServiceImpl.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpStoreServiceImpl.java @@ -21,8 +21,6 @@ import java.util.List; * @author binarywang (https://github.com/binarywang) */ public class WxMpStoreServiceImpl implements WxMpStoreService { - private static final String API_BASE_URL = "http://api.weixin.qq.com/cgi-bin/poi"; - private WxMpService wxMpService; public WxMpStoreServiceImpl(WxMpService wxMpService) { @@ -33,8 +31,7 @@ public class WxMpStoreServiceImpl implements WxMpStoreService { public void add(WxMpStoreBaseInfo request) throws WxErrorException { BeanUtils.checkRequiredFields(request); - String url = API_BASE_URL + "/addpoi"; - String response = this.wxMpService.post(url, request.toJson()); + String response = this.wxMpService.post(POI_ADD_URL, request.toJson()); WxError wxError = WxError.fromJson(response); if (wxError.getErrorCode() != 0) { throw new WxErrorException(wxError); @@ -43,10 +40,9 @@ public class WxMpStoreServiceImpl implements WxMpStoreService { @Override public WxMpStoreBaseInfo get(String poiId) throws WxErrorException { - String url = API_BASE_URL + "/getpoi"; JsonObject paramObject = new JsonObject(); paramObject.addProperty("poi_id", poiId); - String response = this.wxMpService.post(url, paramObject.toString()); + String response = this.wxMpService.post(POI_GET_URL, paramObject.toString()); WxError wxError = WxError.fromJson(response); if (wxError.getErrorCode() != 0) { throw new WxErrorException(wxError); @@ -57,10 +53,9 @@ public class WxMpStoreServiceImpl implements WxMpStoreService { @Override public void delete(String poiId) throws WxErrorException { - String url = API_BASE_URL + "/delpoi"; JsonObject paramObject = new JsonObject(); paramObject.addProperty("poi_id", poiId); - String response = this.wxMpService.post(url, paramObject.toString()); + String response = this.wxMpService.post(POI_DEL_URL, paramObject.toString()); WxError wxError = WxError.fromJson(response); if (wxError.getErrorCode() != 0) { throw new WxErrorException(wxError); @@ -70,11 +65,10 @@ public class WxMpStoreServiceImpl implements WxMpStoreService { @Override public WxMpStoreListResult list(int begin, int limit) throws WxErrorException { - String url = API_BASE_URL + "/getpoilist"; JsonObject params = new JsonObject(); params.addProperty("begin", begin); params.addProperty("limit", limit); - String response = this.wxMpService.post(url, params.toString()); + String response = this.wxMpService.post(POI_LIST_URL, params.toString()); WxError wxError = WxError.fromJson(response); if (wxError.getErrorCode() != 0) { @@ -107,8 +101,7 @@ public class WxMpStoreServiceImpl implements WxMpStoreService { @Override public void update(WxMpStoreBaseInfo request) throws WxErrorException { - String url = API_BASE_URL + "/updatepoi"; - String response = this.wxMpService.post(url, request.toJson()); + String response = this.wxMpService.post(POI_UPDATE_URL, request.toJson()); WxError wxError = WxError.fromJson(response); if (wxError.getErrorCode() != 0) { throw new WxErrorException(wxError); @@ -117,8 +110,7 @@ public class WxMpStoreServiceImpl implements WxMpStoreService { @Override public List listCategories() throws WxErrorException { - String url = API_BASE_URL + "/getwxcategory"; - String response = this.wxMpService.get(url, null); + String response = this.wxMpService.get(POI_GET_WX_CATEGORY_URL, null); WxError wxError = WxError.fromJson(response); if (wxError.getErrorCode() != 0) { throw new WxErrorException(wxError); diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpStoreServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpStoreServiceImplTest.java index c0703028d..3970072bf 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpStoreServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpStoreServiceImplTest.java @@ -26,18 +26,17 @@ public class WxMpStoreServiceImplTest { private WxMpService wxMpService; /** - * Test method for {@link WxMpStoreServiceImpl#add(me.chanjar.weixin.mp.bean.store.WxMpStoreBaseInfo)}. - * - * @throws WxErrorException + * Test method for {@link WxMpStoreServiceImpl#add(WxMpStoreBaseInfo)}. */ public void testAdd() throws WxErrorException { - this.wxMpService.getStoreService().add(WxMpStoreBaseInfo.builder().build()); this.wxMpService.getStoreService() .add(WxMpStoreBaseInfo.builder().businessName("haha").branchName("abc") .province("aaa").district("aaa").telephone("122").address("abc").categories(new String[]{"美食,江浙菜"}) .longitude(new BigDecimal("115.32375")) .latitude(new BigDecimal("25.097486")).city("aaa").offsetType(1) .build()); + // 以下运行会抛异常 + this.wxMpService.getStoreService().add(WxMpStoreBaseInfo.builder().build()); } public void testUpdate() throws WxErrorException {