Creating the Api.php Class
NULL, ' info ' = ' Hang daddy! ', ' Code ' =>-201; Exit (Json_encode ($output));} Go to the interface if ($a = = ' get_users ') {//Check the user if ($uid = = 0) {$output = array (' Data ' =>null, ' info ' = ' The UID is null! ', ' Code ' =>-401); Exit (Json_encode ($output)); }//Assume that $mysql is a database $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 ' and ' 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 ' =&G t;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 ' = A Rray (' Red ' =>13, ' green ' =>3, ' Blue ' =>9, ' yellow ' =>7), ' ctime ' = 1376523234, ' lastlogin ' = > 1377123144, ' level ' = +, ' 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)); }//Query database $userInfo = $mysql [$uid]; Output Data $output = Array (' data ' = = Array (' userInfo ' = = $userInfo, ' islogin ' = ' = tr ue,//First Login ' unread ' + 4,//unread message number ' Untask ' + 3,//unfinished task, ' info ' = ' Here I s the message which, commonly used in popup window ',//message prompt, the client often uses this as a popup window information. ' Code ' = 200,//success and failure codes, usually positive or negative; Exit (Json_encode ($output));} ElseIf ($a = = ' Get_games_result ') {//... die (' You are tuning Get_games_result interface! ');} elseif ($a = = ' Upload_avatars ') {// .... Die (' You're tuning Upload_avatars interface! ');}Call Test http://localhost:63342/HelloPHP/API.php?a=get_users&uid=10001
return results
{
"Data": {
"UserInfo": {
"UID": 10001,
"VIP": 5,
"Nickname": "Shine X",
"Email": "979137@qq.com",
"QQ": 979137,
"Gold": 1500,
"Powerplay": {
"2XP": 12,
"Gem": 12,
"Bingo": 5,
"Keys": 5,
"Chest": 8
},
"Gems": {
"Red": 13,
"Green": 3,
"Blue": 8,
"Yellow": 17
},
"CTime": 1376523234,
"Lastlogin": 1377123144,
"Level": 19,
"Exp": 16758
},
"IsLogin": true,
"Unread": 4,
"Untask": 3
},
"Info": "Here's the message which, commonly used in popup window",
"Code": 200
}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.