Skip to content

Commit b7e8f21

Browse files
committed
添加门店管理-创建门店的接口,单元测试仅测试格式,暂未通过测试
1 parent 18e7f7e commit b7e8f21

File tree

6 files changed

+526
-40
lines changed

6 files changed

+526
-40
lines changed

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

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -302,73 +302,80 @@ public interface WxMpService {
302302
WxMpKefuService getKefuService();
303303

304304
/**
305-
* 返回素材相关接口的方法实现类,以方便调用个其各种接口
305+
* 返回素材相关接口方法的实现类对象,以方便调用个其各种接口
306306
*
307307
* @return WxMpMaterialService
308308
*/
309309
WxMpMaterialService getMaterialService();
310310

311311
/**
312-
* 返回菜单相关接口的方法实现类,以方便调用个其各种接口
312+
* 返回菜单相关接口方法的实现类对象,以方便调用个其各种接口
313313
*
314314
* @return WxMpMenuService
315315
*/
316316
WxMpMenuService getMenuService();
317317

318318
/**
319-
* 返回用户相关接口的方法实现类,以方便调用个其各种接口
319+
* 返回用户相关接口方法的实现类对象,以方便调用个其各种接口
320320
*
321321
* @return WxMpUserService
322322
*/
323323
WxMpUserService getUserService();
324324

325325
/**
326-
* 返回用户分组相关接口的方法实现类,以方便调用个其各种接口
326+
* 返回用户分组相关接口方法的实现类对象,以方便调用个其各种接口
327327
*
328328
* @return WxMpGroupService
329329
*/
330330

331331
WxMpGroupService getGroupService();
332332

333333
/**
334-
* 返回用户标签相关接口的方法实现类,以方便调用个其各种接口
334+
* 返回用户标签相关接口方法的实现类对象,以方便调用个其各种接口
335335
*
336336
* @return WxMpUserTagService
337337
*/
338338
WxMpUserTagService getUserTagService();
339339

340340
/**
341-
* 返回二维码相关接口的方法实现类,以方便调用个其各种接口
341+
* 返回二维码相关接口方法的实现类对象,以方便调用个其各种接口
342342
*
343343
* @return WxMpQrcodeService
344344
*/
345345
WxMpQrcodeService getQrcodeService();
346346

347347
/**
348-
* 返回卡券相关接口的方法实现类,以方便调用个其各种接口
348+
* 返回卡券相关接口方法的实现类对象,以方便调用个其各种接口
349349
*
350350
* @return WxMpCardService
351351
*/
352352
WxMpCardService getCardService();
353353

354354
/**
355-
* 返回微信支付相关接口的方法实现类,以方便调用个其各种接口
355+
* 返回微信支付相关接口方法的实现类对象,以方便调用个其各种接口
356356
*
357357
* @return WxMpPayService
358358
*/
359359
WxMpPayService getPayService();
360360

361361
/**
362-
* 返回数据分析统计相关接口的方法实现类,以方便调用个其各种接口
362+
* 返回数据分析统计相关接口方法的实现类对象,以方便调用个其各种接口
363363
*
364364
* @return WxMpDataCubeService
365365
*/
366366
WxMpDataCubeService getDataCubeService();
367367

368368
/**
369-
* 返回用户黑名单管理相关接口的方法实现类,以方便调用其各种借口
369+
* 返回用户黑名单管理相关接口方法的实现类对象,以方便调用其各种接口
370370
*
371-
* @return WxMpUserBlackListService
371+
* @return WxMpUserBlacklistService
372372
*/
373373
WxMpUserBlacklistService getBlackListService();
374+
375+
/**
376+
* 返回门店管理相关接口方法的实现类对象,以方便调用其各种接口
377+
*
378+
* @return WxMpStoreService
379+
*/
380+
WxMpStoreService getStoreService();
374381
}

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package me.chanjar.weixin.mp.api;
22

33
import me.chanjar.weixin.common.exception.WxErrorException;
4+
import me.chanjar.weixin.mp.bean.WxMpStoreBaseInfo;
45

56
/**
67
* 门店管理的相关接口代码
@@ -19,8 +20,6 @@ public interface WxMpStoreService {
1920
* 接口格式: http://api.weixin.qq.com/cgi-bin/poi/addpoi?access_token=TOKEN
2021
* </pre>
2122
*
22-
* @param scene_id 参数。
23-
* @param expire_seconds 过期秒数,默认60秒,最小60秒,最大1800秒
2423
*/
25-
void userUpdateRemark(String openid, String remark) throws WxErrorException;
24+
void add(WxMpStoreBaseInfo request) throws WxErrorException;
2625
}

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

