From d9ee7e940216b7b834a8e915ffde442efb9cb243 Mon Sep 17 00:00:00 2001 From: wong <106998207@qq.com> Date: Mon, 29 Dec 2025 15:25:04 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=86=E9=94=80=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/distribution/ChannelController.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Server/application/cunkebao/controller/distribution/ChannelController.php b/Server/application/cunkebao/controller/distribution/ChannelController.php index f9691343..d6b4dd22 100644 --- a/Server/application/cunkebao/controller/distribution/ChannelController.php +++ b/Server/application/cunkebao/controller/distribution/ChannelController.php @@ -879,6 +879,7 @@ class ChannelController extends BaseController $type = $this->request->param('type', 'h5'); // h5 或 miniprogram $companyId = $this->getUserInfo('companyId'); + $userId = $this->getUserInfo('id'); // 参数验证 if (!in_array($type, ['h5', 'miniprogram'])) { @@ -890,10 +891,11 @@ class ChannelController extends BaseController ]); } - // 生成临时token(只包含公司ID,有效期24小时) + // 生成临时token(包含公司ID和用户ID,有效期24小时) // 用户扫码后需要自己填写所有信息 $tokenData = [ 'companyId' => $companyId, + 'userId' => $userId, 'expireTime' => time() + 86400 // 24小时后过期 ]; $token = base64_encode(json_encode($tokenData)); @@ -1253,6 +1255,7 @@ class ChannelController extends BaseController } $companyId = $tokenData['companyId']; + $userId = isset($tokenData['userId']) ? $tokenData['userId'] : 0; // 兼容旧token,如果没有userId则默认为0 // GET请求:返回token验证成功信息(前端可以显示表单) if ($this->request->isGet()) { @@ -1345,10 +1348,10 @@ class ChannelController extends BaseController // 生成渠道编码 $code = DistributionChannel::generateChannelCode(); - // 准备插入数据(扫码注册时 userId 为 0,因为是通过二维码注册,没有登录用户) + // 准备插入数据(从token中获取userId,记录是哪个用户生成的二维码) $data = [ 'companyId' => $companyId, - 'userId' => 0, // 扫码注册时没有登录用户,userId 为 0 + 'userId' => $userId, // 从token中获取userId,记录生成二维码的用户 'name' => $name, 'code' => $code, 'phone' => $phone ?: '',