From f5bff78d88d1d8a895d4f6e824d93ba60d92c5a3 Mon Sep 17 00:00:00 2001 From: liufumingren Date: Sun, 25 Oct 2026 09:35:42 +0800 Subject: [PATCH] =?UTF-8?q?fix(shopro):=20=E4=BF=AE=E5=A4=8D=E5=B0=8F?= =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E7=99=BB=E5=BD=95=20500=EF=BC=88EasyWeChat?= =?UTF-8?q?=20=E6=97=A5=E5=BF=97=E5=86=99=20/tmp=20=E8=A2=AB=20open=5Fbase?= =?UTF-8?q?dir=20=E6=8B=A6=E6=88=AA=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 现象:微信小程序登录不上。实测 POST /api/user/getWxMiniProgramSessionKey (appid=wx31f8d1ee127bc64b)返回 500: [2] ErrorException in monolog StreamHandler.php:210 is_dir(): open_basedir restriction in effect. File(/tmp) is not within the allowed path(s): (/www/wwwroot/ye4s.wms.gztbyc.com/:/www/server/php/74/var/ye4s-tmp/) 原因:addons/shopro/library/Wechat::setConfig 把 easywechat 日志路径写死成 /tmp/easywechat.log,新环境 open_basedir 不再放行 /tmp,Monolog 建目录时 触发 warning,TP5 转成 ErrorException,整个 code 换 session_key 接口中断。 改动: - 日志路径改为站点 RUNTIME_PATH/easywechat/easywechat.log,并自动建目录 - 去掉 Model 上不存在的 \->error()(会抛 method not exist),改为 抛出带 appid 的明确异常 验证:接口已能进入 EasyWeChat 初始化,不再因 open_basedir 中断。 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- addons/shopro/library/Wechat.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/addons/shopro/library/Wechat.php b/addons/shopro/library/Wechat.php index ab7378f..3581fd7 100644 --- a/addons/shopro/library/Wechat.php +++ b/addons/shopro/library/Wechat.php @@ -299,6 +299,12 @@ class Wechat extends Model private function setConfig($platform,$appid) { $debug = config('app_debug'); + // open_basedir 下不能写 /tmp,日志改到站点 runtime 目录 + $logPath = defined('RUNTIME_PATH') ? RUNTIME_PATH . 'easywechat' . DIRECTORY_SEPARATOR : ROOT_PATH . 'runtime' . DIRECTORY_SEPARATOR . 'easywechat' . DIRECTORY_SEPARATOR; + if (!is_dir($logPath)) { + @mkdir($logPath, 0755, true); + } + $defaultConfig = [ 'log' => [ 'default' => $debug ? 'dev' : 'prod', // 默认使用的 channel,生产环境可以改为下面的 prod @@ -306,13 +312,13 @@ class Wechat extends Model // 测试环境 'dev' => [ 'driver' => 'single', - 'path' => '/tmp/easywechat.log', + 'path' => $logPath . 'easywechat.log', 'level' => 'debug', ], // 生产环境 'prod' => [ 'driver' => 'daily', - 'path' => '/tmp/easywechat.log', + 'path' => $logPath . 'easywechat.log', 'level' => 'info', ], ], @@ -328,7 +334,7 @@ class Wechat extends Model "warehouse_id" => $APP['warehouse_id'] ]; }else{ - $this->error('找不到应用'); + throw new \Exception('找不到应用:' . $appid); } }else{ // 获取对应平台的配置