Lines changed: 56 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,23 @@
11
package me.chanjar.weixin.mp.api.impl;
22

3+
import java.io.IOException;
4+
5+
import org.apache.http.HttpHost;
6+
import org.apache.http.client.config.RequestConfig;
7+
import org.apache.http.client.methods.CloseableHttpResponse;
8+
import org.apache.http.client.methods.HttpGet;
9+
import org.apache.http.conn.ssl.DefaultHostnameVerifier;
10+
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
11+
import org.apache.http.impl.client.BasicResponseHandler;
12+
import org.apache.http.impl.client.CloseableHttpClient;
13+
import org.slf4j.Logger;
14+
import org.slf4j.LoggerFactory;
15+
316
import com.google.gson.JsonArray;
417
import com.google.gson.JsonElement;
518
import com.google.gson.JsonObject;
619
import com.google.gson.JsonParser;
20+
721
import me.chanjar.weixin.common.bean.WxAccessToken;
822
import me.chanjar.weixin.common.bean.WxJsapiSignature;
923
import me.chanjar.weixin.common.bean.result.WxError;
@@ -12,22 +26,39 @@
1226
import me.chanjar.weixin.common.session.WxSessionManager;
1327
import me.chanjar.weixin.common.util.RandomUtils;
1428
import me.chanjar.weixin.common.util.crypto.SHA1;
15-
import me.chanjar.weixin.common.util.http.*;
16-
import me.chanjar.weixin.mp.api.*;
17-
import me.chanjar.weixin.mp.bean.*;
18-
import me.chanjar.weixin.mp.bean.result.*;
19-
import org.apache.http.HttpHost;
20-
import org.apache.http.client.config.RequestConfig;
21-
import org.apache.http.client.methods.CloseableHttpResponse;
22-
import org.apache.http.client.methods.HttpGet;
23-
import org.apache.http.conn.ssl.DefaultHostnameVerifier;
24-
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
25-
import org.apache.http.impl.client.BasicResponseHandler;
26-
import org.apache.http.impl.client.CloseableHttpClient;
27-
import org.slf4j.Logger;
28-
import org.slf4j.LoggerFactory;
29-
30-
import java.io.IOException;
29+
import me.chanjar.weixin.common.util.http.ApacheHttpClientBuilder;
30+
import me.chanjar.weixin.common.util.http.DefaultApacheHttpClientBuilder;
31+
import me.chanjar.weixin.common.util.http.RequestExecutor;
32+
import me.chanjar.weixin.common.util.http.SimpleGetRequestExecutor;
33+
import me.chanjar.weixin.common.util.http.SimplePostRequestExecutor;
34+
import me.chanjar.weixin.common.util.http.URIUtil;
35+
import me.chanjar.weixin.mp.api.WxMpCardService;
36+
import me.chanjar.weixin.mp.api.WxMpConfigStorage;
37+
import me.chanjar.weixin.mp.api.WxMpDataCubeService;
38+
import me.chanjar.weixin.mp.api.WxMpGroupService;
39+
import me.chanjar.weixin.mp.api.WxMpKefuService;
40+
import me.chanjar.weixin.mp.api.WxMpMaterialService;
41+
import me.chanjar.weixin.mp.api.WxMpMenuService;
42+
import me.chanjar.weixin.mp.api.WxMpPayService;
43+
import me.chanjar.weixin.mp.api.WxMpQrcodeService;
44+
import me.chanjar.weixin.mp.api.WxMpService;
45+
import me.chanjar.weixin.mp.api.WxMpStoreService;
46+
import me.chanjar.weixin.mp.api.WxMpUserBlacklistService;
47+
import me.chanjar.weixin.mp.api.WxMpUserService;
48+
import me.chanjar.weixin.mp.api.WxMpUserTagService;
49+
import me.chanjar.weixin.mp.bean.WxMpIndustry;
50+
import me.chanjar.weixin.mp.bean.WxMpMassGroupMessage;
51+
import me.chanjar.weixin.mp.bean.WxMpMassNews;
52+
import me.chanjar.weixin.mp.bean.WxMpMassOpenIdsMessage;
53+
import me.chanjar.weixin.mp.bean.WxMpMassPreviewMessage;
54+
import me.chanjar.weixin.mp.bean.WxMpMassVideo;
55+
import me.chanjar.weixin.mp.bean.WxMpSemanticQuery;
56+
import me.chanjar.weixin.mp.bean.WxMpTemplateMessage;
57+
import me.chanjar.weixin.mp.bean.result.WxMpMassSendResult;
58+
import me.chanjar.weixin.mp.bean.result.WxMpMassUploadResult;
59+
import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken;
60+
import me.chanjar.weixin.mp.bean.result.WxMpSemanticQueryResult;
61+
import me.chanjar.weixin.mp.bean.result.WxMpUser;
3162

