issue #100 用户分析数据接口

This commit is contained in:
Daniel Qian
2015-02-25 15:17:52 +08:00
parent fb10acf6fd
commit 978c51b90d
8 changed files with 280 additions and 2 deletions

View File

@@ -11,13 +11,16 @@ import me.chanjar.weixin.mp.bean.result.*;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
/**
* 微信API的Service
*/
public interface WxMpService {
public static final SimpleDateFormat SIMPLE_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd");
/**
* <pre>
* 验证推送过来的消息的正确性
@@ -431,6 +434,30 @@ public interface WxMpService {
*/
String[] getCallbackIP() throws WxErrorException;
/**
* <pre>
* 获取用户增减数据
* http://mp.weixin.qq.com/wiki/3/ecfed6e1a0a03b5f35e5efac98e864b7.html
* </pre>
* @param beginDate 最大时间跨度7天
* @param endDate endDate不能早于begingDate
* @return
* @throws WxErrorException
*/
List<WxMpUserSummary> getUserSummary(Date beginDate, Date endDate) throws WxErrorException;
/**
* <pre>
* 获取累计用户数据
* http://mp.weixin.qq.com/wiki/3/ecfed6e1a0a03b5f35e5efac98e864b7.html
* </pre>
* @param beginDate 最大时间跨度7天
* @param endDate endDate不能早于begingDate
* @return
* @throws WxErrorException
*/
List<WxMpUserCumulate> getUserCumulate(Date beginDate, Date endDate) throws WxErrorException;
/**
* 当本Service没有实现某个API的时候可以用这个针对所有微信API中的GET请求
* @param url

View File

@@ -44,6 +44,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.StringReader;
import java.security.NoSuchAlgorithmException;
import java.util.Date;
import java.util.List;
import java.util.UUID;
@@ -465,6 +466,29 @@ public class WxMpServiceImpl implements WxMpService {
return ipArray;
}
@Override
public List<WxMpUserSummary> getUserSummary(Date beginDate, Date endDate) throws WxErrorException {
String url = "https://api.weixin.qq.com/datacube/getusersummary";
JsonObject param = new JsonObject();
param.addProperty("begin_date", SIMPLE_DATE_FORMAT.format(beginDate));
param.addProperty("end_date", SIMPLE_DATE_FORMAT.format(endDate));
String responseContent = post(url, param.toString());
JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent)));
return WxMpGsonBuilder.INSTANCE.create().fromJson(tmpJsonElement.getAsJsonObject().get("list"), new TypeToken<List<WxMpUserSummary>>(){}.getType());
}
@Override
public List<WxMpUserCumulate> getUserCumulate(Date beginDate, Date endDate) throws WxErrorException {
String url = "https://api.weixin.qq.com/datacube/getusercumulate";
JsonObject param = new JsonObject();
param.addProperty("begin_date", SIMPLE_DATE_FORMAT.format(beginDate));
param.addProperty("end_date", SIMPLE_DATE_FORMAT.format(endDate));
String responseContent = post(url, param.toString());
JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent)));
return WxMpGsonBuilder.INSTANCE.create().fromJson(tmpJsonElement.getAsJsonObject().get("list"), new TypeToken<List<WxMpUserCumulate>>(){}.getType());
}
public String get(String url, String queryParam) throws WxErrorException {
return execute(new SimpleGetRequestExecutor(), url, queryParam);
}