重构统计接口代码

This commit is contained in:
BinaryWang 2016-09-09 10:18:04 +08:00
parent 82d71ea418
commit a1d5b3d0dc
7 changed files with 113 additions and 64 deletions

View File

@ -9,8 +9,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.reflect.TypeToken;
import me.chanjar.weixin.common.exception.WxErrorException; import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpDataCubeService; import me.chanjar.weixin.mp.api.WxMpDataCubeService;
@ -21,7 +19,6 @@ import me.chanjar.weixin.mp.bean.datacube.WxDataCubeInterfaceResult;
import me.chanjar.weixin.mp.bean.datacube.WxDataCubeMsgResult; import me.chanjar.weixin.mp.bean.datacube.WxDataCubeMsgResult;
import me.chanjar.weixin.mp.bean.datacube.WxDataCubeUserCumulate; import me.chanjar.weixin.mp.bean.datacube.WxDataCubeUserCumulate;
import me.chanjar.weixin.mp.bean.datacube.WxDataCubeUserSummary; import me.chanjar.weixin.mp.bean.datacube.WxDataCubeUserSummary;
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
/** /**
* Created by Binary Wang on 2016/8/23. * Created by Binary Wang on 2016/8/23.
@ -48,9 +45,7 @@ public class WxMpDataCubeServiceImpl implements WxMpDataCubeService {
param.addProperty("end_date", this.dateFormat.format(endDate)); param.addProperty("end_date", this.dateFormat.format(endDate));
String responseContent = this.wxMpService.post(url, param.toString()); String responseContent = this.wxMpService.post(url, param.toString());
this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent); this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent);
return WxMpGsonBuilder.INSTANCE.create().fromJson(new JsonParser().parse(responseContent).getAsJsonObject().get("list"), return WxDataCubeUserSummary.fromJson(responseContent);
new TypeToken<List<WxDataCubeUserSummary>>() {
}.getType());
} }
@Override @Override
@ -61,9 +56,7 @@ public class WxMpDataCubeServiceImpl implements WxMpDataCubeService {
param.addProperty("end_date", this.dateFormat.format(endDate)); param.addProperty("end_date", this.dateFormat.format(endDate));
String responseContent = this.wxMpService.post(url, param.toString()); String responseContent = this.wxMpService.post(url, param.toString());
this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent); this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent);
return WxMpGsonBuilder.INSTANCE.create().fromJson(new JsonParser().parse(responseContent).getAsJsonObject().get("list"), return WxDataCubeUserCumulate.fromJson(responseContent);
new TypeToken<List<WxDataCubeUserCumulate>>() {
}.getType());
} }
@Override @Override
@ -74,9 +67,7 @@ public class WxMpDataCubeServiceImpl implements WxMpDataCubeService {
param.addProperty("end_date", this.dateFormat.format(endDate)); param.addProperty("end_date", this.dateFormat.format(endDate));
String responseContent = this.wxMpService.post(url, param.toString()); String responseContent = this.wxMpService.post(url, param.toString());
this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent); this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent);
return WxMpGsonBuilder.INSTANCE.create().fromJson(new JsonParser().parse(responseContent).getAsJsonObject().get("list"), return WxDataCubeArticleResult.fromJson(responseContent);
new TypeToken<List<WxDataCubeArticleResult>>() {
}.getType());
} }
@Override @Override
@ -87,9 +78,7 @@ public class WxMpDataCubeServiceImpl implements WxMpDataCubeService {
param.addProperty("end_date", this.dateFormat.format(endDate)); param.addProperty("end_date", this.dateFormat.format(endDate));
String responseContent = this.wxMpService.post(url, param.toString()); String responseContent = this.wxMpService.post(url, param.toString());
this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent); this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent);
return WxMpGsonBuilder.INSTANCE.create().fromJson(new JsonParser().parse(responseContent).getAsJsonObject().get("list"), return WxDataCubeArticleTotal.fromJson(responseContent);
new TypeToken<List<WxDataCubeArticleTotal>>() {
}.getType());
} }
@Override @Override
@ -100,9 +89,7 @@ public class WxMpDataCubeServiceImpl implements WxMpDataCubeService {
param.addProperty("end_date", this.dateFormat.format(endDate)); param.addProperty("end_date", this.dateFormat.format(endDate));
String responseContent = this.wxMpService.post(url, param.toString()); String responseContent = this.wxMpService.post(url, param.toString());
this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent); this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent);
return WxMpGsonBuilder.INSTANCE.create().fromJson(new JsonParser().parse(responseContent).getAsJsonObject().get("list"), return WxDataCubeArticleResult.fromJson(responseContent);
new TypeToken<List<WxDataCubeArticleResult>>() {
}.getType());
} }
@Override @Override
@ -113,9 +100,7 @@ public class WxMpDataCubeServiceImpl implements WxMpDataCubeService {
param.addProperty("end_date", this.dateFormat.format(endDate)); param.addProperty("end_date", this.dateFormat.format(endDate));
String responseContent = this.wxMpService.post(url, param.toString()); String responseContent = this.wxMpService.post(url, param.toString());
this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent); this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent);
return WxMpGsonBuilder.INSTANCE.create().fromJson(new JsonParser().parse(responseContent).getAsJsonObject().get("list"), return WxDataCubeArticleResult.fromJson(responseContent);
new TypeToken<List<WxDataCubeArticleResult>>() {
}.getType());
} }
@Override @Override
@ -126,9 +111,7 @@ public class WxMpDataCubeServiceImpl implements WxMpDataCubeService {
param.addProperty("end_date", this.dateFormat.format(endDate)); param.addProperty("end_date", this.dateFormat.format(endDate));
String responseContent = this.wxMpService.post(url, param.toString()); String responseContent = this.wxMpService.post(url, param.toString());
this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent); this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent);
return WxMpGsonBuilder.INSTANCE.create().fromJson(new JsonParser().parse(responseContent).getAsJsonObject().get("list"), return WxDataCubeArticleResult.fromJson(responseContent);
new TypeToken<List<WxDataCubeArticleResult>>() {
}.getType());
} }
@Override @Override
@ -139,9 +122,7 @@ public class WxMpDataCubeServiceImpl implements WxMpDataCubeService {
param.addProperty("end_date", this.dateFormat.format(endDate)); param.addProperty("end_date", this.dateFormat.format(endDate));
String responseContent = this.wxMpService.post(url, param.toString()); String responseContent = this.wxMpService.post(url, param.toString());
this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent); this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent);
return WxMpGsonBuilder.INSTANCE.create().fromJson(new JsonParser().parse(responseContent).getAsJsonObject().get("list"), return WxDataCubeArticleResult.fromJson(responseContent);
new TypeToken<List<WxDataCubeArticleResult>>() {
}.getType());
} }
@Override @Override
@ -153,9 +134,7 @@ public class WxMpDataCubeServiceImpl implements WxMpDataCubeService {
param.addProperty("end_date", this.dateFormat.format(endDate)); param.addProperty("end_date", this.dateFormat.format(endDate));
String responseContent = this.wxMpService.post(url, param.toString()); String responseContent = this.wxMpService.post(url, param.toString());
this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent); this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent);
return WxMpGsonBuilder.INSTANCE.create().fromJson(new JsonParser().parse(responseContent).getAsJsonObject().get("list"), return WxDataCubeMsgResult.fromJson(responseContent);
new TypeToken<List<WxDataCubeMsgResult>>() {
}.getType());
} }
@Override @Override
@ -167,9 +146,7 @@ public class WxMpDataCubeServiceImpl implements WxMpDataCubeService {
param.addProperty("end_date", this.dateFormat.format(endDate)); param.addProperty("end_date", this.dateFormat.format(endDate));
String responseContent = this.wxMpService.post(url, param.toString()); String responseContent = this.wxMpService.post(url, param.toString());
this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent); this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent);
return WxMpGsonBuilder.INSTANCE.create().fromJson(new JsonParser().parse(responseContent).getAsJsonObject().get("list"), return WxDataCubeMsgResult.fromJson(responseContent);
new TypeToken<List<WxDataCubeMsgResult>>() {
}.getType());
} }
@Override @Override
@ -181,9 +158,7 @@ public class WxMpDataCubeServiceImpl implements WxMpDataCubeService {
param.addProperty("end_date", this.dateFormat.format(endDate)); param.addProperty("end_date", this.dateFormat.format(endDate));
String responseContent = this.wxMpService.post(url, param.toString()); String responseContent = this.wxMpService.post(url, param.toString());
this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent); this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent);
return WxMpGsonBuilder.INSTANCE.create().fromJson(new JsonParser().parse(responseContent).getAsJsonObject().get("list"), return WxDataCubeMsgResult.fromJson(responseContent);
new TypeToken<List<WxDataCubeMsgResult>>() {
}.getType());
} }
@Override @Override
@ -195,9 +170,7 @@ public class WxMpDataCubeServiceImpl implements WxMpDataCubeService {
param.addProperty("end_date", this.dateFormat.format(endDate)); param.addProperty("end_date", this.dateFormat.format(endDate));
String responseContent = this.wxMpService.post(url, param.toString()); String responseContent = this.wxMpService.post(url, param.toString());
this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent); this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent);
return WxMpGsonBuilder.INSTANCE.create().fromJson(new JsonParser().parse(responseContent).getAsJsonObject().get("list"), return WxDataCubeMsgResult.fromJson(responseContent);
new TypeToken<List<WxDataCubeMsgResult>>() {
}.getType());
} }
@Override @Override
@ -209,9 +182,7 @@ public class WxMpDataCubeServiceImpl implements WxMpDataCubeService {
param.addProperty("end_date", this.dateFormat.format(endDate)); param.addProperty("end_date", this.dateFormat.format(endDate));
String responseContent = this.wxMpService.post(url, param.toString()); String responseContent = this.wxMpService.post(url, param.toString());
this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent); this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent);
return WxMpGsonBuilder.INSTANCE.create().fromJson(new JsonParser().parse(responseContent).getAsJsonObject().get("list"), return WxDataCubeMsgResult.fromJson(responseContent);
new TypeToken<List<WxDataCubeMsgResult>>() {
}.getType());
} }
@Override @Override
@ -223,9 +194,7 @@ public class WxMpDataCubeServiceImpl implements WxMpDataCubeService {
param.addProperty("end_date", this.dateFormat.format(endDate)); param.addProperty("end_date", this.dateFormat.format(endDate));
String responseContent = this.wxMpService.post(url, param.toString()); String responseContent = this.wxMpService.post(url, param.toString());
this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent); this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent);
return WxMpGsonBuilder.INSTANCE.create().fromJson(new JsonParser().parse(responseContent).getAsJsonObject().get("list"), return WxDataCubeMsgResult.fromJson(responseContent);
new TypeToken<List<WxDataCubeMsgResult>>() {
}.getType());
} }
@Override @Override
@ -237,9 +206,7 @@ public class WxMpDataCubeServiceImpl implements WxMpDataCubeService {
param.addProperty("end_date", this.dateFormat.format(endDate)); param.addProperty("end_date", this.dateFormat.format(endDate));
String responseContent = this.wxMpService.post(url, param.toString()); String responseContent = this.wxMpService.post(url, param.toString());
this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent); this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent);
return WxMpGsonBuilder.INSTANCE.create().fromJson(new JsonParser().parse(responseContent).getAsJsonObject().get("list"), return WxDataCubeMsgResult.fromJson(responseContent);
new TypeToken<List<WxDataCubeMsgResult>>() {
}.getType());
} }
@Override @Override
@ -251,9 +218,7 @@ public class WxMpDataCubeServiceImpl implements WxMpDataCubeService {
param.addProperty("end_date", this.dateFormat.format(endDate)); param.addProperty("end_date", this.dateFormat.format(endDate));
String responseContent = this.wxMpService.post(url, param.toString()); String responseContent = this.wxMpService.post(url, param.toString());
this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent); this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent);
return WxMpGsonBuilder.INSTANCE.create().fromJson(new JsonParser().parse(responseContent).getAsJsonObject().get("list"), return WxDataCubeInterfaceResult.fromJson(responseContent);
new TypeToken<List<WxDataCubeInterfaceResult>>() {
}.getType());
} }
@Override @Override
@ -265,8 +230,6 @@ public class WxMpDataCubeServiceImpl implements WxMpDataCubeService {
param.addProperty("end_date", this.dateFormat.format(endDate)); param.addProperty("end_date", this.dateFormat.format(endDate));
String responseContent = this.wxMpService.post(url, param.toString()); String responseContent = this.wxMpService.post(url, param.toString());
this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent); this.log.debug("\nurl:{}\nparams:{}\nresponse:{}",url, param, responseContent);
return WxMpGsonBuilder.INSTANCE.create().fromJson(new JsonParser().parse(responseContent).getAsJsonObject().get("list"), return WxDataCubeInterfaceResult.fromJson(responseContent);
new TypeToken<List<WxDataCubeInterfaceResult>>() {
}.getType());
} }
} }

View File

@ -1,6 +1,12 @@
package me.chanjar.weixin.mp.bean.datacube; package me.chanjar.weixin.mp.bean.datacube;
import java.util.List;
import com.google.gson.JsonParser;
import com.google.gson.annotations.SerializedName; import com.google.gson.annotations.SerializedName;
import com.google.gson.reflect.TypeToken;
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
/** /**
* 图文分析数据接口返回结果对象 * 图文分析数据接口返回结果对象
@ -9,6 +15,8 @@ import com.google.gson.annotations.SerializedName;
*/ */
public class WxDataCubeArticleResult extends WxDataCubeBaseResult { public class WxDataCubeArticleResult extends WxDataCubeBaseResult {
private static final JsonParser JSON_PARSER = new JsonParser();
/** /**
* ref_hour * ref_hour
* 数据的小时包括从000到2300分别代表的是[000,100)[2300,2400)即每日的第1小时和最后1小时 * 数据的小时包括从000到2300分别代表的是[000,100)[2300,2400)即每日的第1小时和最后1小时
@ -203,5 +211,11 @@ public class WxDataCubeArticleResult extends WxDataCubeBaseResult {
public void setUserSource(Integer userSource) { public void setUserSource(Integer userSource) {
this.userSource = userSource; this.userSource = userSource;
} }
public static List<WxDataCubeArticleResult> fromJson(String json) {
return WxMpGsonBuilder.INSTANCE.create().fromJson(
JSON_PARSER.parse(json).getAsJsonObject().get("list"),
new TypeToken<List<WxDataCubeArticleResult>>() {
}.getType());
}
} }

View File

@ -1,9 +1,13 @@
package me.chanjar.weixin.mp.bean.datacube; package me.chanjar.weixin.mp.bean.datacube;
import com.google.gson.annotations.SerializedName;
import java.util.List; import java.util.List;
import com.google.gson.JsonParser;
import com.google.gson.annotations.SerializedName;
import com.google.gson.reflect.TypeToken;
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
/** /**
* 图文分析数据接口返回结果对象 * 图文分析数据接口返回结果对象
* @author binarywang(https://github.com/binarywang) * @author binarywang(https://github.com/binarywang)
@ -11,6 +15,8 @@ import java.util.List;
*/ */
public class WxDataCubeArticleTotal extends WxDataCubeBaseResult { public class WxDataCubeArticleTotal extends WxDataCubeBaseResult {
private static final JsonParser JSON_PARSER = new JsonParser();
/** /**
* msgid * msgid
* 请注意这里的msgid实际上是由msgid图文消息id这也就是群发接口调用后返回的msg_data_id和index消息次序索引组成 例如12003_3 其中12003是msgid即一次群发的消息的id 3为index假设该次群发的图文消息共5个文章因为可能为多图文3表示5个中的第3个 * 请注意这里的msgid实际上是由msgid图文消息id这也就是群发接口调用后返回的msg_data_id和index消息次序索引组成 例如12003_3 其中12003是msgid即一次群发的消息的id 3为index假设该次群发的图文消息共5个文章因为可能为多图文3表示5个中的第3个
@ -55,5 +61,11 @@ public class WxDataCubeArticleTotal extends WxDataCubeBaseResult {
public void setDetails(List<WxDataCubeArticleTotalDetail> details) { public void setDetails(List<WxDataCubeArticleTotalDetail> details) {
this.details = details; this.details = details;
} }
public static List<WxDataCubeArticleTotal> fromJson(String json) {
return WxMpGsonBuilder.INSTANCE.create().fromJson(
JSON_PARSER.parse(json).getAsJsonObject().get("list"),
new TypeToken<List<WxDataCubeArticleTotal>>() {
}.getType());
}
} }

View File

@ -1,6 +1,12 @@
package me.chanjar.weixin.mp.bean.datacube; package me.chanjar.weixin.mp.bean.datacube;
import java.util.List;
import com.google.gson.JsonParser;
import com.google.gson.annotations.SerializedName; import com.google.gson.annotations.SerializedName;
import com.google.gson.reflect.TypeToken;
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
/** /**
* 接口分析数据接口返回结果对象 * 接口分析数据接口返回结果对象
@ -9,6 +15,8 @@ import com.google.gson.annotations.SerializedName;
*/ */
public class WxDataCubeInterfaceResult extends WxDataCubeBaseResult { public class WxDataCubeInterfaceResult extends WxDataCubeBaseResult {
private static final JsonParser JSON_PARSER = new JsonParser();
/** /**
* ref_hour * ref_hour
* 数据的小时包括从000到2300分别代表的是[000,100)[2300,2400)即每日的第1小时和最后1小时 * 数据的小时包括从000到2300分别代表的是[000,100)[2300,2400)即每日的第1小时和最后1小时
@ -83,5 +91,12 @@ public class WxDataCubeInterfaceResult extends WxDataCubeBaseResult {
public void setMaxTimeCost(Integer maxTimeCost) { public void setMaxTimeCost(Integer maxTimeCost) {
this.maxTimeCost = maxTimeCost; this.maxTimeCost = maxTimeCost;
} }
public static List<WxDataCubeInterfaceResult> fromJson(String json) {
return WxMpGsonBuilder.INSTANCE.create().fromJson(
JSON_PARSER.parse(json).getAsJsonObject().get("list"),
new TypeToken<List<WxDataCubeInterfaceResult>>() {
}.getType());
}
} }

View File

@ -1,6 +1,12 @@
package me.chanjar.weixin.mp.bean.datacube; package me.chanjar.weixin.mp.bean.datacube;
import java.util.List;
import com.google.gson.JsonParser;
import com.google.gson.annotations.SerializedName; import com.google.gson.annotations.SerializedName;
import com.google.gson.reflect.TypeToken;
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
/** /**
* 消息分析数据接口返回结果对象 * 消息分析数据接口返回结果对象
@ -9,6 +15,8 @@ import com.google.gson.annotations.SerializedName;
*/ */
public class WxDataCubeMsgResult extends WxDataCubeBaseResult { public class WxDataCubeMsgResult extends WxDataCubeBaseResult {
private static final JsonParser JSON_PARSER = new JsonParser();
/** /**
* ref_hour * ref_hour
* 数据的小时包括从000到2300分别代表的是[000,100)[2300,2400)即每日的第1小时和最后1小时 * 数据的小时包括从000到2300分别代表的是[000,100)[2300,2400)即每日的第1小时和最后1小时
@ -114,4 +122,11 @@ public class WxDataCubeMsgResult extends WxDataCubeBaseResult {
this.oriPageReadUser = oriPageReadUser; this.oriPageReadUser = oriPageReadUser;
} }
public static List<WxDataCubeMsgResult> fromJson(String json) {
return WxMpGsonBuilder.INSTANCE.create().fromJson(
JSON_PARSER.parse(json).getAsJsonObject().get("list"),
new TypeToken<List<WxDataCubeMsgResult>>() {
}.getType());
}
} }

View File

@ -1,19 +1,27 @@
package me.chanjar.weixin.mp.bean.datacube; package me.chanjar.weixin.mp.bean.datacube;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle; import org.apache.commons.lang3.builder.ToStringStyle;
import java.io.Serializable; import com.google.gson.JsonParser;
import java.util.Date; import com.google.gson.reflect.TypeToken;
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
/** /**
* <pre> * <pre>
* 累计用户数据接口的返回JSON数据包 * 累计用户数据接口的返回JSON数据包
* http://mp.weixin.qq.com/wiki/3/ecfed6e1a0a03b5f35e5efac98e864b7.html * 详情查看文档<a href="http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141082&token=&lang=zh_CN">用户分析数据接口</a>
* </pre> * </pre>
*/ */
public class WxDataCubeUserCumulate implements Serializable { public class WxDataCubeUserCumulate implements Serializable {
private static final JsonParser JSON_PARSER = new JsonParser();
private static final long serialVersionUID = -3570981300225093657L; private static final long serialVersionUID = -3570981300225093657L;
private Date refDate; private Date refDate;
@ -40,4 +48,11 @@ public class WxDataCubeUserCumulate implements Serializable {
public String toString() { public String toString() {
return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE); return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE);
} }
public static List<WxDataCubeUserCumulate> fromJson(String json) {
return WxMpGsonBuilder.INSTANCE.create().fromJson(
JSON_PARSER.parse(json).getAsJsonObject().get("list"),
new TypeToken<List<WxDataCubeUserCumulate>>() {
}.getType());
}
} }

View File

@ -1,20 +1,28 @@
package me.chanjar.weixin.mp.bean.datacube; package me.chanjar.weixin.mp.bean.datacube;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle; import org.apache.commons.lang3.builder.ToStringStyle;
import java.io.Serializable; import com.google.gson.JsonParser;
import java.util.Date; import com.google.gson.reflect.TypeToken;
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
/** /**
* <pre> * <pre>
* 用户增减数据接口的返回JSON数据包 * 用户增减数据接口的返回JSON数据包
* http://mp.weixin.qq.com/wiki/3/ecfed6e1a0a03b5f35e5efac98e864b7.html * 详情查看文档<a href="http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141082&token=&lang=zh_CN">用户分析数据接口</a>
* </pre> * </pre>
*/ */
public class WxDataCubeUserSummary implements Serializable { public class WxDataCubeUserSummary implements Serializable {
private static final long serialVersionUID = -2336654489906694173L; private static final long serialVersionUID = -2336654489906694173L;
private static final JsonParser JSON_PARSER = new JsonParser();
private Date refDate; private Date refDate;
private Integer userSource; private Integer userSource;
@ -59,4 +67,11 @@ public class WxDataCubeUserSummary implements Serializable {
public String toString() { public String toString() {
return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE); return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE);
} }
public static List<WxDataCubeUserSummary> fromJson(String json) {
return WxMpGsonBuilder.INSTANCE.create().fromJson(
JSON_PARSER.parse(json).getAsJsonObject().get("list"),
new TypeToken<List<WxDataCubeUserSummary>>() {
}.getType());
}
} }