diff --git a/backend/application/api/controller/Order.php b/backend/application/api/controller/Order.php index 17ca338..32ac6d5 100644 --- a/backend/application/api/controller/Order.php +++ b/backend/application/api/controller/Order.php @@ -371,7 +371,8 @@ class Order extends Api */ private function assertVirtualPaySignature() { - $token = (string)config('common.virtual_pay.msg_token'); + $virtualPay = config('common.virtual_pay'); + $token = is_array($virtualPay) ? (string)($virtualPay['msg_token'] ?? '') : ''; if ($token === '') { throw new \Exception('未配置虚拟支付消息令牌'); } diff --git a/backend/application/common/service/VirtualPayService.php b/backend/application/common/service/VirtualPayService.php index e080730..167f88c 100644 --- a/backend/application/common/service/VirtualPayService.php +++ b/backend/application/common/service/VirtualPayService.php @@ -43,7 +43,7 @@ class VirtualPayService */ public static function createClientPay($orderNo, $amountYuan, $openid) { - $offerId = (string)config('common.virtual_pay.offer_id'); + $offerId = (string)(self::payConfig()['offer_id'] ?? ''); if ($offerId === '') { self::logMissingOfferId(); throw new \Exception('未配置虚拟支付 OfferID'); @@ -159,9 +159,11 @@ class VirtualPayService */ public static function decryptMessage($encrypt, $msgSignature, $nonce, $timestamp) { - $token = (string)config('common.virtual_pay.msg_token'); - $aesKey = (string)config('common.virtual_pay.aes_key'); - $appId = (string)config('common.wechat.app_id'); + $payConfig = self::payConfig(); + $wechat = config('common.wechat'); + $token = (string)($payConfig['msg_token'] ?? ''); + $aesKey = (string)($payConfig['aes_key'] ?? ''); + $appId = is_array($wechat) ? (string)($wechat['app_id'] ?? '') : ''; if ($token === '' || $aesKey === '' || $appId === '') { throw new \Exception('未配置虚拟支付消息加解密参数'); } @@ -378,6 +380,17 @@ class VirtualPayService return (string)$sessionKey; } + /** + * ThinkPHP 5 的 config() 只按第一个点拆成两级,三级键会读成空 + * @return array + */ + private static function payConfig() + { + $config = config('common.virtual_pay'); + + return is_array($config) ? $config : []; + } + /** * OfferID 为空时记下 .env 有没有被读到,不记录密钥内容 */ @@ -431,7 +444,7 @@ class VirtualPayService if ($fen < 1) { throw new \Exception('支付金额不能小于0.01元'); } - $coinPerYuan = (int)config('common.virtual_pay.coin_per_yuan'); + $coinPerYuan = (int)(self::payConfig()['coin_per_yuan'] ?? 0); if ($coinPerYuan < 1) { $coinPerYuan = 1; } @@ -456,7 +469,7 @@ class VirtualPayService */ private static function env() { - return (int)config('common.virtual_pay.env') === 1 ? 1 : 0; + return (int)(self::payConfig()['env'] ?? 0) === 1 ? 1 : 0; } /** @@ -465,7 +478,7 @@ class VirtualPayService */ private static function appKey() { - $config = config('common.virtual_pay'); + $config = self::payConfig(); $key = self::env() === 1 ? (string)($config['sandbox_app_key'] ?? '') : (string)($config['app_key'] ?? ''); if ($key === '') { throw new \Exception('未配置虚拟支付 AppKey');