<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    Pencil.Java

    to dig Java
    數據加載中……
    Jdom+HttpClient寫的校內網APP平臺用戶信息獲取類

    校內官方提供的不會用。沒說明,也懶得看代碼。自己寫了一個基本信息獲取class。功能有限,主要是為了這幾天要開發的一個APP所用。

     

    package xiaonei;
    import java.io.IOException;
    import java.io.StringReader;
    import java.util.List;

    import org.apache.commons.httpclient.HttpClient;
    import org.apache.commons.httpclient.HttpException;
    import org.apache.commons.httpclient.NameValuePair;
    import org.apache.commons.httpclient.methods.PostMethod;
    import org.jdom.Document;
    import org.jdom.Element;
    import org.jdom.JDOMException;
    import org.jdom.Namespace;
    import org.jdom.input.SAXBuilder;
    import org.xml.sax.InputSource;

     /**
     * 調用校內Web服務的客戶端
     * @author Pencil 

     * @QQ 552526

     */


    //生成客戶端
    public class Client{
     private String apikey = "";
     private String sessionkey = "";
     public Client(String apikey,String sessionkey){
      this.apikey = apikey;
      this.sessionkey = sessionkey;
      
     }
     
        public String getStream(String uid,String field) throws HttpException, IOException, JDOMException{
         HttpClient client = new HttpClient();
         PostMethod post = new UTF8PostMethod("

            NameValuePair[] fixedParam = {
                    new NameValuePair("method", "xiaonei.users.getInfo"),
                    new NameValuePair("v", "1.0"),
                    new NameValuePair("api_key", apikey),
                    new NameValuePair("session_key", sessionkey),
                    new NameValuePair("fields",field ),
                    new NameValuePair("uids", uid)
                };
            post.addParameters(fixedParam);
            client.executeMethod(post);
           
         String s = post.getResponseBodyAsString();
            StringReader read = new StringReader(s);
            //創建新的輸入源SAX 解析器將使用 InputSource 對象來確定如何讀取 XML 輸入
            InputSource source = new InputSource(read);
         SAXBuilder builder = new SAXBuilder();

      Document doc = builder.build(source);
      Element foo = doc.getRootElement(); 
         Namespace ns = foo.getNamespace();
      List allChildren = foo.getChildren();
      String info = ((Element)allChildren.get(0)).getChild(field,ns).getText();
            if(field.equals("province")){
             String province = ((Element)allChildren.get(0)).getChild("hometown_location",ns).getChild("province",ns).getText();
                return province;
            }
            if(field.equals("city")){
             String city = ((Element)allChildren.get(0)).getChild("hometown_location",ns).getChild("city",ns).getText();
                return city;
            }
            return info;
     
     }
        //編碼轉換
        public static class UTF8PostMethod extends PostMethod {

            public UTF8PostMethod(String url) {
                super(url);
            }

            @Override
            public String getRequestCharSet() {
                //return super.getRequestCharSet();
                return "UTF-8";
            }
        }
        //獲取用戶姓名
        public String getName(String uid) throws HttpException, IOException, JDOMException{
         String name = this.getStream(uid, "name");
      return name;
         
        }
        //獲取用戶性別 true是男
        public boolean getSex(String uid) throws HttpException, IOException, JDOMException{
         String sex = this.getStream(uid, "sex");
         if(sex.equals("1"))
          return true;
         else
          return false;
         
        }
        //獲取用戶生日  格式:yyyy-MM-dd
        public String getBirthday(String uid) throws HttpException, IOException, JDOMException{
         String birthday = this.getStream(uid, "birthday");
         return birthday;
         
        }
        //判斷用戶是否為星級用戶  true 為是
        public boolean isStar(String uid) throws HttpException, IOException, JDOMException{
         String star = this.getStream(uid, "star");
         if(star.equals("1"))
          return true;
         else
          return false;
        }
        //獲取用戶小圖url  
        public String getTinyurl(String uid) throws HttpException, IOException, JDOMException{
         String tinyurl = this.getStream(uid, "tinyurl");
         return tinyurl;
        }
        //獲取用戶標準頭像圖片url
        public String getHeadurl(String uid) throws HttpException, IOException, JDOMException{
         String headurl = this.getStream(uid, "headurl");
         
      return headurl;
         
        }
        //獲取用戶家鄉所 省
        public String getProvince(String uid) throws HttpException, IOException, JDOMException{
         String province = this.getStream(uid, "province");
      return province; 
        }
        //獲取用戶家鄉所在城市
        public String getCity(String uid) throws HttpException, IOException, JDOMException{
         String city = this.getStream(uid, "city");
         return city;     
        }
       

    }

    posted on 2009-04-17 23:33 鉛筆 閱讀(660) 評論(0)  編輯  收藏


    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    主站蜘蛛池模板: 亚洲国产成AV人天堂无码| 亚洲国产婷婷六月丁香| 色偷偷亚洲女人天堂观看欧| 日韩精品免费视频| 亚洲激情在线视频| 99re免费在线视频| 久久久久亚洲AV片无码下载蜜桃| 99久久综合精品免费| 亚洲精品国产免费| 丁香花免费完整高清观看| 天堂亚洲国产中文在线| 日韩激情淫片免费看| 青青青视频免费观看| 久久久久久久亚洲精品| 青青青国产手机频在线免费观看| 亚洲成人在线电影| 97在线观看永久免费视频| 亚洲精品蜜夜内射| 亚洲成人一区二区| 中文成人久久久久影院免费观看 | 国产1024精品视频专区免费| 亚洲一区二区观看播放| 国产女高清在线看免费观看| 一级毛片免费在线| 亚洲午夜视频在线观看| 一二三四免费观看在线电影| 亚洲爆乳成av人在线视菜奈实 | 亚洲成AV人片天堂网无码| 91香蕉在线观看免费高清| 亚洲伊人久久大香线焦| 午夜a级成人免费毛片| 国产日韩在线视频免费播放| 亚洲精品视频观看| 国产真实伦在线视频免费观看| 一级人做人爰a全过程免费视频 | 久久国产乱子免费精品| 亚洲av无码不卡久久| 伊人久久亚洲综合影院| 毛片无码免费无码播放| 美女露100%胸无遮挡免费观看 | 久久精品国产亚洲香蕉|