doge пре 1 дан
родитељ
комит
7109ec7a01
2 измењених фајлова са 77 додато и 18 уклоњено
  1. 47 18
      app/Http/Controllers/api/Pay.php
  2. 30 0
      app/Services/PaymentOrderService.php

+ 47 - 18
app/Http/Controllers/api/Pay.php

@@ -22,32 +22,61 @@ class Pay extends Controller
     public function notifyHandle(Request $request)
     {
         $data = $request->all();
-        // 记录到专用支付日志
-        Log::channel('payment')->info('支付回调', $data);
-
-        $res = PaymentOrderService::receiveOrder($data);
-        // var_dump($res);
-        if (NoPayService::getWithdrawMerchantId() !== '' && ($data['appId'] ?? '') === NoPayService::getWithdrawMerchantId()) {
-            echo $res ? 'SUCCESS' : 'fail';
-            return;
+        $context = $this->callbackContext($request, $data);
+        Log::error('支付提现回调收到', $context);
+
+        try {
+            $res = PaymentOrderService::receiveOrder($data);
+            Log::error('支付提现回调处理结果', $context + ['success' => (bool)$res]);
+            if (NoPayService::getWithdrawMerchantId() !== '' && ($data['appId'] ?? '') === NoPayService::getWithdrawMerchantId()) {
+                return response($res ? 'SUCCESS' : 'fail');
+            }
+            return response('success');
+        } catch (\Throwable $e) {
+            Log::error('支付提现回调处理异常', $context + [
+                'error' => $e->getMessage(),
+                'exception' => get_class($e),
+            ]);
+            return response('fail', 500);
         }
-        echo 'success';
     }
 
     // 用户支付异步通知
     public function harvestHandle(Request $request)
     {
         $data = $request->all();
-        // 记录到专用支付日志
-        Log::channel('payment')->info('三斤支付回调', $data);
-
-        $res = PaymentOrderService::receivePay($data);
-        // var_dump($res);
-        if (NoPayService::getDepositMerchantId() !== '' && ($data['appId'] ?? '') === NoPayService::getDepositMerchantId()) {
-            echo $res ? 'SUCCESS' : 'fail';
-            return;
+        $context = $this->callbackContext($request, $data);
+        Log::error('支付充值回调收到', $context);
+
+        try {
+            $res = PaymentOrderService::receivePay($data);
+            Log::error('支付充值回调处理结果', $context + ['success' => (bool)$res]);
+            if (NoPayService::getDepositMerchantId() !== '' && ($data['appId'] ?? '') === NoPayService::getDepositMerchantId()) {
+                return response($res ? 'SUCCESS' : 'fail');
+            }
+            return response('success');
+        } catch (\Throwable $e) {
+            Log::error('支付充值回调处理异常', $context + [
+                'error' => $e->getMessage(),
+                'exception' => get_class($e),
+            ]);
+            return response('fail', 500);
         }
-        echo 'success';
     }
 
+    private function callbackContext(Request $request, array $data): array
+    {
+        if (isset($data['sign'])) {
+            $data['sign'] = substr((string)$data['sign'], 0, 8) . '***';
+        }
+
+        return [
+            'ip' => $request->ip(),
+            'url' => $request->fullUrl(),
+            'content_type' => $request->header('Content-Type'),
+            'user_agent' => $request->userAgent(),
+            'data' => $data,
+            'raw_body' => $request->getContent(),
+        ];
+    }
 }

+ 30 - 0
app/Services/PaymentOrderService.php

@@ -397,12 +397,27 @@ class PaymentOrderService extends BaseService
         if (NoPayService::getDepositMerchantId() !== '' && ($params['appId'] ?? '') === NoPayService::getDepositMerchantId()) {
             $info = self::findOne(['order_no' => $params['merchantOrderNo'] ?? '']);
             if (!$info || $info->type != self::TYPE_PAY || !NoPayService::isRechargeChannel($info->channel)) {
+                Log::error('NO钱包充值回调订单不存在或类型不匹配', [
+                    'merchant_order_no' => $params['merchantOrderNo'] ?? '',
+                    'order_id' => $info->id ?? null,
+                    'order_type' => $info->type ?? null,
+                    'channel' => $info->channel ?? null,
+                ]);
                 return false;
             }
             if (!NoPayService::verifyDepositNotify($params)) {
+                Log::error('NO钱包充值回调验签失败', [
+                    'merchant_order_no' => $params['merchantOrderNo'] ?? '',
+                    'app_id' => $params['appId'] ?? '',
+                ]);
                 return false;
             }
             if (bccomp(NoPayService::amount($info->amount), NoPayService::amount($params['amount'] ?? 0), 2) !== 0) {
+                Log::error('NO钱包充值回调金额不一致', [
+                    'merchant_order_no' => $params['merchantOrderNo'] ?? '',
+                    'order_amount' => $info->amount,
+                    'callback_amount' => $params['amount'] ?? null,
+                ]);
                 return false;
             }
             if ($info->status != self::STATUS_PROCESS) {
@@ -936,12 +951,27 @@ class PaymentOrderService extends BaseService
         if (NoPayService::getWithdrawMerchantId() !== '' && ($params['appId'] ?? '') === NoPayService::getWithdrawMerchantId()) {
             $info = self::findOne(['order_no' => $params['merchantOrderNo'] ?? '']);
             if (!$info || $info->type != self::TYPE_PAYOUT || !NoPayService::isWithdrawChannel($info->channel)) {
+                Log::error('NO钱包提现回调订单不存在或类型不匹配', [
+                    'merchant_order_no' => $params['merchantOrderNo'] ?? '',
+                    'order_id' => $info->id ?? null,
+                    'order_type' => $info->type ?? null,
+                    'channel' => $info->channel ?? null,
+                ]);
                 return false;
             }
             if (!NoPayService::verifyWithdrawNotify($params)) {
+                Log::error('NO钱包提现回调验签失败', [
+                    'merchant_order_no' => $params['merchantOrderNo'] ?? '',
+                    'app_id' => $params['appId'] ?? '',
+                ]);
                 return false;
             }
             if (bccomp(NoPayService::amount($info->amount), NoPayService::amount($params['amount'] ?? 0), 2) !== 0) {
+                Log::error('NO钱包提现回调金额不一致', [
+                    'merchant_order_no' => $params['merchantOrderNo'] ?? '',
+                    'order_amount' => $info->amount,
+                    'callback_amount' => $params['amount'] ?? null,
+                ]);
                 return false;
             }
             self::onSubmitNoPayout($params, $info);