多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
## 一、获取单个用户的信息 ### 1.接口地址 +++ post:http://www.dakaifa.net/index.php?g=App&m=Users&a=getUserInfo *int:uid=111#说明文字 <<< success { "id": "111", "user_nicename": "张天", "avatar": "http://dakaifa.net/data/upload/avatar/57b683b09d109.jpg" } <<< error +++ ### 2.接口代码 ``` public function getUserInfo(){ $uid=$_POST['uid']; $user_model=M('Users'); $where="id,user_nicename,avatar"; $rst=$user_model->field($where)->find($uid); $rst['avatar'] = "http://".$_SERVER['SERVER_NAME']."/".C("UPLOADPATH")."avatar/" .$rst['avatar']; echo json_encode($rst); } ``` ## 二、获取多个用户的信息 ### 1.接口地址 +++ post:http://www.dakaifa.net/index.php?g=App&m=Users&a=getUserInfos *int:uids=111,112,113#说明文字 <<< success [ { "id": "111", "user_nicename": "张天", "avatar": "http://dakaifa.net/data/upload/avatar/57b683b09d109.jpg" }, { "id": "112", "user_nicename": "张君", "avatar": "http://dakaifa.net/data/upload/avatar/57987d7896cd4.jpg" }, { "id": "113", "user_nicename": "微风", "avatar": "http://dakaifa.net/data/upload/avatar/57b6ad22cb5da.png" } ] <<< error +++ ### 2.接口代码 ``` public function getUserInfos() { $uids=$_POST['uids']; $arr = explode(",", $uids); $user_model=M('Users'); $where="id,user_nicename,avatar"; foreach ( $arr as $key=> $value) { $rst[$key]=$user_model->field($where)->find($value); $rst[$key]['avatar'] = "http://".$_SERVER['SERVER_NAME']."/".C("UPLOADPATH")."avatar/" .$rst[$key]['avatar']; } echo json_encode($rst); } ```