From cfee872aec7b66fc8a1940a141ffe0b9947b8f65 Mon Sep 17 00:00:00 2001 From: Anyon Date: Mon, 14 Sep 2020 12:28:50 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=85=AC=E4=BC=97=E5=8F=B7?= =?UTF-8?q?=E6=8E=88=E6=9D=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/data/controller/api/Wxapp.php | 12 ++++++------ app/data/service/UserService.php | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/data/controller/api/Wxapp.php b/app/data/controller/api/Wxapp.php index 13e484162..0b88fc344 100644 --- a/app/data/controller/api/Wxapp.php +++ b/app/data/controller/api/Wxapp.php @@ -50,9 +50,9 @@ class Wxapp extends Controller public function session() { $input = $this->_vali(['code.require' => '登录凭证code不能为空!']); - [$openid, $unionid, $sessionKey] = $this->_exchangeSessionKey($input['code']); - [$map, $data] = [['openid1' => $openid], ['openid1' => $openid, 'session_key' => $sessionKey]]; - if (!empty($unionid)) [$map, $data] = [['unionid' => $unionid], array_merge(['unionid' => $unionid], $data)]; + [$openid, $unionid, $sessionKey] = $this->_getSessionKey($input['code']); + $map = empty($unionid) ? ['openid1' => $openid] : ['unionid' => $unionid]; + $data = array_merge($map, ['openid1' => $openid, 'session_key' => $sessionKey]); $this->success('授权换取成功!', UserService::instance()->save($map, $data, true)); } @@ -71,7 +71,7 @@ class Wxapp extends Controller ]); if (empty($input['session_key'])) { if (empty($input['code'])) $this->error('登录凭证code不能为空!'); - [, , $input['session_key']] = $this->_exchangeSessionKey($input['code']); + [, , $input['session_key']] = $this->_getSessionKey($input['code']); } $result = Crypt::instance($this->config)->decode($input['iv'], $input['session_key'], $input['encrypted']); if (is_array($result) && isset($result['openId']) && isset($result['avatarUrl']) && isset($result['nickName'])) { @@ -96,7 +96,7 @@ class Wxapp extends Controller * @param string $code 换取授权CODE * @return array [openid, sessionkey] */ - private function _exchangeSessionKey($code) + private function _getSessionKey($code) { try { $cache = $this->app->cache->get($code, []); @@ -131,7 +131,7 @@ class Wxapp extends Controller 'path.require' => '跳转路径不能为空!', ]); $result = Qrcode::instance($this->config)->createMiniPath($data['path'], $data['size']); - if (isset($data['type']) && $data['type'] === 'base64') { + if ($data['type'] === 'base64') { $this->success('生成小程序码成功!', [ 'base64' => 'data:image/png;base64,' . base64_encode($result), ]); diff --git a/app/data/service/UserService.php b/app/data/service/UserService.php index 826abcc2a..37db9fa89 100644 --- a/app/data/service/UserService.php +++ b/app/data/service/UserService.php @@ -56,7 +56,7 @@ class UserService extends Service { $user = $this->app->db->name($this->table)->where($map)->where(['deleted' => 0])->find() ?: []; unset($data['id'], $data['token'], $data['tokenv'], $data['status'], $data['deleted'], $data['create_at']); - if (empty($data) || (empty($data['phone']) && empty($data['openid']) && empty($data['unionid']))) { + if (empty($data) || (empty($data['phone'] . $data['openid1'] . $data['openid2'] . $data['unionid']))) { unset($user['deleted'], $user['password']); return $user; } elseif (empty($user['id'])) {