diff --git a/app/data/controller/api/Auth.php b/app/data/controller/api/Auth.php index 292ac001f..2e123bc28 100644 --- a/app/data/controller/api/Auth.php +++ b/app/data/controller/api/Auth.php @@ -20,7 +20,7 @@ abstract class Auth extends Controller protected $mid; /** - * 接口授权TOKEN + * 接口授权令牌 * @var string */ protected $token; @@ -45,7 +45,7 @@ abstract class Auth extends Controller * 获取会员数据 * @return array */ - protected function getMember(): array + protected function getMember() { try { if (empty($this->token)) $this->error('接口授权TOKEN无效'); diff --git a/app/data/controller/api/Login.php b/app/data/controller/api/Login.php index 4f7ffcc49..39f8829f5 100644 --- a/app/data/controller/api/Login.php +++ b/app/data/controller/api/Login.php @@ -37,7 +37,7 @@ class Login extends Controller if (empty($user)) $this->error('该手机号还没有注册哦!'); if (empty($user['status'])) $this->error('该会员账号状态异常!'); if (md5($data['password']) === $user['password']) { - $this->success('手机登录成功!', UserService::instance()->get($map, true)); + $this->success('手机登录成功!', UserService::instance()->get($user['id'], true)); } else { $this->error('账号登录失败,请稍候再试!'); } diff --git a/app/data/controller/api/auth/Center.php b/app/data/controller/api/auth/Center.php index ca6d9ee11..ae890665f 100644 --- a/app/data/controller/api/auth/Center.php +++ b/app/data/controller/api/auth/Center.php @@ -60,6 +60,7 @@ class Center extends Auth /** * 绑定会员邀请人 + * @throws \think\Exception * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException @@ -71,7 +72,7 @@ class Center extends Auth $this->error('邀请人不能是自己哦', UserService::instance()->total($this->mid)); } $from = $this->app->db->name($this->table)->where(['id' => $data['from']])->find(); - if (empty($from)) $this->error('邀请人状态异常', UserService::instance()->total($this->mid)); + if (empty($from)) $this->error('邀请人状态异常', UserService::instance()->get($this->mid)); if ($this->member['from'] > 0) $this->error('您已经绑定了邀请人', UserService::instance()->total($this->mid)); if ($this->app->db->name($this->table)->where(['id' => $this->mid])->update($data) !== false) { $this->success('绑定邀请人成功!', UserService::instance()->total($this->mid)); diff --git a/app/data/service/UserService.php b/app/data/service/UserService.php index dccccf284..b21103914 100644 --- a/app/data/service/UserService.php +++ b/app/data/service/UserService.php @@ -19,22 +19,27 @@ class UserService extends Service /** * 获取会员资料 - * @param array $map 查询条件 - * @param bool $force 强制令牌 + * @param mixed $map 查询条件 + * @param boolean $force 强制令牌 * @return array * @throws \think\Exception * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ - public function get(array $map, bool $force = false): array + public function get($map, bool $force = false): array { - $member = $this->save($map, [], $force); - if (empty($member)) throw new \think\Exception('登录授权失败'); + if (is_numeric($map)) { + $map = ['id' => $map]; + } elseif (is_string($map)) { + $map = ['token|openid' => $map]; + } + $user = $this->save($map, [], $force); + if (empty($user)) throw new \think\Exception('登录授权失败'); // if ($member['tokenv'] !== $this->buildTokenVerify()) { // throw new \think\Exception('请重新登录授权'); // } - return $member; + return $user; } /**