Play Framework - 接口定義&與客戶端交互


接口定義:

    頻道列表:

            接口名稱:channelList html

            參數說明: android

                        

名稱 類型 是否必選 說明
offset
int 當前遊標偏移量
count int 請求總數,默認爲10
            請求實例

        

{
  "client": {
    "height": 1280,
    "width": 720
  },
  "data": {
    "offset": 1,
    "count": 50
  },
  "token": ""
}





            返回實例
git


{
  "service": "channels",
  "state": {
    "tips": null,
    "code": 200,
    "msg": "OK"
  },
  "data": {
    "content": [
      {
        "id": 98,
        "cid": "T1370583240249",
        "cname": "原創",
        "subnum": "9.7萬",
        "extra": null
      },
      {
        "id": 99,
        "cid": "T1348649145984",
        "cname": "NBA",
        "subnum": "3.1萬",
        "extra": null
      },
      {
        "id": 100,
        "cid": "T1348647909107",
        "cname": "頭條",
        "subnum": "3.2萬",
        "extra": null
      },
      {
        "id": 101,
        "cid": "T1422935072191",
        "cname": "畫報",
        "subnum": "2.4萬",
        "extra": null
      },
      {
        "id": 102,
        "cid": "T1348648037603",
        "cname": "社會",
        "subnum": "100",
        "extra": null
      },
      {
        "id": 103,
        "cid": "T1368497029546",
        "cname": "歷史",
        "subnum": "29.2萬",
        "extra": null
      },
      {
        "id": 104,
        "cid": "T1348648141035",
        "cname": "軍事",
        "subnum": "11.1萬",
        "extra": null
      },
      {
        "id": 105,
        "cid": "T1444289532601",
        "cname": "噠噠",
        "subnum": "2152",
        "extra": null
      },
      {
        "id": 106,
        "cid": "T1348648517839",
        "cname": "娛樂",
        "subnum": "22.3萬",
        "extra": null
      },
      {
        "id": 107,
        "cid": "T1348648650048",
        "cname": "影視",
        "subnum": "204.6萬",
        "extra": null
      },
      {
        "id": 108,
        "cid": "T1348648756099",
        "cname": "財經",
        "subnum": "22.1萬",
        "extra": null
      },
      {
        "id": 109,
        "cid": "T1356600029035",
        "cname": "彩票",
        "subnum": "3.1萬",
        "extra": null
      },
      {
        "id": 110,
        "cid": "T1348649079062",
        "cname": "體育",
        "subnum": "19.1萬",
        "extra": null
      },
      {
        "id": 111,
        "cid": "T1348649503389",
        "cname": "中國足球",
        "subnum": "1.8萬",
        "extra": null
      },
      {
        "id": 112,
        "cid": "T1348649176279",
        "cname": "國際足球",
        "subnum": "2.5萬",
        "extra": null
      },
      {
        "id": 113,
        "cid": "T1348649475931",
        "cname": "CBA",
        "subnum": "9837",
        "extra": null
      },
      {
        "id": 114,
        "cid": "T1411113472760",
        "cname": "跑步",
        "subnum": "5648",
        "extra": null
      },
      {
        "id": 115,
        "cid": "T1348649580692",
        "cname": "科技",
        "subnum": "27.5萬",
        "extra": null
      },
      {
        "id": 116,
        "cid": "T1348649654285",
        "cname": "手機",
        "subnum": "13萬",
        "extra": null
      },
      {
        "id": 117,
        "cid": "T1348649776727",
        "cname": "數碼",
        "subnum": "10.4萬",
        "extra": null
      },
      {
        "id": 118,
        "cid": "T1351233117091",
        "cname": "移動互聯",
        "subnum": "7.1萬",
        "extra": null
      },
      {
        "id": 119,
        "cid": "T1350383429665",
        "cname": "輕鬆一刻",
        "subnum": "604.3萬",
        "extra": null
      },
      {
        "id": 120,
        "cid": "T1421997195219",
        "cname": "雲課堂",
        "subnum": "6080",
        "extra": null
      },
      {
        "id": 121,
        "cid": "T1348654060988",
        "cname": "汽車",
        "subnum": "25.8萬",
        "extra": null
      },
      {
        "id": 122,
        "cid": "T1348654085632",
        "cname": "房產",
        "subnum": "23.5萬",
        "extra": null
      },
      {
        "id": 123,
        "cid": "T1348654105308",
        "cname": "家居",
        "subnum": "3.7萬",
        "extra": null
      },
      {
        "id": 124,
        "cid": "T1348654151579",
        "cname": "遊戲",
        "subnum": "6.1萬",
        "extra": null
      },
      {
        "id": 125,
        "cid": "T1348654204705",
        "cname": "旅遊",
        "subnum": "4.3萬",
        "extra": null
      },
      {
        "id": 126,
        "cid": "T1414389941036",
        "cname": "健康",
        "subnum": "1.5萬",
        "extra": null
      },
      {
        "id": 127,
        "cid": "T1401272877187",
        "cname": "讀書",
        "subnum": "3.9萬",
        "extra": null
      },
      {
        "id": 128,
        "cid": "T1385429690972",
        "cname": "酒香",
        "subnum": "1.4萬",
        "extra": null
      },
      {
        "id": 129,
        "cid": "T1348654225495",
        "cname": "教育",
        "subnum": "3.1萬",
        "extra": null
      },
      {
        "id": 130,
        "cid": "T1397116135282",
        "cname": "親子",
        "subnum": "2.5萬",
        "extra": null
      },
      {
        "id": 131,
        "cid": "T1402031665628",
        "cname": "葡萄酒",
        "subnum": "9772",
        "extra": null
      },
      {
        "id": 132,
        "cid": "T1432711055315",
        "cname": "你照嗎",
        "subnum": "1402",
        "extra": null
      },
      {
        "id": 133,
        "cid": "T1397016069906",
        "cname": "暴雪遊戲",
        "subnum": "2.3萬",
        "extra": null
      },
      {
        "id": 134,
        "cid": "T1444270454635",
        "cname": "漫畫",
        "subnum": "2160",
        "extra": null
      },
      {
        "id": 135,
        "cid": "T1348650593803",
        "cname": "時尚",
        "subnum": "24.9萬",
        "extra": null
      },
      {
        "id": 136,
        "cid": "T1348650839000",
        "cname": "情感",
        "subnum": "6.3萬",
        "extra": null
      },
      {
        "id": 137,
        "cid": "T1414142214384",
        "cname": "政務",
        "subnum": "2.6萬",
        "extra": null
      },
      {
        "id": 138,
        "cid": "T1441074311424",
        "cname": "藝術",
        "subnum": "2730",
        "extra": null
      },
      {
        "id": 139,
        "cid": "T1420771091297",
        "cname": "值得買",
        "subnum": "4963",
        "extra": null
      },
      {
        "id": 140,
        "cid": "T1419315959525",
        "cname": "跟貼",
        "subnum": "4.2萬",
        "extra": null
      },
      {
        "id": 141,
        "cid": "T1419316284722",
        "cname": "段子",
        "subnum": "6.9萬",
        "extra": null
      },
      {
        "id": 142,
        "cid": "T1419316384474",
        "cname": "圖片",
        "subnum": "4.4萬",
        "extra": null
      },
      {
        "id": 143,
        "cid": "T1419316531256",
        "cname": "本地",
        "subnum": "8.8萬",
        "extra": null
      },
      {
        "id": 144,
        "cid": "T1419386592923",
        "cname": "論壇",
        "subnum": "5020",
        "extra": null
      },
      {
        "id": 145,
        "cid": "T1427878984398",
        "cname": "熱點",
        "subnum": "4.2萬",
        "extra": null
      },
      {
        "id": 146,
        "cid": "T1433137697241",
        "cname": "直播",
        "subnum": "3.8萬",
        "extra": null
      }
    ],
    "nextOffset": -2,
    "type": 0
  }
}







   新聞列表:

   接口名稱:newsList github

            參數說明: sql

                        

