<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
    數(shù)據(jù)加載中……
    Jdom+HttpClient寫的校內(nèi)網(wǎng)APP平臺用戶信息獲取類

    校內(nèi)官方提供的不會用。沒說明,也懶得看代碼。自己寫了一個(gè)基本信息獲取class。功能有限,主要是為了這幾天要開發(fā)的一個(gè)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;

     /**
     * 調(diào)用校內(nèi)Web服務(wù)的客戶端
     * @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);
            //創(chuàng)建新的輸入源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;
     
     }
        //編碼轉(zhuǎn)換
        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;
        }
        //獲取用戶標(biāo)準(zhǔn)頭像圖片url
        public String getHeadurl(String uid) throws HttpException, IOException, JDOMException{
         String headurl = this.getStream(uid, "headurl");
         
      return headurl;
         
        }
        //獲取用戶家鄉(xiāng)所 省
        public String getProvince(String uid) throws HttpException, IOException, JDOMException{
         String province = this.getStream(uid, "province");
      return province; 
        }
        //獲取用戶家鄉(xiāng)所在城市
        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)  編輯  收藏


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


    網(wǎng)站導(dǎo)航:
     
    主站蜘蛛池模板: 亚洲av中文无码乱人伦在线咪咕| 最近中文字幕2019高清免费| 美女无遮挡免费视频网站| 亚洲黄页网在线观看| www.亚洲成在线| 亚洲宅男精品一区在线观看| 亚洲一区二区影视| 久久久久久亚洲精品影院| 亚洲 欧洲 日韩 综合在线| 亚洲中文无码mv| 亚洲a∨无码精品色午夜| 婷婷国产偷v国产偷v亚洲| 免费视频成人国产精品网站| 一区二区三区视频免费| 巨胸狂喷奶水视频www网站免费| 伊人免费在线观看| 免费无码中文字幕A级毛片| 亚洲最大免费视频网| 日韩精品无码区免费专区| 国产精品麻豆免费版| 亚洲一区二区三区免费| 好看的电影网站亚洲一区| 在线电影你懂的亚洲| 亚洲影视自拍揄拍愉拍| 国产精品久久久久久亚洲小说| 一级特黄录像视频免费| 特级做A爰片毛片免费看无码| 热re99久久6国产精品免费| av无码国产在线看免费网站| 日韩中文字幕在线免费观看| 国产精品亚洲mnbav网站 | 一区二区三区视频免费观看| 两个人看的www免费视频中文| 最近免费最新高清中文字幕韩国 | 暖暖在线视频免费视频| 免费影院未满十八勿进网站| 国产午夜免费秋霞影院| 最新亚洲成av人免费看| 亚洲成人免费网站| 男女超爽视频免费播放| 久久青草精品38国产免费|