From f198ad01d5d3ab4dfce4ce29c6f0abe3305d33b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E6=99=AF=E7=AB=8B?= Date: Tue, 13 Apr 2021 14:23:23 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=96=B0=E7=89=88=E5=B0=8F?= =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/data/controller/api/Wxapp.php | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/app/data/controller/api/Wxapp.php b/app/data/controller/api/Wxapp.php index 1996b22d8..91e53b9cf 100644 --- a/app/data/controller/api/Wxapp.php +++ b/app/data/controller/api/Wxapp.php @@ -77,26 +77,19 @@ class Wxapp extends Controller { try { $input = $this->_vali([ - 'code.default' => '', // code 与 session_key 二选一 - 'session_key.default' => '', // code 与 session_key 二选一 - 'iv.require' => '解密向量不能为空!', - 'encrypted.require' => '加密内容不能为空!', + 'iv.require' => '解密向量不能为空!', + 'code.require' => '授权CODE不能为空!', + 'encrypted.require' => '加密内容不能为空!', ]); - if (empty($input['session_key'])) { - if (empty($input['code'])) $this->error('登录凭证code不能为空!'); - [, , $input['session_key']] = $this->_getSessionKey($input['code']); - } + [$openid, $unionid, $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'])) { + if (is_array($result) && isset($result['avatarUrl']) && isset($result['nickName'])) { $sex = ['未知', '男', '女'][$result['gender']] ?? '未知'; - $map = empty($result['unionId']) ? [$this->field => $result['openId']] : ['unionid' => $result['unionId']]; - $data = [$this->field => $result['openId'], 'headimg' => $result['avatarUrl'], 'nickname' => $result['nickName'], 'base_sex' => $sex]; + $map = empty($result['unionId']) ? [$this->field => $openid] : ['unionid' => $unionid]; + $data = [$this->field => $openid, 'headimg' => $result['avatarUrl'], 'nickname' => $result['nickName'], 'base_sex' => $sex]; $this->success('数据解密成功!', UserAdminService::instance()->set($map, array_merge($map, $data), $this->type, true)); - } elseif (is_array($result) && isset($result['phoneNumber'])) { - $this->success('数据解密成功!', $result); } elseif (is_array($result)) { - $this->success('解码成功', $result); + $this->success('数据解密成功!', $result); } else { $this->error('数据处理失败,请稍候再试!'); }