use of me.chanjar.weixin.mp.bean.result.WxMpUserSummary in project weixin-java-tools by chanjarster.
the class WxMpServiceImpl method getUserSummary.
@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());
}
use of me.chanjar.weixin.mp.bean.result.WxMpUserSummary in project weixin-java-tools by chanjarster.
the class WxMpMiscAPITest method testGetUserSummary.
@Test
public void testGetUserSummary() throws WxErrorException, ParseException {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
Date beginDate = simpleDateFormat.parse("2015-01-01");
Date endDate = simpleDateFormat.parse("2015-01-02");
List<WxMpUserSummary> summaries = wxService.getUserSummary(beginDate, endDate);
System.out.println(summaries);
Assert.assertNotNull(summaries);
}
use of me.chanjar.weixin.mp.bean.result.WxMpUserSummary in project weixin-java-tools by chanjarster.
the class WxMpUserSummaryGsonAdapter method deserialize.
public WxMpUserSummary deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
WxMpUserSummary summary = new WxMpUserSummary();
JsonObject summaryJsonObject = json.getAsJsonObject();
try {
String refDate = GsonHelper.getString(summaryJsonObject, "ref_date");
if (refDate != null) {
summary.setRefDate(SIMPLE_DATE_FORMAT.parse(refDate));
}
summary.setUserSource(GsonHelper.getInteger(summaryJsonObject, "user_source"));
summary.setNewUser(GsonHelper.getInteger(summaryJsonObject, "new_user"));
summary.setCancelUser(GsonHelper.getInteger(summaryJsonObject, "cancel_user"));
} catch (ParseException e) {
throw new JsonParseException(e);
}
return summary;
}
Aggregations