mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2026-03-10 00:13:40 +08:00
issue #100 用户分析数据接口
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user