mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-12-21 19:10:01 +08:00
issue #3 获取用户基本信息
This commit is contained in:
@@ -6,6 +6,7 @@ import chanjarster.weixin.bean.WxMassGroupMessage;
|
||||
import chanjarster.weixin.bean.WxMassNews;
|
||||
import chanjarster.weixin.bean.WxMassOpenIdsMessage;
|
||||
import chanjarster.weixin.bean.WxMenu;
|
||||
import chanjarster.weixin.bean.result.WxUser;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
@@ -22,7 +23,7 @@ public class WxGsonBuilder {
|
||||
INSTANCE.registerTypeAdapter(WxMassGroupMessage.class, new WxMassMessageGsonAdapter());
|
||||
INSTANCE.registerTypeAdapter(WxMassOpenIdsMessage.class, new WxMassOpenIdsMessageGsonAdapter());
|
||||
INSTANCE.registerTypeAdapter(WxGroup.class, new WxGroupGsonAdapter());
|
||||
|
||||
INSTANCE.registerTypeAdapter(WxUser.class, new WxUserGsonAdapter());
|
||||
}
|
||||
|
||||
public static Gson create() {
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* KINGSTAR MEDIA SOLUTIONS Co.,LTD. Copyright c 2005-2013. All rights reserved.
|
||||
*
|
||||
* This source code is the property of KINGSTAR MEDIA SOLUTIONS LTD. It is intended
|
||||
* only for the use of KINGSTAR MEDIA application development. Reengineering, reproduction
|
||||
* arose from modification of the original source, or other redistribution of this source
|
||||
* is not permitted without written permission of the KINGSTAR MEDIA SOLUTIONS LTD.
|
||||
*/
|
||||
package chanjarster.weixin.util.json;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
import chanjarster.weixin.bean.result.WxUser;
|
||||
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonDeserializer;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParseException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author qianjia
|
||||
*
|
||||
*/
|
||||
public class WxUserGsonAdapter implements JsonDeserializer<WxUser> {
|
||||
|
||||
public WxUser deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
||||
JsonObject o = json.getAsJsonObject();
|
||||
WxUser wxUser = new WxUser();
|
||||
wxUser.setSubscribe(new Integer(0).equals(GsonHelper.getInteger(o, "subscribe")) ? false : true);
|
||||
wxUser.setCity(GsonHelper.getString(o, "city"));
|
||||
wxUser.setCountry(GsonHelper.getString(o, "country"));
|
||||
wxUser.setHeadimgurl(GsonHelper.getString(o, "headimgurl"));
|
||||
wxUser.setLanguage(GsonHelper.getString(o, "language"));
|
||||
wxUser.setNickname(GsonHelper.getString(o, "nickname"));
|
||||
wxUser.setOpenid(GsonHelper.getString(o, "openid"));
|
||||
wxUser.setProvince(GsonHelper.getString(o, "province"));
|
||||
wxUser.setSubscribe_time(GsonHelper.getLong(o, "subscribe_time"));
|
||||
wxUser.setUnionid(GsonHelper.getString(o, "unionid"));
|
||||
Integer sex = GsonHelper.getInteger(o, "sex");
|
||||
if(new Integer(1).equals(sex)) {
|
||||
wxUser.setSex("男");
|
||||
} else if (new Integer(2).equals(sex)) {
|
||||
wxUser.setSex("女");
|
||||
} else {
|
||||
wxUser.setSex("未知");
|
||||
}
|
||||
return wxUser;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user