1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
| <?php $output = array(); $a = @$_GET["a"] ? $_GET["a"] : ""; $uid = @$_GET["uid"] ? $_GET["uid"] : 0;\r\n 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"=>"88888888@qq.com", "qq"=>88888888, "ctime"=>1320321234, "lastLogin"=>1321121144, "level"=>19 ),10002 => array( "uid"=>10002, "vip"=>3, "nickname" => "elva", "email"=>"99999999@qq.com", "qq"=>NULL, "ctime"=>1372323234, "lastLogin"=>1371122114, "level"=>12, ) ); //检测查询的数据是否注册存在 $uidArr = array(10001,10002); if (in_array($uid, $nickname, 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), "info" => "Here is the message which, commonly used in popup window", //返回消息提示 "code" => 200, //成功与失败的代码,一般都是正数或者负数 ); exit(json_encode($output)); //其他端口查询还可以自己再继续添加,方法同上 } elseif ($a == "get_result") { //... die("您正在调 get_result 接口!"); } elseif ($a == "get_upload") { //.... die("您正在调 get_upload 接口!"); }
|