添加门店管理-创建门店的接口,单元测试仅测试格式,暂未通过测试

This commit is contained in:
BinaryWang
2016-09-26 20:06:00 +08:00
parent 18e7f7e123
commit b7e8f2129d
6 changed files with 527 additions and 41 deletions

View File

@@ -302,28 +302,28 @@ public interface WxMpService {
WxMpKefuService getKefuService();
/**
* 返回素材相关接口方法实现类,以方便调用个其各种接口
* 返回素材相关接口方法实现类对象,以方便调用个其各种接口
*
* @return WxMpMaterialService
*/
WxMpMaterialService getMaterialService();
/**
* 返回菜单相关接口方法实现类,以方便调用个其各种接口
* 返回菜单相关接口方法实现类对象,以方便调用个其各种接口
*
* @return WxMpMenuService
*/
WxMpMenuService getMenuService();
/**
* 返回用户相关接口方法实现类,以方便调用个其各种接口
* 返回用户相关接口方法实现类对象,以方便调用个其各种接口
*
* @return WxMpUserService
*/
WxMpUserService getUserService();
/**
* 返回用户分组相关接口方法实现类,以方便调用个其各种接口
* 返回用户分组相关接口方法实现类对象,以方便调用个其各种接口
*
* @return WxMpGroupService
*/
@@ -331,44 +331,51 @@ public interface WxMpService {
WxMpGroupService getGroupService();
/**
* 返回用户标签相关接口方法实现类,以方便调用个其各种接口
* 返回用户标签相关接口方法实现类对象,以方便调用个其各种接口
*
* @return WxMpUserTagService
*/
WxMpUserTagService getUserTagService();
/**
* 返回二维码相关接口方法实现类,以方便调用个其各种接口
* 返回二维码相关接口方法实现类对象,以方便调用个其各种接口
*
* @return WxMpQrcodeService
*/
WxMpQrcodeService getQrcodeService();
/**
* 返回卡券相关接口方法实现类,以方便调用个其各种接口
* 返回卡券相关接口方法实现类对象,以方便调用个其各种接口
*
* @return WxMpCardService
*/
WxMpCardService getCardService();
/**
* 返回微信支付相关接口方法实现类,以方便调用个其各种接口
* 返回微信支付相关接口方法实现类对象,以方便调用个其各种接口
*
* @return WxMpPayService
*/
WxMpPayService getPayService();
/**
* 返回数据分析统计相关接口方法实现类,以方便调用个其各种接口
* 返回数据分析统计相关接口方法实现类对象,以方便调用个其各种接口
*
* @return WxMpDataCubeService
*/
WxMpDataCubeService getDataCubeService();
/**
* 返回用户黑名单管理相关接口方法实现类,以方便调用其各种
* 返回用户黑名单管理相关接口方法实现类对象,以方便调用其各种
*
* @return WxMpUserBlackListService
* @return WxMpUserBlacklistService
*/
WxMpUserBlacklistService getBlackListService();
/**
* 返回门店管理相关接口方法的实现类对象,以方便调用其各种接口
*
* @return WxMpStoreService
*/
WxMpStoreService getStoreService();
}

View File

@@ -1,6 +1,7 @@
package me.chanjar.weixin.mp.api;
import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.mp.bean.WxMpStoreBaseInfo;
/**
* 门店管理的相关接口代码
@@ -19,8 +20,6 @@ public interface WxMpStoreService {
* 接口格式: http://api.weixin.qq.com/cgi-bin/poi/addpoi?access_token=TOKEN
* </pre>
*
* @param scene_id 参数。
* @param expire_seconds 过期秒数默认60秒最小60秒最大1800秒
*/
void userUpdateRemark(String openid, String remark) throws WxErrorException;
void add(WxMpStoreBaseInfo request) throws WxErrorException;
}

View File

