Selaa lähdekoodia

#195 抽取门店管理相关接口请求URL为常量

master
Binary Wang 7 vuotta sitten
vanhempi
commit
972b07a20f
3 muutettua tiedostoa jossa 16 lisäystä ja 27 poistoa
  1. +7
    -9
      weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpStoreService.java
  2. +6
    -14
      weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpStoreServiceImpl.java
  3. +3
    -4
      weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpStoreServiceImplTest.java

+ 7
- 9
weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpStoreService.java Näytä tiedosto

@@ -15,6 +15,13 @@ import java.util.List;
* @author <a href="https://github.com/binarywang">Binary Wang</a>
*/
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>
* 创建门店
@@ -40,7 +47,6 @@ public interface WxMpStoreService<H, P> {
* </pre>
*
* @param poiId 门店Id
* @throws WxErrorException
*/
WxMpStoreBaseInfo get(String poiId) throws WxErrorException;

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

@@ -67,7 +72,6 @@ public interface WxMpStoreService<H, P> {
*
* @param begin 开始位置,0 即为从第一条开始查询
* @param limit 返回数据条数,最大允许50,默认为20
* @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>
* 接口格式:http://api.weixin.qq.com/cgi-bin/poi/getpoilist?access_token=TOKEN
* </pre>
*
* @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>
* 接口格式:http://api.weixin.qq.com/cgi-bin/poi/updatepoi?access_token=TOKEN
* </pre>
*
* @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>
* 接口格式:http://api.weixin.qq.com/cgi-bin/poi/getwxcategory?access_token=TOKEN
* </pre>
*
* @throws WxErrorException
*/
List<String> listCategories() throws WxErrorException;



+ 6
- 14
weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpStoreServiceImpl.java Näytä tiedosto

@@ -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<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);
if (wxError.getErrorCode() != 0) {
throw new WxErrorException(wxError);


+ 3
- 4
weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpStoreServiceImplTest.java Näytä tiedosto

@@ -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 {


Ladataan…
Peruuta
Tallenna