@@ -15,6 +15,13 @@ import java.util.List; | |||||
* @author <a href="https://github.com/binarywang">Binary Wang</a> | * @author <a href="https://github.com/binarywang">Binary Wang</a> | ||||
*/ | */ | ||||
public interface WxMpStoreService<H, P> { | public interface WxMpStoreService<H, P> { | ||||
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"; | |||||
/** | /** | ||||
* <pre> | * <pre> | ||||
* 创建门店 | * 创建门店 | ||||
@@ -40,7 +47,6 @@ public interface WxMpStoreService<H, P> { | |||||
* </pre> | * </pre> | ||||
* | * | ||||
* @param poiId 门店Id | * @param poiId 门店Id | ||||
* @throws WxErrorException | |||||
*/ | */ | ||||
WxMpStoreBaseInfo get(String poiId) throws WxErrorException; | WxMpStoreBaseInfo get(String poiId) throws WxErrorException; | ||||
@@ -53,7 +59,6 @@ public interface WxMpStoreService<H, P> { | |||||
* </pre> | * </pre> | ||||
* | * | ||||
* @param poiId 门店Id | * @param poiId 门店Id | ||||
* @throws WxErrorException | |||||
*/ | */ | ||||
void delete(String poiId) throws WxErrorException; | void delete(String poiId) throws WxErrorException; | ||||
@@ -67,7 +72,6 @@ public interface WxMpStoreService<H, P> { | |||||
* | * | ||||
* @param begin 开始位置,0 即为从第一条开始查询 | * @param begin 开始位置,0 即为从第一条开始查询 | ||||
* @param limit 返回数据条数,最大允许50,默认为20 | * @param limit 返回数据条数,最大允许50,默认为20 | ||||
* @throws WxErrorException | |||||
*/ | */ | ||||
WxMpStoreListResult list(int begin, int limit) throws WxErrorException; | WxMpStoreListResult list(int begin, int limit) throws WxErrorException; | ||||
@@ -78,8 +82,6 @@ public interface WxMpStoreService<H, P> { | |||||
* 详情请见: <a href="https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1444378120&token=&lang=zh_CN">微信门店接口</a> | * 详情请见: <a href="https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1444378120&token=&lang=zh_CN">微信门店接口</a> | ||||
* 接口格式:http://api.weixin.qq.com/cgi-bin/poi/getpoilist?access_token=TOKEN | * 接口格式:http://api.weixin.qq.com/cgi-bin/poi/getpoilist?access_token=TOKEN | ||||
* </pre> | * </pre> | ||||
* | |||||
* @throws WxErrorException | |||||
*/ | */ | ||||
List<WxMpStoreInfo> listAll() throws WxErrorException; | List<WxMpStoreInfo> listAll() throws WxErrorException; | ||||
@@ -90,8 +92,6 @@ public interface WxMpStoreService<H, P> { | |||||
* 详情请见: <a href="https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1444378120&token=&lang=zh_CN">微信门店接口</a> | * 详情请见: <a href="https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1444378120&token=&lang=zh_CN">微信门店接口</a> | ||||
* 接口格式:http://api.weixin.qq.com/cgi-bin/poi/updatepoi?access_token=TOKEN | * 接口格式:http://api.weixin.qq.com/cgi-bin/poi/updatepoi?access_token=TOKEN | ||||
* </pre> | * </pre> | ||||
* | |||||
* @throws WxErrorException | |||||
*/ | */ | ||||
void update(WxMpStoreBaseInfo info) throws WxErrorException; | void update(WxMpStoreBaseInfo info) throws WxErrorException; | ||||
@@ -102,8 +102,6 @@ public interface WxMpStoreService<H, P> { | |||||
* 详情请见: <a href="https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1444378120&token=&lang=zh_CN">微信门店接口</a> | * 详情请见: <a href="https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1444378120&token=&lang=zh_CN">微信门店接口</a> | ||||
* 接口格式:http://api.weixin.qq.com/cgi-bin/poi/getwxcategory?access_token=TOKEN | * 接口格式:http://api.weixin.qq.com/cgi-bin/poi/getwxcategory?access_token=TOKEN | ||||
* </pre> | * </pre> | ||||
* | |||||
* @throws WxErrorException | |||||
*/ | */ | ||||
List<String> listCategories() throws WxErrorException; | List<String> listCategories() throws WxErrorException; | ||||
@@ -21,8 +21,6 @@ import java.util.List; | |||||
* @author binarywang (https://github.com/binarywang) | * @author binarywang (https://github.com/binarywang) | ||||
*/ | */ | ||||
public class WxMpStoreServiceImpl implements WxMpStoreService { | public class WxMpStoreServiceImpl implements WxMpStoreService { | ||||
private static final String API_BASE_URL = "http://api.weixin.qq.com/cgi-bin/poi"; | |||||
private WxMpService wxMpService; | private WxMpService wxMpService; | ||||
public WxMpStoreServiceImpl(WxMpService wxMpService) { | public WxMpStoreServiceImpl(WxMpService wxMpService) { | ||||
@@ -33,8 +31,7 @@ public class WxMpStoreServiceImpl implements WxMpStoreService { | |||||
public void add(WxMpStoreBaseInfo request) throws WxErrorException { | public void add(WxMpStoreBaseInfo request) throws WxErrorException { | ||||
BeanUtils.checkRequiredFields(request); | 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); | WxError wxError = WxError.fromJson(response); | ||||
if (wxError.getErrorCode() != 0) { | if (wxError.getErrorCode() != 0) { | ||||
throw new WxErrorException(wxError); | throw new WxErrorException(wxError); | ||||
@@ -43,10 +40,9 @@ public class WxMpStoreServiceImpl implements WxMpStoreService { | |||||
@Override | @Override | ||||
public WxMpStoreBaseInfo get(String poiId) throws WxErrorException { | public WxMpStoreBaseInfo get(String poiId) throws WxErrorException { | ||||
String url = API_BASE_URL + "/getpoi"; | |||||
JsonObject paramObject = new JsonObject(); | JsonObject paramObject = new JsonObject(); | ||||
paramObject.addProperty("poi_id", poiId); | 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); | WxError wxError = WxError.fromJson(response); | ||||
if (wxError.getErrorCode() != 0) { | if (wxError.getErrorCode() != 0) { | ||||
throw new WxErrorException(wxError); | throw new WxErrorException(wxError); | ||||
@@ -57,10 +53,9 @@ public class WxMpStoreServiceImpl implements WxMpStoreService { | |||||
@Override | @Override | ||||
public void delete(String poiId) throws WxErrorException { | public void delete(String poiId) throws WxErrorException { | ||||
String url = API_BASE_URL + "/delpoi"; | |||||
JsonObject paramObject = new JsonObject(); | JsonObject paramObject = new JsonObject(); | ||||
paramObject.addProperty("poi_id", poiId); | 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); | WxError wxError = WxError.fromJson(response); | ||||
if (wxError.getErrorCode() != 0) { | if (wxError.getErrorCode() != 0) { | ||||
throw new WxErrorException(wxError); | throw new WxErrorException(wxError); | ||||
@@ -70,11 +65,10 @@ public class WxMpStoreServiceImpl implements WxMpStoreService { | |||||
@Override | @Override | ||||
public WxMpStoreListResult list(int begin, int limit) | public WxMpStoreListResult list(int begin, int limit) | ||||
throws WxErrorException { | throws WxErrorException { | ||||
String url = API_BASE_URL + "/getpoilist"; | |||||
JsonObject params = new JsonObject(); | JsonObject params = new JsonObject(); | ||||
params.addProperty("begin", begin); | params.addProperty("begin", begin); | ||||
params.addProperty("limit", limit); | 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); | WxError wxError = WxError.fromJson(response); | ||||
if (wxError.getErrorCode() != 0) { | if (wxError.getErrorCode() != 0) { | ||||
@@ -107,8 +101,7 @@ public class WxMpStoreServiceImpl implements WxMpStoreService { | |||||
@Override | @Override | ||||
public void update(WxMpStoreBaseInfo request) throws WxErrorException { | 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); | WxError wxError = WxError.fromJson(response); | ||||
if (wxError.getErrorCode() != 0) { | if (wxError.getErrorCode() != 0) { | ||||
throw new WxErrorException(wxError); | throw new WxErrorException(wxError); | ||||
@@ -117,8 +110,7 @@ public class WxMpStoreServiceImpl implements WxMpStoreService { | |||||
@Override | @Override | ||||
public List<String> listCategories() throws WxErrorException { | public List<String> 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); | WxError wxError = WxError.fromJson(response); | ||||
if (wxError.getErrorCode() != 0) { | if (wxError.getErrorCode() != 0) { | ||||
throw new WxErrorException(wxError); | throw new WxErrorException(wxError); | ||||
@@ -26,18 +26,17 @@ public class WxMpStoreServiceImplTest { | |||||
private WxMpService wxMpService; | 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 { | public void testAdd() throws WxErrorException { | ||||
this.wxMpService.getStoreService().add(WxMpStoreBaseInfo.builder().build()); | |||||
this.wxMpService.getStoreService() | this.wxMpService.getStoreService() | ||||
.add(WxMpStoreBaseInfo.builder().businessName("haha").branchName("abc") | .add(WxMpStoreBaseInfo.builder().businessName("haha").branchName("abc") | ||||
.province("aaa").district("aaa").telephone("122").address("abc").categories(new String[]{"美食,江浙菜"}) | .province("aaa").district("aaa").telephone("122").address("abc").categories(new String[]{"美食,江浙菜"}) | ||||
.longitude(new BigDecimal("115.32375")) | .longitude(new BigDecimal("115.32375")) | ||||
.latitude(new BigDecimal("25.097486")).city("aaa").offsetType(1) | .latitude(new BigDecimal("25.097486")).city("aaa").offsetType(1) | ||||
.build()); | .build()); | ||||
// 以下运行会抛异常 | |||||
this.wxMpService.getStoreService().add(WxMpStoreBaseInfo.builder().build()); | |||||
} | } | ||||
public void testUpdate() throws WxErrorException { | public void testUpdate() throws WxErrorException { | ||||