Skip to content

Commit 972b07a

Browse files
committed
binarywang#195 抽取门店管理相关接口请求URL为常量
1 parent ffcbb2a commit 972b07a

File tree

3 files changed

+16
-27
lines changed

3 files changed

+16
-27
lines changed

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpStoreService.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@
1515
* @author <a href="https://github.com/binarywang">Binary Wang</a>
1616
*/
1717
public interface WxMpStoreService<H, P> {
18+
String POI_GET_WX_CATEGORY_URL = "https://api.weixin.qq.com/cgi-bin/poi/getwxcategory";
19+
String POI_UPDATE_URL = "https://api.weixin.qq.com/cgi-bin/poi/updatepoi";
20+
String POI_LIST_URL = "https://api.weixin.qq.com/cgi-bin/poi/getpoilist";
21+
String POI_DEL_URL = "https://api.weixin.qq.com/cgi-bin/poi/delpoi";
22+
String POI_GET_URL = "https://api.weixin.qq.com/cgi-bin/poi/getpoi";
23+
String POI_ADD_URL = "https://api.weixin.qq.com/cgi-bin/poi/addpoi";
24+
1825
/**
1926
* <pre>
2027
* 创建门店
@@ -40,7 +47,6 @@ public interface WxMpStoreService<H, P> {
4047
* </pre>
4148
*
4249
* @param poiId 门店Id
43-
* @throws WxErrorException
4450
*/
4551
WxMpStoreBaseInfo get(String poiId) throws WxErrorException;
4652

@@ -53,7 +59,6 @@ public interface WxMpStoreService<H, P> {
5359
* </pre>
5460
*
5561
* @param poiId 门店Id
56-
* @throws WxErrorException
5762
*/
5863
void delete(String poiId) throws WxErrorException;
5964

@@ -67,7 +72,6 @@ public interface WxMpStoreService<H, P> {
6772
*
6873
* @param begin 开始位置,0 即为从第一条开始查询
6974
* @param limit 返回数据条数,最大允许50,默认为20
70-
* @throws WxErrorException
7175
*/
7276
WxMpStoreListResult list(int begin, int limit) throws WxErrorException;
7377

@@ -78,8 +82,6 @@ public interface WxMpStoreService<H, P> {
7882
* 详情请见: <a href="https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1444378120&token=&lang=zh_CN">微信门店接口</a>
7983
* 接口格式:http://api.weixin.qq.com/cgi-bin/poi/getpoilist?access_token=TOKEN
8084
* </pre>
81-
*
82-
* @throws WxErrorException
8385
*/
8486
List<WxMpStoreInfo> listAll() throws WxErrorException;
8587

@@ -90,8 +92,6 @@ public interface WxMpStoreService<H, P> {
9092
* 详情请见: <a href="https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1444378120&token=&lang=zh_CN">微信门店接口</a>
9193
* 接口格式:http://api.weixin.qq.com/cgi-bin/poi/updatepoi?access_token=TOKEN
9294
* </pre>
93-
*
94-
* @throws WxErrorException
9595
*/
9696
void update(WxMpStoreBaseInfo info) throws WxErrorException;
9797

@@ -102,8 +102,6 @@ public interface WxMpStoreService<H, P> {
102102
* 详情请见: <a href="https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1444378120&token=&lang=zh_CN">微信门店接口</a>
103103
* 接口格式:http://api.weixin.qq.com/cgi-bin/poi/getwxcategory?access_token=TOKEN
104104
* </pre>
105-
*
106-
* @throws WxErrorException
107105
*/
108106
List<String> listCategories() throws WxErrorException;
109107

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpStoreServiceImpl.java

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
* @author binarywang (https://github.com/binarywang)
2222
*/
2323
public class WxMpStoreServiceImpl implements WxMpStoreService {
24-
private static final String API_BASE_URL = "http://api.weixin.qq.com/cgi-bin/poi";
25-
2624
private WxMpService wxMpService;
2725

2826
public WxMpStoreServiceImpl(WxMpService wxMpService) {
@@ -33,8 +31,7 @@ public WxMpStoreServiceImpl(WxMpService wxMpService) {
3331
public void add(WxMpStoreBaseInfo request) throws WxErrorException {
3432
BeanUtils.checkRequiredFields(request);
3533

36-
String url = API_BASE_URL + "/addpoi";
37-
String response = this.wxMpService.post(url, request.toJson());
34+
String response = this.wxMpService.post(POI_ADD_URL, request.toJson());
3835
WxError wxError = WxError.fromJson(response);
3936
if (wxError.getErrorCode() != 0) {
4037
throw new WxErrorException(wxError);
@@ -43,10 +40,9 @@ public void add(WxMpStoreBaseInfo request) throws WxErrorException {
4340

4441
@Override
4542
public WxMpStoreBaseInfo get(String poiId) throws WxErrorException {
46-
String url = API_BASE_URL + "/getpoi";
4743
JsonObject paramObject = new JsonObject();
4844
paramObject.addProperty("poi_id", poiId);
49-
String response = this.wxMpService.post(url, paramObject.toString());
45+
String response = this.wxMpService.post(POI_GET_URL, paramObject.toString());
5046
WxError wxError = WxError.fromJson(response);
5147
if (wxError.getErrorCode() != 0) {
5248
throw new WxErrorException(wxError);
@@ -57,10 +53,9 @@ public WxMpStoreBaseInfo get(String poiId) throws WxErrorException {
5753

5854
@Override
5955
public void delete(String poiId) throws WxErrorException {
60-
String url = API_BASE_URL + "/delpoi";
6156
JsonObject paramObject = new JsonObject();
6257
paramObject.addProperty("poi_id", poiId);
63-
String response = this.wxMpService.post(url, paramObject.toString());
58+
String response = this.wxMpService.post(POI_DEL_URL, paramObject.toString());
6459
WxError wxError = WxError.fromJson(response);
6560
if (wxError.getErrorCode() != 0) {
6661
throw new WxErrorException(wxError);
@@ -70,11 +65,10 @@ public void delete(String poiId) throws WxErrorException {
7065
@Override
7166
public WxMpStoreListResult list(int begin, int limit)
7267
throws WxErrorException {
73-
String url = API_BASE_URL + "/getpoilist";
7468
JsonObject params = new JsonObject();
7569
params.addProperty("begin", begin);
7670
params.addProperty("limit", limit);
77-
String response = this.wxMpService.post(url, params.toString());
71+
String response = this.wxMpService.post(POI_LIST_URL, params.toString());
7872

7973
WxError wxError = WxError.fromJson(response);
8074
if (wxError.getErrorCode() != 0) {
@@ -107,8 +101,7 @@ public List<WxMpStoreInfo> listAll() throws WxErrorException {
107101

108102
@Override
109103
public void update(WxMpStoreBaseInfo request) throws WxErrorException {
110-
String url = API_BASE_URL + "/updatepoi";
111-
String response = this.wxMpService.post(url, request.toJson());
104+
String response = this.wxMpService.post(POI_UPDATE_URL, request.toJson());
112105
WxError wxError = WxError.fromJson(response);
113106
if (wxError.getErrorCode() != 0) {
114107
throw new WxErrorException(wxError);
@@ -117,8 +110,7 @@ public void update(WxMpStoreBaseInfo request) throws WxErrorException {
117110

118111
@Override
119112
public List<String> listCategories() throws WxErrorException {
120-
String url = API_BASE_URL + "/getwxcategory";
121-
String response = this.wxMpService.get(url, null);
113+
String response = this.wxMpService.get(POI_GET_WX_CATEGORY_URL, null);
122114
WxError wxError = WxError.fromJson(response);
123115
if (wxError.getErrorCode() != 0) {
124116
throw new WxErrorException(wxError);

weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpStoreServiceImplTest.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,17 @@ public class WxMpStoreServiceImplTest {
2626
private WxMpService wxMpService;
2727

2828
/**
29-
* Test method for {@link WxMpStoreServiceImpl#add(me.chanjar.weixin.mp.bean.store.WxMpStoreBaseInfo)}.
30-
*
31-
* @throws WxErrorException
29+
* Test method for {@link WxMpStoreServiceImpl#add(WxMpStoreBaseInfo)}.
3230
*/
3331
public void testAdd() throws WxErrorException {
34-
this.wxMpService.getStoreService().add(WxMpStoreBaseInfo.builder().build());
3532
this.wxMpService.getStoreService()
3633
.add(WxMpStoreBaseInfo.builder().businessName("haha").branchName("abc")
3734
.province("aaa").district("aaa").telephone("122").address("abc").categories(new String[]{"美食,江浙菜"})
3835
.longitude(new BigDecimal("115.32375"))
3936
.latitude(new BigDecimal("25.097486")).city("aaa").offsetType(1)
4037
.build());
38+
// 以下运行会抛异常
39+
this.wxMpService.getStoreService().add(WxMpStoreBaseInfo.builder().build());
4140
}
4241

4342
public void testUpdate() throws WxErrorException {

0 commit comments

Comments
 (0)