From 88c2ef015c4edb229048d2fc81a8894a75a15da4 Mon Sep 17 00:00:00 2001 From: "iVampireSP.com" Date: Mon, 14 Nov 2022 17:47:52 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9B=20=E6=94=AF=E4=BB=98?= =?UTF-8?q?=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/Api/BalanceController.php | 42 +++++++++++-------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/app/Http/Controllers/Api/BalanceController.php b/app/Http/Controllers/Api/BalanceController.php index 47656ef..ded81cc 100644 --- a/app/Http/Controllers/Api/BalanceController.php +++ b/app/Http/Controllers/Api/BalanceController.php @@ -102,25 +102,31 @@ public function notify(Request $request) return view('pay_process'); } - $data = Pay::alipay()->callback(); + // try { + // $data = Pay::alipay()->callback(); + // } catch (InvalidResponseException $e) { + // return $this->error('支付失败'); + // } - // 检测 out_trade_no 是否为商户系统中创建的订单号 - if ($data->out_trade_no != $balance->order_id) { - return $this->error('订单号不一致'); + // // 检测 out_trade_no 是否为商户系统中创建的订单号 + // if ($data->out_trade_no != $balance->order_id) { + // return $this->error('订单号不一致'); + // } + + // if ((int) $data->total_amount != (int) $balance->amount) { + // throw new ChargeException('金额不一致'); + // } + + // // 验证 商户 + // if ($data['app_id'] != config('pay.alipay.default.app_id')) { + // throw new ChargeException('商户不匹配'); + // } + + if ($this->checkAndCharge($balance, true)) { + return view('pay_process'); + } else { + return $this->error('支付失败'); } - - if ((int) $data->total_amount != (int) $balance->amount) { - throw new ChargeException('金额不一致'); - } - - // 验证 商户 - if ($data['app_id'] != config('pay.alipay.default.app_id')) { - throw new ChargeException('商户不匹配'); - } - - $this->checkAndCharge($balance); - - return view('pay_process'); } public function checkAndCharge(Balance $balance, $check = false) @@ -145,7 +151,7 @@ public function checkAndCharge(Balance $balance, $check = false) 'paid_at' => now() ]); } catch (InvalidResponseException) { - return $this->error('无法验证支付结果'); + return $this->error('无法验证支付结果。'); } return true;