From 788769fcfc828fa9723d98cfde1fc36d85d3bb96 Mon Sep 17 00:00:00 2001 From: panliang <1163816051@qq.com> Date: Wed, 11 May 2022 14:46:56 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E6=9C=8D=E5=8A=A1=E5=95=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Services/Payment/WxpayService.php | 21 ++++++++++++++++++++- config/wechat.php | 5 +++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/app/Services/Payment/WxpayService.php b/app/Services/Payment/WxpayService.php index 7b6de61f..ae91cfec 100644 --- a/app/Services/Payment/WxpayService.php +++ b/app/Services/Payment/WxpayService.php @@ -36,6 +36,14 @@ class WxpayService $app = $this->payment($payment); + // 服务商模式 (子商户) + $appId = config('wechat.payment.sub.app_id'); + $mchId = config('wechat.payment.sub.mch_id'); + + if ($appId && $mchId) { + $params['sub_openid'] = Arr::pull($params, 'openid'); + } + $result = $app->order->unify($params); $this->validateResult($result, $params); @@ -120,7 +128,18 @@ class WxpayService throw new WeChatPayException("支付 [{$name}] 配置未找到"); } - return Factory::payment($config); + $app = Factory::payment($config); + + // 服务商模式 (子商户) + $appId = config('wechat.payment.sub.app_id'); + $mchId = config('wechat.payment.sub.mch_id'); + + if ($appId && $mchId) { + $params['sub_openid'] = Arr::pull($params, 'openid'); + $app->setSubMerchant($mchId, $appId); + } + + return $app; } /** diff --git a/config/wechat.php b/config/wechat.php index 60af8281..71dad1bf 100644 --- a/config/wechat.php +++ b/config/wechat.php @@ -72,6 +72,11 @@ return [ ], ], ], + // 服务商模式, 子商户 + 'sub' => [ + 'app_id' => env('WECHAT_PAYMENT_SUB_APPID'), + 'mch_id' => env('WECHAT_PAYMENT_SUB_MCH_ID'), + ], // 商城 - 微信小程序支付 'mini_program' => [ 'sandbox' => env('WECHAT_PAYMENT_SANDBOX', false),