@@ -1,21 +1,7 @@
package me.chanjar.weixin.mp.api.impl;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import me.chanjar.weixin.common.bean.WxAccessToken;
import me.chanjar.weixin.common.bean.WxJsapiSignature;
import me.chanjar.weixin.common.bean.result.WxError;
import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.common.session.StandardSessionManager;
import me.chanjar.weixin.common.session.WxSessionManager;
import me.chanjar.weixin.common.util.RandomUtils;
import me.chanjar.weixin.common.util.crypto.SHA1;
import me.chanjar.weixin.common.util.http.*;
import me.chanjar.weixin.mp.api.*;
import me.chanjar.weixin.mp.bean.*;
import me.chanjar.weixin.mp.bean.result.*;
import java.io.IOException;
import org.apache.http.HttpHost;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
@@ -27,7 +13,52 @@ import org.apache.http.impl.client.CloseableHttpClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import me.chanjar.weixin.common.bean.WxAccessToken;
import me.chanjar.weixin.common.bean.WxJsapiSignature;
import me.chanjar.weixin.common.bean.result.WxError;
import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.common.session.StandardSessionManager;
import me.chanjar.weixin.common.session.WxSessionManager;
import me.chanjar.weixin.common.util.RandomUtils;
import me.chanjar.weixin.common.util.crypto.SHA1;
import me.chanjar.weixin.common.util.http.ApacheHttpClientBuilder;
import me.chanjar.weixin.common.util.http.DefaultApacheHttpClientBuilder;
import me.chanjar.weixin.common.util.http.RequestExecutor;
import me.chanjar.weixin.common.util.http.SimpleGetRequestExecutor;
import me.chanjar.weixin.common.util.http.SimplePostRequestExecutor;
import me.chanjar.weixin.common.util.http.URIUtil;
import me.chanjar.weixin.mp.api.WxMpCardService;
import me.chanjar.weixin.mp.api.WxMpConfigStorage;
import me.chanjar.weixin.mp.api.WxMpDataCubeService;
import me.chanjar.weixin.mp.api.WxMpGroupService;
import me.chanjar.weixin.mp.api.WxMpKefuService;
import me.chanjar.weixin.mp.api.WxMpMaterialService;
import me.chanjar.weixin.mp.api.WxMpMenuService;
import me.chanjar.weixin.mp.api.WxMpPayService;
import me.chanjar.weixin.mp.api.WxMpQrcodeService;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.WxMpStoreService;
import me.chanjar.weixin.mp.api.WxMpUserBlacklistService;
import me.chanjar.weixin.mp.api.WxMpUserService;
import me.chanjar.weixin.mp.api.WxMpUserTagService;
import me.chanjar.weixin.mp.bean.WxMpIndustry;
import me.chanjar.weixin.mp.bean.WxMpMassGroupMessage;
import me.chanjar.weixin.mp.bean.WxMpMassNews;
import me.chanjar.weixin.mp.bean.WxMpMassOpenIdsMessage;
import me.chanjar.weixin.mp.bean.WxMpMassPreviewMessage;
import me.chanjar.weixin.mp.bean.WxMpMassVideo;
import me.chanjar.weixin.mp.bean.WxMpSemanticQuery;
import me.chanjar.weixin.mp.bean.WxMpTemplateMessage;
import me.chanjar.weixin.mp.bean.result.WxMpMassSendResult;
import me.chanjar.weixin.mp.bean.result.WxMpMassUploadResult;
import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken;
import me.chanjar.weixin.mp.bean.result.WxMpSemanticQueryResult;
import me.chanjar.weixin.mp.bean.result.WxMpUser;
public class WxMpServiceImpl implements WxMpService {
@@ -65,6 +96,8 @@ public class WxMpServiceImpl implements WxMpService {
private WxMpPayService payService = new WxMpPayServiceImpl(this);
private WxMpStoreService storeService = new WxMpStoreServiceImpl(this);
private WxMpDataCubeService dataCubeService = new WxMpDataCubeServiceImpl(this);
private WxMpUserBlacklistService blackListService = new WxMpUserBlacklistServiceImpl(this);
@@ -442,6 +475,8 @@ public class WxMpServiceImpl implements WxMpService {
return this.execute(executor, uri, data);
}
if (error.getErrorCode() != 0) {
this.log.error("\n[URL]: {}\n[PARAMS]: {}\n[RESPONSE]: {}", uri, data,
error);
throw new WxErrorException(error);
}
return null;
@@ -560,4 +595,9 @@ public class WxMpServiceImpl implements WxMpService {
return this.blackListService;
}
@Override
public WxMpStoreService getStoreService() {
return this.storeService;
}
}

View File

@@ -0,0 +1,67 @@
package me.chanjar.weixin.mp.api.impl;
import java.lang.reflect.Field;
import java.util.List;
import java.util.Map.Entry;
import org.joor.Reflect;
import com.google.common.collect.Lists;
import me.chanjar.weixin.common.annotation.Required;
import me.chanjar.weixin.common.bean.result.WxError;
import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.WxMpStoreService;
import me.chanjar.weixin.mp.bean.WxMpStoreBaseInfo;
/**
* Created by Binary Wang on 2016/9/26.
* @author binarywang (https://github.com/binarywang)
*
*/
public class WxMpStoreServiceImpl implements WxMpStoreService {
private WxMpService wxMpService;
public WxMpStoreServiceImpl(WxMpService wxMpService) {
this.wxMpService = wxMpService;
}
@Override
public void add(WxMpStoreBaseInfo request) throws WxErrorException {
checkParameters(request);
String url = "http://api.weixin.qq.com/cgi-bin/poi/addpoi";
// 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\"}}}";
String response = this.wxMpService.post(url, request.toJson());
// String response = this.wxMpService.post(url, data);
WxError wxError = WxError.fromJson(response);
if (wxError.getErrorCode() != 0) {
throw new WxErrorException(wxError);
}
}
private void checkParameters(WxMpStoreBaseInfo request) {
List<String> nullFields = Lists.newArrayList();
for (Entry<String, Reflect> entry : Reflect.on(request).fields()
.entrySet()) {
Reflect reflect = entry.getValue();
try {
Field field = request.getClass().getDeclaredField(entry.getKey());
if (field.isAnnotationPresent(Required.class)
&& reflect.get() == null) {
nullFields.add(entry.getKey());
}
} catch (NoSuchFieldException | SecurityException e) {
e.printStackTrace();
}
}
if (!nullFields.isEmpty()) {
throw new IllegalArgumentException("必填字段[" + nullFields + "]必须提供值");
}
}
}