From ad73da1db40d8bed20f76585f0235b181357e0fd Mon Sep 17 00:00:00 2001 From: MiAn Date: Thu, 12 Nov 2026 18:20:32 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=BE=AE=E4=BF=A1?= =?UTF-8?q?=E6=94=AF=E4=BB=98=E8=AF=81=E4=B9=A6open=5Fbasedir=E8=B7=AF?= =?UTF-8?q?=E5=BE=84=E8=A7=A3=E6=9E=90=E9=94=99=E8=AF=AF=E5=8F=8APHP8.5?= =?UTF-8?q?=E5=85=BC=E5=AE=B9=E6=80=A7=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/application/common/controller/Api.php | 2 +- .../common/library/PaymentService.php | 4 ++-- .../common/library/WxPayException.php | 2 +- .../common/library/WxPayV3Service.php | 24 ++++++++++++++++--- 4 files changed, 25 insertions(+), 7 deletions(-) diff --git a/server/application/common/controller/Api.php b/server/application/common/controller/Api.php index f685ca2..38a226d 100755 --- a/server/application/common/controller/Api.php +++ b/server/application/common/controller/Api.php @@ -69,7 +69,7 @@ class Api * @access public * @param Request $request Request 对象 */ - public function __construct(Request $request = null) + public function __construct(?Request $request = null) { $this->request = is_null($request) ? Request::instance() : $request; diff --git a/server/application/common/library/PaymentService.php b/server/application/common/library/PaymentService.php index 3784690..45495c6 100644 --- a/server/application/common/library/PaymentService.php +++ b/server/application/common/library/PaymentService.php @@ -324,7 +324,7 @@ class PaymentService * @param array|null $wxTxData 异步回调已解密的交易数据;传 null 时自动向微信网关主动查单 * @return array */ - public static function confirmOrderPay($outTradeNo, array $wxTxData = null) + public static function confirmOrderPay($outTradeNo, ?array $wxTxData = null) { $outTradeNo = trim((string)$outTradeNo); if ($outTradeNo === '') { @@ -1122,7 +1122,7 @@ class PaymentService * @param array|null $wxBillData 微信回调已解密报文;传 null 则主动调用微信查单接口 * @return array 最新提现单行记录 */ - public static function syncWithdrawTransfer($withdrawId, array $wxBillData = null) + public static function syncWithdrawTransfer($withdrawId, ?array $wxBillData = null) { $withdrawId = (int)$withdrawId; $wd = Db::name('withdraw')->where('id', $withdrawId)->find(); diff --git a/server/application/common/library/WxPayException.php b/server/application/common/library/WxPayException.php index a1d7568..f2e6c0c 100644 --- a/server/application/common/library/WxPayException.php +++ b/server/application/common/library/WxPayException.php @@ -32,7 +32,7 @@ class WxPayException extends \RuntimeException $curlErrno = 0, $isUncertain = false, $rawDetail = '', - \Throwable $previous = null + ?\Throwable $previous = null ) { parent::__construct((string)$message, (int)($httpCode ?: $curlErrno), $previous); $this->wxCode = (string)$wxCode; diff --git a/server/application/common/library/WxPayV3Service.php b/server/application/common/library/WxPayV3Service.php index a81d388..7952822 100644 --- a/server/application/common/library/WxPayV3Service.php +++ b/server/application/common/library/WxPayV3Service.php @@ -1054,10 +1054,28 @@ class WxPayV3Service if ($path === '') { return ''; } - if (is_file($path)) { + $root = defined('ROOT_PATH') ? rtrim(ROOT_PATH, '/\\') : dirname(__DIR__, 3); + // 1. 若已经是项目根目录下的绝对路径 + if (strpos($path, $root) === 0 && @is_file($path)) { return $path; } - $root = defined('ROOT_PATH') ? rtrim(ROOT_PATH, '/\\') : dirname(__DIR__, 3); - return $root . DIRECTORY_SEPARATOR . ltrim(str_replace(['/', '\\'], DIRECTORY_SEPARATOR, $path), DIRECTORY_SEPARATOR); + // 2. 拼接项目根目录后的候选绝对路径 + $candidate = $root . DIRECTORY_SEPARATOR . ltrim(str_replace(['/', '\\'], DIRECTORY_SEPARATOR, $path), DIRECTORY_SEPARATOR); + if (@is_file($candidate)) { + return $candidate; + } + // 3. Windows 盘符绝对路径 + if (preg_match('/^[a-zA-Z]:[\\\\\/]/', $path) && @is_file($path)) { + return $path; + } + // 4. 若以斜杠开头,避免触发 open_basedir 报错,优先返回 candidate + if (strpos($path, '/') === 0 || strpos($path, '\\') === 0) { + return $candidate; + } + // 5. 兜底检测 + if (@is_file($path)) { + return $path; + } + return $candidate; } }