Search in sources :

Example 1 with WxMpUserCumulate

use of me.chanjar.weixin.mp.bean.result.WxMpUserCumulate in project weixin-java-tools by chanjarster.

the class WxMpMiscAPITest method testGetUserCumulate.

@Test
public void testGetUserCumulate() 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<WxMpUserCumulate> cumulates = wxService.getUserCumulate(beginDate, endDate);
    System.out.println(cumulates);
    Assert.assertNotNull(cumulates);
}
Also used : WxMpUserCumulate(me.chanjar.weixin.mp.bean.result.WxMpUserCumulate) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) Test(org.testng.annotations.Test)

Example 2 with WxMpUserCumulate

use of me.chanjar.weixin.mp.bean.result.WxMpUserCumulate in project weixin-java-tools by chanjarster.

the class WxMpUserCumulateGsonAdapter method deserialize.

public WxMpUserCumulate deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
    WxMpUserCumulate cumulate = new WxMpUserCumulate();
    JsonObject summaryJsonObject = json.getAsJsonObject();
    try {
        String refDate = GsonHelper.getString(summaryJsonObject, "ref_date");
        if (refDate != null) {
            cumulate.setRefDate(SIMPLE_DATE_FORMAT.parse(refDate));
        }
        cumulate.setCumulateUser(GsonHelper.getInteger(summaryJsonObject, "cumulate_user"));
    } catch (ParseException e) {
        throw new JsonParseException(e);
    }
    return cumulate;
}
Also used : WxMpUserCumulate(me.chanjar.weixin.mp.bean.result.WxMpUserCumulate) ParseException(java.text.ParseException)

Example 3 with WxMpUserCumulate

use of me.chanjar.weixin.mp.bean.result.WxMpUserCumulate in project weixin-java-tools by chanjarster.

the class WxMpServiceImpl method getUserCumulate.

@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());
}
Also used : WxMpUserCumulate(me.chanjar.weixin.mp.bean.result.WxMpUserCumulate) 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)

Aggregations

WxMpUserCumulate (me.chanjar.weixin.mp.bean.result.WxMpUserCumulate)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