|
|
|
@ -1,7 +1,6 @@ |
|
|
|
<?php |
|
|
|
|
|
|
|
namespace App\Http\Controllers\Api; |
|
|
|
use App\Http\Controllers\Controller; |
|
|
|
use App\Models\Agent; |
|
|
|
use App\Models\AgentProduct; |
|
|
|
use App\Models\Order; |
|
|
|
@ -20,7 +19,7 @@ class WxpayController |
|
|
|
{ |
|
|
|
// {"sign": "3F99E6044C503B0E0131F95A1410B630", "appid": "wxb35ef055a4dd8ad4", "mch_id": "1606181693", "openid": "oBYj55W0gLv5MYUnsYUuJfzYzmsg", "cash_fee": "1", "fee_type": "CNY", "time_end": "20210623222330", "bank_type": "OTHERS", "nonce_str": "60d343d820e94", "total_fee": "1", "trade_type": "JSAPI", "result_code": "SUCCESS", "return_code": "SUCCESS", "is_subscribe": "N", "out_trade_no": "2842908479209865216", "transaction_id": "4200001210202106237487333085"}
|
|
|
|
|
|
|
|
$agent_id = request()->route('aid'); |
|
|
|
$agent_id = request()->route('agent_id'); |
|
|
|
$agent = Agent::find($agent_id); |
|
|
|
|
|
|
|
$config = config('wechat.payment.default'); |
|
|
|
@ -41,7 +40,7 @@ class WxpayController |
|
|
|
->first(); |
|
|
|
|
|
|
|
//已经处理过的订单直接返回true
|
|
|
|
if ($order && in_array($order->status, [OrderStatus::PAID, OrderStatus::PAY_RETAINAGE])) { |
|
|
|
if ($order && in_array($order->status, [OrderStatus::PAID, OrderStatus::PAID_RETAINAGE])) { |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
@ -56,7 +55,7 @@ class WxpayController |
|
|
|
if ($pay_type == OrderStatus::UNPAID) { |
|
|
|
$order->status = OrderStatus::PAY_EARNEST; |
|
|
|
} else if ($status == OrderStatus::PAY_EARNEST) { |
|
|
|
$order->status = OrderStatus::PAY_RETAINAGE; |
|
|
|
$order->status = OrderStatus::PAID_RETAINAGE; |
|
|
|
} |
|
|
|
} else if ($pay_type == 0) { |
|
|
|
$order->status = OrderStatus::PAID; |
|
|
|
@ -88,7 +87,7 @@ class WxpayController |
|
|
|
|
|
|
|
DB::commit(); |
|
|
|
return true; |
|
|
|
} catch (\Exception $e) { |
|
|
|
} catch (Exception $e) { |
|
|
|
DB::rollBack(); |
|
|
|
$fail('Unknown error'); |
|
|
|
} |
|
|
|
@ -101,7 +100,7 @@ class WxpayController |
|
|
|
// 希望微信重试
|
|
|
|
$fail('Order not exists.'); |
|
|
|
}); |
|
|
|
} catch (InvalidSignException | \Exception $e) { |
|
|
|
} catch (InvalidSignException | Exception $e) { |
|
|
|
$time = time(); |
|
|
|
$filename = storage_path('logs/wxpay_notify_') . date('Y-m-d-H', $time) . '.log'; |
|
|
|
$data = '[' . date('Y-m-d H:i:s', $time) . ']' . PHP_EOL; |
|
|
|
@ -119,8 +118,17 @@ class WxpayController |
|
|
|
|
|
|
|
// {"sign": "3F99E6044C503B0E0131F95A1410B630", "appid": "wxb35ef055a4dd8ad4", "mch_id": "1606181693", "openid": "oBYj55W0gLv5MYUnsYUuJfzYzmsg", "cash_fee": "1", "fee_type": "CNY", "time_end": "20210623222330", "bank_type": "OTHERS", "nonce_str": "60d343d820e94", "total_fee": "1", "trade_type": "JSAPI", "result_code": "SUCCESS", "return_code": "SUCCESS", "is_subscribe": "N", "out_trade_no": "2842908479209865216", "transaction_id": "4200001210202106237487333085"}
|
|
|
|
|
|
|
|
$agent_id = request()->route('agent_id'); |
|
|
|
$agent = Agent::find($agent_id); |
|
|
|
|
|
|
|
$config = config('wechat.payment.default'); |
|
|
|
$config = array_merge($config, [ |
|
|
|
'app_id' => $agent->appid, |
|
|
|
'mch_id' => $agent->mchid, |
|
|
|
'key' => $agent->mchkey, |
|
|
|
]); |
|
|
|
$app = Factory::payment($config); |
|
|
|
try { |
|
|
|
$response = $app->handleRefundedNotify(function ($message, $reqInfo, $fail) { |
|
|
|
// 记录一下本地调试
|
|
|
|
file_put_contents(storage_path('/wxpay/refund' . date('Y-m-d-H') . '.log'), date('Y-m-d H:i:s') . PHP_EOL . json_encode($message) . PHP_EOL . json_encode($reqInfo), FILE_APPEND); |
|
|
|
@ -172,6 +180,9 @@ class WxpayController |
|
|
|
|
|
|
|
$fail('Unknown error'); |
|
|
|
}); |
|
|
|
} catch (Exception $e) { |
|
|
|
return 'error'; |
|
|
|
} |
|
|
|
|
|
|
|
return $response; |
|
|
|
} |
|
|
|
|