issue #90 WxMpUser添加sexId字段,和微信返回的性别字段保持一致

This commit is contained in:
Daniel Qian
2015-01-27 13:34:14 +08:00
parent 4dc297c5ed
commit 6d383fa90e
3 changed files with 21 additions and 7 deletions

View File

@@ -20,7 +20,11 @@ public class WxMpUser {
protected String headImgUrl; protected String headImgUrl;
protected Long subscribeTime; protected Long subscribeTime;
protected String unionId; protected String unionId;
protected Integer sexId;
public Boolean getSubscribe() {
return subscribe;
}
public Boolean isSubscribe() { public Boolean isSubscribe() {
return subscribe; return subscribe;
} }
@@ -87,7 +91,16 @@ public class WxMpUser {
public void setUnionId(String unionId) { public void setUnionId(String unionId) {
this.unionId = unionId; this.unionId = unionId;
} }
public Integer getSexId() {
return sexId;
}
public void setSexId(Integer sexId) {
this.sexId = sexId;
}
public static WxMpUser fromJson(String json) { public static WxMpUser fromJson(String json) {
return WxMpGsonBuilder.INSTANCE.create().fromJson(json, WxMpUser.class); return WxMpGsonBuilder.INSTANCE.create().fromJson(json, WxMpUser.class);
} }

View File

@@ -16,7 +16,7 @@ public class WxMpGsonBuilder {
INSTANCE.registerTypeAdapter(WxMpMassGroupMessage.class, new WxMpMassGroupMessageGsonAdapter()); INSTANCE.registerTypeAdapter(WxMpMassGroupMessage.class, new WxMpMassGroupMessageGsonAdapter());
INSTANCE.registerTypeAdapter(WxMpMassOpenIdsMessage.class, new WxMpMassOpenIdsMessageGsonAdapter()); INSTANCE.registerTypeAdapter(WxMpMassOpenIdsMessage.class, new WxMpMassOpenIdsMessageGsonAdapter());
INSTANCE.registerTypeAdapter(WxMpGroup.class, new WxMpGroupGsonAdapter()); INSTANCE.registerTypeAdapter(WxMpGroup.class, new WxMpGroupGsonAdapter());
INSTANCE.registerTypeAdapter(WxMpUser.class, new WxUserGsonAdapter()); INSTANCE.registerTypeAdapter(WxMpUser.class, new WxMpUserGsonAdapter());
INSTANCE.registerTypeAdapter(WxMpUserList.class, new WxUserListGsonAdapter()); INSTANCE.registerTypeAdapter(WxMpUserList.class, new WxUserListGsonAdapter());
INSTANCE.registerTypeAdapter(WxMpMassVideo.class, new WxMpMassVideoAdapter()); INSTANCE.registerTypeAdapter(WxMpMassVideo.class, new WxMpMassVideoAdapter());
INSTANCE.registerTypeAdapter(WxMpMassSendResult.class, new WxMpMassSendResultAdapter()); INSTANCE.registerTypeAdapter(WxMpMassSendResult.class, new WxMpMassSendResultAdapter());

View File

@@ -14,7 +14,7 @@ import me.chanjar.weixin.mp.bean.result.WxMpUser;
import java.lang.reflect.Type; import java.lang.reflect.Type;
public class WxUserGsonAdapter implements JsonDeserializer<WxMpUser> { public class WxMpUserGsonAdapter implements JsonDeserializer<WxMpUser> {
public WxMpUser deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { public WxMpUser deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
JsonObject o = json.getAsJsonObject(); JsonObject o = json.getAsJsonObject();
@@ -29,10 +29,11 @@ public class WxUserGsonAdapter implements JsonDeserializer<WxMpUser> {
wxMpUser.setProvince(GsonHelper.getString(o, "province")); wxMpUser.setProvince(GsonHelper.getString(o, "province"));
wxMpUser.setSubscribeTime(GsonHelper.getLong(o, "subscribe_time")); wxMpUser.setSubscribeTime(GsonHelper.getLong(o, "subscribe_time"));
wxMpUser.setUnionId(GsonHelper.getString(o, "unionid")); wxMpUser.setUnionId(GsonHelper.getString(o, "unionid"));
Integer sex = GsonHelper.getInteger(o, "sex"); Integer sexId = GsonHelper.getInteger(o, "sex");
if(new Integer(1).equals(sex)) { wxMpUser.setSexId(sexId);
if(new Integer(1).equals(sexId)) {
wxMpUser.setSex(""); wxMpUser.setSex("");
} else if (new Integer(2).equals(sex)) { } else if (new Integer(2).equals(sexId)) {
wxMpUser.setSex(""); wxMpUser.setSex("");
} else { } else {
wxMpUser.setSex("未知"); wxMpUser.setSex("未知");