名稱 類型 是否必選 說明
type String 頻道ID
offset
int 當前遊標偏移量
count int 請求總數,默認爲10

            請求實例: json

        

{
  "client": {
    "height": 1280,
    "width": 720
  },
  "data": {
    "type": "T1370583240249",
    "offset": 1,
    "count": 10
  },
  "token": ""
} 

            返回實例:
緩存

 {
  "service": "news",
  "state": {
    "tips": null,
    "code": 200,
    "msg": "OK"
  },
  "data": {
    "content": [
      {
        "id": 1262,
        "title": "俄土交鋒將引起第三次世界大戰?",
        "source": null,
        "cp": "熱觀察",
        "time": 1448396190000,
        "cid": "T1370583240249",
        "snapDetail": "別擔憂了,經濟捆綁、大國制約,「硬漢」秀完就散了吧。",
        "icon": "http://img3.cache.netease.com/3g/2015/11/25/201511250431556b46b.jpg",
        "url": "http://3g.163.com/ntes/15/1125/04/B986K9500004662N.html",
        "extra": null
      },
      {
        "id": 1263,
        "title": "12個關於「黑戶」觸目驚心的事實",
        "source": null,
        "cp": "熱觀察",
        "time": 1448374163000,
        "cid": "T1370583240249",
        "snapDetail": "100箇中國人裏有一個是黑戶;黑戶數量不止1300萬。",
        "icon": "http://img5.cache.netease.com/3g/2015/11/24/20151124221128b154a.jpg",
        "url": "http://3g.163.com/ntes/15/1124/22/B97HK3680004662N.html",
        "extra": null
      },
      {
        "id": 1264,
        "title": "兩個中國棄嬰的美國奇幻之旅",
        "source": null,
        "cp": "大國小民",
        "time": 1448367191000,
        "cid": "T1370583240249",
        "snapDetail": "美女子三年時間前後收養兩棄嬰,意外發現竟是親生姐妹!",
        "icon": "http://img6.cache.netease.com/3g/2015/11/24/20151124203407ebdfe.jpg",
        "url": "http://3g.163.com/ntes/15/1124/20/B97AV9OG000465CI.html",
        "extra": null
      },
      {
        "id": 1265,
        "title": "二孩放開,落戶還要先上環?",
        "source": null,
        "cp": "熱觀察",
        "time": 1448278736000,
        "cid": "T1370583240249",
        "snapDetail": "上億婦女被強制上環;\"先上環再落戶\"沒有法律依據。",
        "icon": "http://img6.cache.netease.com/3g/2015/11/23/201511231957029702e.jpg",
        "url": "http://3g.163.com/ntes/15/1123/19/B94MJSQS0004662N.html",
        "extra": null
      },
      {
        "id": 1266,
        "title": "評:救急就不能\"特事特辦\"?",
        "source": null,
        "cp": "網易新媒體",
        "time": 1448346764000,
        "cid": "T1370583240249",
        "snapDetail": "這究竟是制度僵化,仍是生命意識的匱乏? ",
        "icon": "http://img1.cache.netease.com/3g/2015/11/24/20151124143455a07a3.jpg",
        "url": "http://3g.163.com/ntes/15/1124/14/B96NFTHP00963VRO.html",
        "extra": null
      },
      {
        "id": 1267,
        "title": "「亞洲最大」國有馬場的凋敝",
        "source": null,
        "cp": "網易",
        "time": 1448357089000,
        "cid": "T1370583240249",
        "snapDetail": "軍馬場一萬多職工現在陷於貧困,昔日輝煌一去不返。",
        "icon": "http://img4.cache.netease.com/3g/2015/11/24/20151124174717d42ef.jpg",
        "url": "http://3g.163.com/news/15/1124/17/B971B0MT000153N3.html",
        "extra": null
      },
      {
        "id": 1268,
        "title": "李昆學曾爲成都市長熱門人選",
        "source": null,
        "cp": "路標",
        "time": 1448334139000,
        "cid": "T1370583240249",
        "snapDetail": "曾主抓天網工程,系李春城執政班底內第八名被查者。",
        "icon": "http://img1.cache.netease.com/3g/2015/11/24/20151124111228c7885.jpg",
        "url": "http://3g.163.com/ntes/15/1124/11/B96BEKPN0004662L.html",
        "extra": null
      },
      {
        "id": 1269,
        "title": "圖片故事:手機鏡頭下的地鐵衆生相",
        "source": null,
        "cp": null,
        "time": 1448272356000,
        "cid": "T1370583240249",
        "snapDetail": "在這行色匆匆的人羣裏,還曾記得與你擦身過的身影嗎?",
        "icon": "http://img2.cache.netease.com/3g/2015/11/23/20151123175932b7a78.jpg",
        "url": null,
        "extra": null
      },
      {
        "id": 1270,
        "title": "朝鮮重啓經濟特區,能成嗎?",
        "source": null,
        "cp": "熱觀察",
        "time": 1448204008000,
        "cid": "T1370583240249",
        "snapDetail": "幾回特區試驗都失敗,此次能帶領朝鮮改革開放嗎?",
        "icon": "http://img5.cache.netease.com/3g/2015/11/22/2015112223061925e35.jpg",
        "url": "http://3g.163.com/ntes/15/1122/22/B92FBBB80004662N.html",
        "extra": null
      },
      {
        "id": 1271,
        "title": "招罵的放生:放生老鼠和毒蛇",
        "source": null,
        "cp": "槽值",
        "time": 1448271902000,
        "cid": "T1370583240249",
        "snapDetail": "放生自古即有血色利益鏈,也可能破壞生態環境。",
        "icon": "http://img2.cache.netease.com/3g/2015/11/23/201511231757570334c.png",
        "url": "http://3g.163.com/news/15/1123/17/B94G3ATC0001544E.html",
        "extra": null
      }
    ],
    "nextOffset": 11,
    "type": 0
  }
}



     


