fix(shopro): 修复小程序登录 500(EasyWeChat 日志写 /tmp 被 open_basedir 拦截)

现象:微信小程序登录不上。实测 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>
This commit is contained in:
liufumingren 2026-10-25 09:35:42 +08:00
parent dedb18a80c
commit f5bff78d88

View File

@ -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{
// 获取对应平台的配置