Ver Fonte

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

- 将事件类型判断从 `$inBody` 改为 `$data` 提取字段
- 统一使用 `$data['event_type']` 进行条件判断
- 修复转账完成事件类型的处理逻辑
- 更新未实现事件类型的日志记录和异常抛出逻辑
runphp há 3 meses atrás
pai
commit
4065eb52f6
1 ficheiros alterados com 4 adições e 4 exclusões
  1. 4 4
      src/PaymentProvider.php

+ 4 - 4
src/PaymentProvider.php

@@ -109,7 +109,7 @@ class PaymentProvider implements PaymentProviderInterface
     {
         $inBody = $request['inBody'];
         $data = $this->notifyService->transactionSuccess($request['headers'], $request['inBody']);
-        if ($inBody['event_type'] == 'TRANSACTION.SUCCESS') {
+        if ($data['event_type'] == 'TRANSACTION.SUCCESS') {
             // 交易成功
             Log::debug(__METHOD__ . json_encode($data));
             $payment = $this->extensionPaymentEntity->where([
@@ -126,7 +126,7 @@ class PaymentProvider implements PaymentProviderInterface
                 status: $queryResult->status,
                 raw: $data
             );
-        } else if ($inBody['event_type'] == 'MCHTRANSFER.BILL.FINISHED') {
+        } else if ($data['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: ' . $inBody['event_type']. ' ' . json_encode($data));
-        throw_logic_exception('Not implemented: ' . $inBody['event_type']);
+        Log::warning('Not implemented: ' . $data['event_type']. ' ' . json_encode($data));
+        throw_logic_exception('Not implemented: ' . $data['event_type']);
     }
 
     public function query(int $recordID): PaymentQueryResult