From d147648efc806e8437e30a18d00e0e3b942eac82 Mon Sep 17 00:00:00 2001 From: fengxinyhyl Date: Fri, 15 Mar 2024 14:22:10 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=B0=8F=E7=A8=8B=E5=BA=8F?= =?UTF-8?q?=E6=94=AF=E4=BB=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../store/order/StoreOrderRepository.php | 2 ++ crmeb/services/MiniProgramService.php | 21 +++++++++++++------ crmeb/services/PayService.php | 8 ++++++- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/app/common/repositories/store/order/StoreOrderRepository.php b/app/common/repositories/store/order/StoreOrderRepository.php index 5304c50..c54ff5e 100644 --- a/app/common/repositories/store/order/StoreOrderRepository.php +++ b/app/common/repositories/store/order/StoreOrderRepository.php @@ -112,7 +112,9 @@ class StoreOrderRepository extends BaseRepository event('order.pay.before', compact('groupOrder', 'type', 'isApp')); if (in_array($type, ['weixin', 'weixinApp', 'routine', 'h5', 'weixinQr'], true) && systemConfig('open_wx_combine')) { $service = new CombinePayService($type, $groupOrder->getCombinePayParams()); + Log::info("CombinePayService"); } else { + Log::info("PayService and {$type}"); $service = new PayService($type, $groupOrder->getPayParams($type === 'alipay' ? $return_url : '')); } $config = $service->pay($user); diff --git a/crmeb/services/MiniProgramService.php b/crmeb/services/MiniProgramService.php index 11c8528..dac5ee7 100644 --- a/crmeb/services/MiniProgramService.php +++ b/crmeb/services/MiniProgramService.php @@ -256,6 +256,7 @@ class MiniProgramService public function paymentPrepare($openid, $out_trade_no, $total_fee, $attach, $body, $detail = '', $trade_type = 'JSAPI', $options = []) { $order = $this->paymentOrder($openid, $out_trade_no, $total_fee, $attach, $body, $detail, $trade_type, $options); + Log::info("MiniProgramService paymentPrepare order" ); // 获取配置 判断是否为新支付 if (isset($this->config['pay_routine_new_mchid']) && $this->config['pay_routine_new_mchid']) { $result = $this->service->minipay->createorder($order); @@ -265,12 +266,17 @@ class MiniProgramService throw new ValidateException('微信支付错误返回:' . $result->return_msg); } } else { - if ($this->v3Pay()) { - if ($trade_type == 'MWEB') $trade_type = 'H5'; - $payFunction = 'pay'.ucfirst($trade_type); - return $this->service->v3Pay->{$payFunction}($order); - } else { + Log::info("MiniProgramService paymentPrepare order2".json_encode($this->v3Pay()) ); + +// if ($this->v3Pay()) { +// Log::info("MiniProgramService paymentPrepare order4" ); +// if ($trade_type == 'MWEB') $trade_type = 'H5'; +// $payFunction = 'pay'.ucfirst($trade_type); +// return $this->service->v3Pay->{$payFunction}($order); +// } else { + Log::info("MiniProgramService paymentPrepare order3" ); $result = $this->paymentService()->prepare($order); + Log::info("MiniProgramService paymentPrepare ".json_encode($result) ); if ($result->return_code == 'SUCCESS' && $result->result_code == 'SUCCESS') { return $result->prepay_id; } else { @@ -282,7 +288,7 @@ class MiniProgramService throw new ValidateException('没有获取微信支付的预支付ID,请重新发起支付!'); } } - } +// } } } @@ -300,7 +306,10 @@ class MiniProgramService */ public function jsPay($openid, $out_trade_no, $total_fee, $attach, $body, $detail = '', $trade_type = 'JSAPI', $options = []) { + Log::info('小程序支付参数版本V3'); $paymentPrepare = $this->paymentPrepare($openid, $out_trade_no, $total_fee, $attach, $body, $detail, $trade_type, $options); + Log::info('小程序支付参数' . json_encode($paymentPrepare)); + if ($this->isV3()) { return $paymentPrepare; } diff --git a/crmeb/services/PayService.php b/crmeb/services/PayService.php index 3bbadc1..83ac07e 100644 --- a/crmeb/services/PayService.php +++ b/crmeb/services/PayService.php @@ -17,6 +17,7 @@ use app\common\model\user\User; use app\common\repositories\wechat\WechatUserRepository; use think\exception\ValidateException; use think\facade\Cache; +use think\facade\Log; class PayService { @@ -60,9 +61,14 @@ class PayService { $wechatUserRepository = app()->make(WechatUserRepository::class); $openId = $wechatUserRepository->idByRoutineId($user['wechat_user_id']); + Log::info("payRoutine openId: " . $openId); if (!$openId) throw new ValidateException('请关联微信小程序!'); - $config = MiniProgramService::create()->jsPay($openId, $this->options['order_sn'], $this->options['pay_price'], $this->options['attach'], $this->options['body']); + try { + $config = MiniProgramService::create()->jsPay($openId, $this->options['order_sn'], $this->options['pay_price'], $this->options['attach'], $this->options['body']); + } catch (\Exception $e) { + Log::info("payRoutine error: " . $e->getMessage()); + } return compact('config'); }