From 5c1a0132c83beafff3cd132ba32703601ec440d6 Mon Sep 17 00:00:00 2001 From: Anyon Date: Tue, 3 Nov 2020 16:13:36 +0800 Subject: [PATCH] Update Center.php --- app/data/controller/api/auth/Center.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/app/data/controller/api/auth/Center.php b/app/data/controller/api/auth/Center.php index ae890665f..1d580f387 100644 --- a/app/data/controller/api/auth/Center.php +++ b/app/data/controller/api/auth/Center.php @@ -4,6 +4,8 @@ namespace app\data\controller\api\auth; use app\data\controller\api\Auth; use app\data\service\UserService; +use think\admin\Storage; +use think\exception\HttpResponseException; /** * 会员资料管理 @@ -58,6 +60,27 @@ class Center extends Auth $this->success('获取会员数据统计!', UserService::instance()->total($this->mid)); } + /** + * 上传Base64图片 + */ + public function image() + { + try { + $data = $this->_vali(['base64.require' => '图片内容不为空!']); + if (preg_match('|^data:image/(.*?);base64,|i', $data['base64'])) { + [$ext, $img] = explode('|||', preg_replace('|^data:image/(.*?);base64,|i', '$1|||', $data['base64'])); + $info = Storage::instance()->set(Storage::name($img, $ext ?: 'png', 'image/'), base64_decode($img)); + $this->success('图片上传成功!', ['url' => $info['url']]); + } else { + $this->error('解析内容失败!'); + } + } catch (HttpResponseException $exception) { + throw $exception; + } catch (\Exception $exception) { + $this->error($exception->getMessage()); + } + } + /** * 绑定会员邀请人 * @throws \think\Exception