This commit is contained in:
wucongxing 2023-03-07 17:59:55 +08:00
parent 63894f37a6
commit 8ea79574dc
3 changed files with 31 additions and 3 deletions

View File

@ -136,7 +136,34 @@ class CallBackController extends AbstractController
Db::rollBack(); Db::rollBack();
Log::getInstance()->error("微信支付回调数据验证失败:" . $e->getMessage()); Log::getInstance()->error("微信支付回调数据验证失败:" . $e->getMessage());
return $this->wxPayErrorReturn($e->getMessage()); return $this->wxPayErrorReturn($e->getMessage());
}
}
public function wxPayRefundCallBack(): ResponseInterface
{
try {
// 处理支付结果事件
$WechatPay = new WechatPay(1);
$app = $WechatPay->createApp();
$server = $app->getServer();
$message = $server->getRequestMessage();
if (empty($message)){
Db::rollBack();
return $this->response->withStatus(500)->withBody(new SwooleStream(strval(json_encode(['code' => 'ERROR', 'message' => "回调数据为空"], JSON_UNESCAPED_UNICODE))));
} }
// 验证推送消息签名
$app->getValidator()->validate($app->getRequest());
Log::getInstance()->info("微信支付回调数据:" . json_encode($message,JSON_UNESCAPED_UNICODE));
return $server->serve();
}catch (\Exception $e) {
// 验证失败
Db::rollBack();
Log::getInstance()->error("微信支付回调数据验证失败:" . $e->getMessage());
return $this->wxPayErrorReturn($e->getMessage());
}
} }
/** /**

View File

@ -378,6 +378,9 @@ Router::addGroup('/callback', function () {
Router::addGroup('/inquiry', function () { Router::addGroup('/inquiry', function () {
// 支付成功回调 // 支付成功回调
Router::post('/success', [CallBackController::class, 'wxPaySuccessCallBack']); Router::post('/success', [CallBackController::class, 'wxPaySuccessCallBack']);
// 退款回调
Router::post('/refund', [CallBackController::class, 'wxPayRefundCallBack']);
}); });
}); });

View File

@ -178,9 +178,7 @@ class WechatPay
try { try {
$app = $this->createApp(); $app = $this->createApp();
$options = [ $options['notify_url'] = env('DOMAIN_NAME_DEV') . $this->config['refund_notify_url'];
"notify_url " => env('DOMAIN_NAME_DEV') . $this->config['refund_notify_url'],
];
$response = $app->getClient()->postJson("v3/refund/domestic/refunds", $options); $response = $app->getClient()->postJson("v3/refund/domestic/refunds", $options);
if ($response->isFailed()) { if ($response->isFailed()) {