6
0
Fork 0

微信支付回调日志

release
李静 2021-12-29 10:20:03 +08:00
parent cbc1e04014
commit 1b6e73bd0b
1 changed files with 20 additions and 0 deletions

View File

@ -11,6 +11,7 @@ use App\Services\WeChatPayService;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Throwable;
class WeChatPayController extends Controller
@ -24,6 +25,8 @@ class WeChatPayController extends Controller
public function paidNotify(WeChatPayService $weChatPayService)
{
return $weChatPayService->handlePaidNotify(function ($message, $fail) {
$this->log('paid notify', $message);
// 通信失败
if (data_get($message, 'return_code') !== 'SUCCESS') {
return $fail('通信失败');
@ -67,6 +70,8 @@ class WeChatPayController extends Controller
public function orderRefundedNotify(WeChatPayService $weChatPayService)
{
return $weChatPayService->handleRefundedNotify(function ($message, $reqInfo, $fail) {
$this->log('refund notify', $reqInfo);
// 通信失败
if (data_get($message, 'return_code') !== 'SUCCESS') {
return $fail('通信失败');
@ -85,4 +90,19 @@ class WeChatPayController extends Controller
return true;
});
}
/**
* 微信回调日志
*
* @param string $message
* @param array $context
* @return void
*/
protected function log(string $message, array $context = [])
{
return Log::build([
'driver' => 'daily',
'path' => storage_path('logs/wxpay-notify.log'),
])->info($message, $context);
}
}