Search in sources :

Example 1 with WxMpUserSummary

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());
}
Also used : JsonElement(com.google.gson.JsonElement) TypeToken(com.google.gson.reflect.TypeToken) StringReader(java.io.StringReader) JsonObject(com.google.gson.JsonObject) JsonReader(com.google.gson.stream.JsonReader) WxMpUserSummary(me.chanjar.weixin.mp.bean.result.WxMpUserSummary)

Example 2 with WxMpUserSummary

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);
}
Also used : WxMpUserSummary(me.chanjar.weixin.mp.bean.result.WxMpUserSummary) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) Test(org.testng.annotations.Test)

Example 3 with WxMpUserSummary

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;
}
Also used : ParseException(java.text.ParseException) WxMpUserSummary(me.chanjar.weixin.mp.bean.result.WxMpUserSummary)

Aggregations

WxMpUserSummary (me.chanjar.weixin.mp.bean.result.WxMpUserSummary)3 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 TypeToken (com.google.gson.reflect.TypeToken)1 JsonReader (com.google.gson.stream.JsonReader)1 StringReader (java.io.StringReader)1 ParseException (java.text.ParseException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 Test (org.testng.annotations.Test)1