package com.partynetwork.iparty.app.bean; import java.io.IOException; import java.io.InputStream; import org.codehaus.jackson.JsonNode; import org.codehaus.jackson.JsonProcessingException; import org.codehaus.jackson.map.ObjectMapper; import com.lidroid.xutils.util.LogUtils; import com.partynetwork.dataprovider.util.StringUtil; import com.partynetwork.iparty.app.AppException; import com.partynetwork.iparty.app.util.StringUtils; /** * 登录用户实体类 * * @version 1.0 * @created 2012-3-21 */ public class BLogin extends Base { /** * */ private static final long serialVersionUID = -6612654551253059019L; public final static int RELATION_ACTION_DELETE = 0x00;// 取消关注 public final static int RELATION_ACTION_ADD = 0x01;// 加关注 public final static int RELATION_TYPE_BOTH = 0x01;// 双方互为粉丝 public final static int RELATION_TYPE_FANS_HIM = 0x02;// 你单方面关注他 public final static int RELATION_TYPE_NULL = 0x03;// 互不关注 public final static int RELATION_TYPE_FANS_ME = 0x04;// 只有他关注我 private int uid; private String location; private String name; private String face; private String account; private String pwd; private int sex; private int age; private String state; private boolean isRememberMe; private int authType; private String weiboAccessToken; private String phone; private String email; public BLogin(int uid, String location, String name, String face, int sex, int age, String state, int authType, String weiboAccessToken,String phone,String email) { super(); this.uid = uid; this.location = location; this.name = name; this.face = face; this.sex = sex; this.age = age; this.state = state; this.authType = authType; this.weiboAccessToken = weiboAccessToken; this.phone=phone; this.email=email; } public BLogin() { super(); } public int getUid() { return uid; } public void setUid(int uid) { this.uid = uid; } public String getLocation() { return location; } public void setLocation(String location) { this.location = location; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getFace() { return face; } public void setFace(String face) { this.face = face; } public String getAccount() { return account; } public void setAccount(String account) { this.account = account; } public String getPwd() { return pwd; } public void setPwd(String pwd) { this.pwd = pwd; } public boolean isRememberMe() { return isRememberMe; } public void setRememberMe(boolean isRememberMe) { this.isRememberMe = isRememberMe; } public int getSex() { return sex; } public void setSex(int sex) { this.sex = sex; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public String getState() { return state; } public void setState(String state) { this.state = state; } public int getAuthType() { return authType; } public void setAuthType(int authType) { this.authType = authType; } public String getWeiboAccessToken() { return weiboAccessToken; } public void setWeiboAccessToken(String weiboAccessToken) { this.weiboAccessToken = weiboAccessToken; } public String getPhone() { return phone; } public void setPhone(String phone) { this.phone = phone; } public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } public static BLogin parse(InputStream stream) throws AppException { String str = StringUtil.convertStreamToString(stream); LogUtils.i("登陆返回json:"+str); ObjectMapper om = new ObjectMapper(); try { JsonNode rootNode = om.readTree(str); int result = rootNode.path("result").getIntValue(); if (result == 0) { // 失败 String why = rootNode.path("description").getTextValue(); throw AppException.fail(why); } else if (result == 1) { // 成功 JsonNode dataNode = rootNode.path("details"); int id = StringUtils.toInt(dataNode.path("userId") .getValueAsText(), 0); String face = dataNode.path("userHeadUrl").getValueAsText(); String name = dataNode.path("userName").getValueAsText(); String city = dataNode.path("userCity").getValueAsText(); int age = StringUtils.toInt(dataNode.path("userAge") .getValueAsText(), 0); int sex = StringUtils.toInt(dataNode.path("userSex") .getValueAsText(), 0); String state = dataNode.path("userState").getValueAsText(); int authType = StringUtils.toInt(dataNode.path("authType") .getValueAsText(), 0); String weiboAccessToken = dataNode.path("weiboAccessToken") .getValueAsText(); String phone=dataNode.path("userPhone").getValueAsText(); String email=dataNode.path("userEmail").getValueAsText(); return new BLogin(id, city, name, face, sex, age, state, authType, weiboAccessToken,phone,email); } else { throw AppException.fail("接口异常"); } } catch (JsonProcessingException e) { throw AppException.json(e); } catch (IOException e) { throw AppException.io(e); } } }