控制器:

   頻道:ChannelsController app

          1.channelList()
            負責獲取頻道列表。 框架

   新聞:NewsController

           1.newsList
                負責獲取新聞列表。
eclipse




其餘:

   1.代碼位置

    https://github.com/pgq10240817/PlayNews

    anndroid:https://github.com/pgq10240817/PlayNews/tree/master/client/AndroidNews

                     eclipse工程。

                    HOST切換在HttpURLTag : HOST類裏面。

                    抽取了一些基類,封裝了下vollery。

                    道友如果想替換package,能夠運行下面這個pathon文件替換package

https://github.com/pgq10240817/PlayNews/tree/master/client/AndroidNews/scripts/package.py

    server:

        https://github.com/pgq10240817/PlayNews/tree/master/server/myNews

        抽取了model查詢類,主要是想緩存第一頁的數據(不知道這個意義大不大?????)


    DB:

        道友能夠在初始化項目(建表以後),運行下面sql插入模擬數據。

        https://github.com/pgq10240817/PlayNews/tree/master/conf/db

          頻道數據:  channels.sql

          新聞:news3.sql




後續:

  這個系列寫到這裏,基本上已經完結了,原本是計劃10月份後寫剩下的文章的,可是android框架那塊搭建起來比較耗時。

 後續的話其餘系列應該會採用這個android框架來實驗。


   注意點:

    1.model層次屬性的修改最好經過setXX方式修改,不要直接Model.XX = YY方式去修改。

    2.http post請求須要在content-type設置爲application/json。

   已知BUG:

           暫無。等道友來填哈。

相關文章
相關標籤/搜索