From 694668dbd05f4fb0a8216fa9b585f9eb0c8fe11a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E6=B3=BD=E5=B9=B3?= Date: Tue, 19 Jan 2016 10:17:36 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E3=80=90=E4=BF=AE=E5=A4=8D=E3=80=91api?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E6=A8=A1=E5=9D=97=E4=BF=AE=E5=A4=8D(?= =?UTF-8?q?=E5=8C=85=E5=90=AB=E7=94=A8=E6=88=B7=E6=B3=A8=E5=86=8C=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E5=8A=9F=E8=83=BD)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Application/Api/Common/index.html | 1 + Application/Api/Conf/config.php | 4 + Application/Api/Conf/index.html | 1 + .../Api/Controller/UserController.class.php | 103 ++++++++++++++++++ Application/Api/Controller/index.html | 1 + Application/Api/Model/index.html | 1 + Application/Api/View/index.html | 1 + Application/Api/index.html | 1 + Application/Common/Model/UserModel.class.php | 14 ++- api.php | 30 +---- 10 files changed, 125 insertions(+), 32 deletions(-) create mode 100644 Application/Api/Common/index.html create mode 100644 Application/Api/Conf/config.php create mode 100644 Application/Api/Conf/index.html create mode 100644 Application/Api/Controller/UserController.class.php create mode 100644 Application/Api/Controller/index.html create mode 100644 Application/Api/Model/index.html create mode 100644 Application/Api/View/index.html create mode 100644 Application/Api/index.html diff --git a/Application/Api/Common/index.html b/Application/Api/Common/index.html new file mode 100644 index 0000000..0519ecb --- /dev/null +++ b/Application/Api/Common/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Application/Api/Conf/config.php b/Application/Api/Conf/config.php new file mode 100644 index 0000000..cc42ec6 --- /dev/null +++ b/Application/Api/Conf/config.php @@ -0,0 +1,4 @@ +'配置值' +); \ No newline at end of file diff --git a/Application/Api/Conf/index.html b/Application/Api/Conf/index.html new file mode 100644 index 0000000..0519ecb --- /dev/null +++ b/Application/Api/Conf/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Application/Api/Controller/UserController.class.php b/Application/Api/Controller/UserController.class.php new file mode 100644 index 0000000..76fd052 --- /dev/null +++ b/Application/Api/Controller/UserController.class.php @@ -0,0 +1,103 @@ +ajaxReturn ( array ( + 'state' => 601, + 'msg' => '参数不全', + 'data' => NULL + ) ); + exit (); + } + $type = 1; + if (preg_match ( '/^\d+$/', $username )) { + // 全数字 + if (preg_match ( '/^(0|86|17951)?(13[0-9]|15[012356789]|17[0678]|18[0-9]|14[57])[0-9]{8}$/', $username )) { + // 手机号 + $type = 3; + } else { + // uid + $type = 4; + } + } else { + if (preg_match ( '/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/', $username )) { + // 邮箱 + $type = 2; + } else { + // 用户名 + $type = 1; + } + } + if ($ext == 'wxopid') { + $type = 5; + }else if ($ext == 'wxunid') { + $type = 6; + } + $api = new UserApi (); + $result = $api->login ( $username, $password, $type ); + if ($isInSystem){ + return $result; + } + if ($result > 0) { + $this->ajaxReturn ( array ( + 'state' => 200, + 'msg' => '登录成功', + 'data' => array ( + 'uid' => $result + ) + ) ); + } else { + if ($result == - 1) { + $this->ajaxReturn ( array ( + 'state' => 404, + 'msg' => '用户不存在', + 'data' => NULL + ) ); + } + if ($result == - 2) { + $this->ajaxReturn ( array ( + 'state' => 401, + 'msg' => '密码错误', + 'data' => NULL + ) ); + } + } + } + + public function regist($user,$nick,$pwd,$mail,$phone){ + $username = I ( 'username', '', 'text' ) != '' ? I ( 'username', '', 'text' ) : $user; + $nickname = I ( 'nickname', '', 'text' ) != '' ? I ( 'nickname', '', 'text' ) : $nick; + $password = I ( 'password', '', 'text' ) != '' ? I ( 'password', '', 'text' ) : $pwd; + $email = I ( 'email', '', 'text' ) != '' ? I ( 'email', '', 'text' ) : $mail; + $mobile = I ( 'mobile', '', 'text' ) != '' ? I ( 'mobile', '', 'text' ) : $phone; + $nickname = ''; + $api = new UserApi (); + $result = $api->register($username, $nickname, $password, $email, $mobile); + if ($isInSystem){ + return $result; + } + if ($result > 0){ + $this->ajaxReturn ( array ( + 'state' => 200, + 'msg' => '注册成功', + 'data' => array ( + 'uid' => $result + ) + )); + }else{ + $this->ajaxReturn(array( + 'state' => 500, + 'msg' => '注册失败', + 'data' => NULL + )); + } + } +} \ No newline at end of file diff --git a/Application/Api/Controller/index.html b/Application/Api/Controller/index.html new file mode 100644 index 0000000..0519ecb --- /dev/null +++ b/Application/Api/Controller/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Application/Api/Model/index.html b/Application/Api/Model/index.html new file mode 100644 index 0000000..0519ecb --- /dev/null +++ b/Application/Api/Model/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Application/Api/View/index.html b/Application/Api/View/index.html new file mode 100644 index 0000000..0519ecb --- /dev/null +++ b/Application/Api/View/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Application/Api/index.html b/Application/Api/index.html new file mode 100644 index 0000000..0519ecb --- /dev/null +++ b/Application/Api/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Application/Common/Model/UserModel.class.php b/Application/Common/Model/UserModel.class.php index 8b7f7dd..94e00cf 100644 --- a/Application/Common/Model/UserModel.class.php +++ b/Application/Common/Model/UserModel.class.php @@ -44,7 +44,11 @@ class UserModel private function popGotFields($fiels, $gotFields) { - return array_diff($fiels, $gotFields); + if(count($gotFields)!=0){ + return array_diff($fiels, $gotFields); + } + return $fiels; + } private function combineUserData($user_data, $values) @@ -62,7 +66,8 @@ class UserModel $need_query = array_intersect($this->table_fields, $fields); //如果有需要检索的数据 if (!empty($need_query)) { - $query_results = D('')->query('select ' . implode(',', $need_query) . ' from ocenter_member,ocenter_ucenter_member where ocenter_member.uid=ocenter_ucenter_member.id and uid=' . $uid . ' limit 1'); + $db_prefix=C('DB_PREFIX'); + $query_results = D('')->query('select ' . implode(',', $need_query) . " from `{$db_prefix}member`,`{$db_prefix}ucenter_member` where uid=id and uid={$uid} limit 1"); $query_result = $query_results[0]; $user_data = $this->combineUserData($user_data, $query_result); $fields = $this->popGotFields($fields, $need_query); @@ -247,7 +252,10 @@ class UserModel } } //去除已经缓存的字段 - $fields = array_diff($fields, $cachedFields); + if(count($cachedFields)!=0){ + $fields = array_diff($fields, $cachedFields); + } + return array($cacheResult, $fields); } diff --git a/api.php b/api.php index c994238..6310646 100644 --- a/api.php +++ b/api.php @@ -1,35 +1,7 @@ - */ -define ('OS_THEME_PATH', './Theme/'); define ( 'RUNTIME_PATH', './Runtime/' ); require './ThinkPHP/ThinkPHP.php'; \ No newline at end of file -- Gitee From 394aff035a818bd3463ea5c587f440f3508f4551 Mon Sep 17 00:00:00 2001 From: Bai Date: Mon, 18 Apr 2016 19:36:44 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8DUser=20Api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Api/Controller/UserController.class.php | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Application/Api/Controller/UserController.class.php b/Application/Api/Controller/UserController.class.php index 63e72c3..ff72387 100644 --- a/Application/Api/Controller/UserController.class.php +++ b/Application/Api/Controller/UserController.class.php @@ -5,10 +5,10 @@ namespace Api\Controller; use Think\Controller; use User\Api\UserApi; class UserController extends Controller { - public function login($user,$pwd) { - $username = I ( 'username', '', 'text' ) != '' ? I ( 'username', '', 'text' ) : $user; - $password = I ( 'password', '', 'text' ) != '' ? I ( 'password', '', 'text' ) : $pwd; - if ($username == '' || $password == '') { + public function login() { + $username = I ( 'username', '', 'text' ); + $password = I ( 'password', '', 'text' ); + if ($username == '' && $password == '') { $this->ajaxReturn ( array ( 'state' => 601, 'msg' => '参数不全', @@ -63,12 +63,12 @@ class UserController extends Controller { } } - public function regist($user,$nick,$pwd,$mail,$phone){ - $username = I ( 'username', '', 'text' ) != '' ? I ( 'username', '', 'text' ) : $user; - $nickname = I ( 'nickname', '', 'text' ) != '' ? I ( 'nickname', '', 'text' ) : $nick; - $password = I ( 'password', '', 'text' ) != '' ? I ( 'password', '', 'text' ) : $pwd; - $email = I ( 'email', '', 'text' ) != '' ? I ( 'email', '', 'text' ) : $mail; - $mobile = I ( 'mobile', '', 'text' ) != '' ? I ( 'mobile', '', 'text' ) : $phone; + public function register(){ + $username = I ( 'username', '', 'text' ); + $nickname = I ( 'nickname', '', 'text' ); + $password = I ( 'password', '', 'text' ); + $email = I ( 'email', '', 'text' ); + $mobile = I ( 'mobile', '', 'text' ); $nickname = ''; $api = new UserApi (); $result = $api->register($username, $nickname, $password, $email, $mobile); -- Gitee