3263
public class WxMpServiceImpl implements WxMpService {
3364

@@ -65,6 +96,8 @@ public class WxMpServiceImpl implements WxMpService {
6596

6697
private WxMpPayService payService = new WxMpPayServiceImpl(this);
6798

99+
private WxMpStoreService storeService = new WxMpStoreServiceImpl(this);
100+
68101
private WxMpDataCubeService dataCubeService = new WxMpDataCubeServiceImpl(this);
69102

70103
private WxMpUserBlacklistService blackListService = new WxMpUserBlacklistServiceImpl(this);
@@ -442,6 +475,8 @@ protected synchronized <T, E> T executeInternal(RequestExecutor<T, E> executor,
442475
return this.execute(executor, uri, data);
443476
}
444477
if (error.getErrorCode() != 0) {
478+
this.log.error("\n[URL]: {}\n[PARAMS]: {}\n[RESPONSE]: {}", uri, data,
479+
error);
445480
throw new WxErrorException(error);
446481
}
447482
return null;
@@ -560,4 +595,9 @@ public WxMpUserBlacklistService getBlackListService() {
560595
return this.blackListService;
561596
}
562597

598+
@Override
599+
public WxMpStoreService getStoreService() {
600+
return this.storeService;
601+
}
602+
563603
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package me.chanjar.weixin.mp.api.impl;
2+
3+
import java.lang.reflect.Field;
4+
import java.util.List;
5+
import java.util.Map.Entry;
6+
7+
import org.joor.Reflect;
8+
9+
import com.google.common.collect.Lists;
10+
11+
import me.chanjar.weixin.common.annotation.Required;
12+
import me.chanjar.weixin.common.bean.result.WxError;
13+
import me.chanjar.weixin.common.exception.WxErrorException;
14+
import me.chanjar.weixin.mp.api.WxMpService;
15+
import me.chanjar.weixin.mp.api.WxMpStoreService;
16+
import me.chanjar.weixin.mp.bean.WxMpStoreBaseInfo;
17+
18+
/**
19+
* Created by Binary Wang on 2016/9/26.
20+
* @author binarywang (https://github.com/binarywang)
21+
*
22+
*/
23+
public class WxMpStoreServiceImpl implements WxMpStoreService {
24+
25+
private WxMpService wxMpService;
26+
27+
public WxMpStoreServiceImpl(WxMpService wxMpService) {
28+
this.wxMpService = wxMpService;
29+
}
30+
31+
@Override
32+
public void add(WxMpStoreBaseInfo request) throws WxErrorException {
33+
checkParameters(request);
34+
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\"}}}";
37+
String response = this.wxMpService.post(url, request.toJson());
38+
// String response = this.wxMpService.post(url, data);
39+
WxError wxError = WxError.fromJson(response);
40+
if (wxError.getErrorCode() != 0) {
41+
throw new WxErrorException(wxError);
42+
}
43+
}
44+
45+
private void checkParameters(WxMpStoreBaseInfo request) {
46+
List<String> nullFields = Lists.newArrayList();
47+
for (Entry<String, Reflect> entry : Reflect.on(request).fields()
48+
.entrySet()) {
49+
Reflect reflect = entry.getValue();
50+
try {
51+
Field field = request.getClass().getDeclaredField(entry.getKey());
52+
if (field.isAnnotationPresent(Required.class)
53+
&& reflect.get() == null) {
54+
nullFields.add(entry.getKey());
55+
}
56+
} catch (NoSuchFieldException | SecurityException e) {
57+
e.printStackTrace();
58+
}
59+
}
60+
61+
if (!nullFields.isEmpty()) {
62+
throw new IllegalArgumentException("必填字段[" + nullFields + "]必须提供值");
63+
}
64+
65+
}
66+
67+
}

0 commit comments

Comments
 (0)