Przeglądaj źródła

fix(wechatpay): 修复支付通知事件类型判断逻辑

- 使用解码后的请求体数据判断事件类型
- 确保交易成功和转账完成事件能被正确识别
- 未实现的事件类型日志记录和异常抛出使用统一数据源
runphp 3 miesięcy temu
rodzic
commit
991c234f84
1 zmienionych plików z 5 dodań i 5 usunięć
  1. 5 5
      src/PaymentProvider.php

+ 5 - 5
src/PaymentProvider.php

@@ -107,10 +107,10 @@ class PaymentProvider implements PaymentProviderInterface
      */
     public function notify(array $request): PaymentNotifyResult
     {
-        $inBody = $request['inBody'];
         $data = $this->notifyService->transactionSuccess($request['headers'], $request['inBody']);
         Log::debug(__METHOD__ . json_encode($data));
-        if ($data['event_type'] == 'TRANSACTION.SUCCESS') {
+        $inBody = json_decode($inBody, true);
+        if ($inBody['event_type'] == 'TRANSACTION.SUCCESS') {
             // 交易成功
             $payment = $this->extensionPaymentEntity->where([
                 'out_trade_no' => $data['out_trade_no'],
@@ -126,7 +126,7 @@ class PaymentProvider implements PaymentProviderInterface
                 status: $queryResult->status,
                 raw: $data
             );
-        } else if ($data['event_type'] == 'MCHTRANSFER.BILL.FINISHED') {
+        } else if ($inBody['event_type'] == 'MCHTRANSFER.BILL.FINISHED') {
             // 转账完成
             $transferBill = $this->wechatpayTransferBillEntity->where('out_bill_no', $data['out_bill_no'])->findOrEmpty();
             if ($transferBill->isEmpty()) {
@@ -141,8 +141,8 @@ class PaymentProvider implements PaymentProviderInterface
                 raw: $data
             );
         }
-        Log::warning('Not implemented: ' . $data['event_type']. ' ' . json_encode($data));
-        throw_logic_exception('Not implemented: ' . $data['event_type']);
+        Log::warning('Not implemented: ' . $inBody['event_type']. ' ' . json_encode($data));
+        throw_logic_exception('Not implemented: ' . $inBody['event_type']);
     }
 
     public function query(int $recordID): PaymentQueryResult