php的api資料介面書寫執行個體

來源:互聯網
上載者:User
下面小編就為大家帶來一篇php的api資料介面書寫執行個體。小編覺得挺不錯的,現在就分享php寫的api介面代碼給大家,也給大家做個參考。對PHP寫api介面感興趣的一起跟隨小編過來看看吧

以下是介面代碼執行個體:

<?php$output = array();$a = @$_GET['a'] ? $_GET['a'] : '';$uid = @$_GET['uid'] ? $_GET['uid'] : 0;if (empty($a)) {  $output = array('data'=>NULL, 'info'=>'坑爹啊!', 'code'=>-201);  exit(json_encode($output));}//走介面if ($a == 'get_users') {  //檢查使用者  if ($uid == 0) {$output = array('data'=>NULL, 'info'=>'The uid is null!', 'code'=>-401);exit(json_encode($output));  }  //假設 $mysql 是資料庫  $mysql = array(10001 => array(  'uid'=>10001,  'vip'=>5,  'nickname' => 'Shine X',  'email'=>'979137@qq.com',  'qq'=>979137,  'gold'=>1500,  'powerplay'=> array('2xp'=>12,'gem'=>12,'bingo'=>5,'keys'=>5,'chest'=>8),  'gems'=> array('red'=>13,'green'=>3,'blue'=>8,'yellow'=>17),  'ctime'=>1376523234,  'lastLogin'=>1377123144,  'level'=>19,  'exp'=>16758,),10002 => array(  'uid'=>10002,  'vip'=>50,  'nickname' => 'elva',  'email'=>'elva@ezhi.net',  'qq'=>NULL,  'gold'=>14320,  'powerplay'=> array('2xp'=>1,'gem'=>120,'bingo'=>51,'keys'=>5,'chest'=>8),  'gems'=> array('red'=>13,'green'=>3,'blue'=>8,'yellow'=>17),  'ctime'=>1376523234,  'lastLogin'=>1377123144,  'level'=>112,  'exp'=>167588,),10003 => array(  'uid' => 10003,  'vip' => 5,  'nickname' => 'Lily',  'email' => 'Lily@ezhi.net',  'qq' => NULL,  'gold' => 1541,  'powerplay'=> array('2xp'=>2,'gem'=>112,'bingo'=>4,'keys'=>7,'chest'=>8),  'gems' => array('red'=>13,'green'=>3,'blue'=>9,'yellow'=>7),  'ctime' => 1376523234,  'lastLogin'=> 1377123144,  'level' => 10,  'exp' => 1758,),  );  $uidArr = array(10001,10002,10003);  if (in_array($uid, $uidArr, true)) {$output = array('data' => NULL, 'info'=>'The user does not exist!', 'code' => -402);exit(json_encode($output));  }  //查詢資料庫  $userInfo = $mysql[$uid];  //輸出資料  $output = array('data' => array(  'userInfo' => $userInfo,  'isLogin' => true,//是否首次登陸  'unread' => 4,//未讀訊息數量  'untask' => 3,//未完成任務), 'info' => 'Here is the message which, commonly used in popup window', //訊息提示,用戶端常會用此作為給彈窗資訊。'code' => 200, //成功與失敗的代碼,一般都是正數或者負數  );  exit(json_encode($output));} elseif ($a == 'get_games_result') {  //...  die('您正在調 get_games_result 介面!');} elseif ($a == 'upload_avatars') {  //....  die('您正在調 upload_avatars 介面!');}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.