1
This commit is contained in:
parent
63894f37a6
commit
8ea79574dc
@ -139,6 +139,33 @@ class CallBackController extends AbstractController
|
||||
}
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 微信支付返回错误响应
|
||||
* @param string $message
|
||||
|
||||
@ -378,6 +378,9 @@ Router::addGroup('/callback', function () {
|
||||
Router::addGroup('/inquiry', function () {
|
||||
// 支付成功回调
|
||||
Router::post('/success', [CallBackController::class, 'wxPaySuccessCallBack']);
|
||||
|
||||
// 退款回调
|
||||
Router::post('/refund', [CallBackController::class, 'wxPayRefundCallBack']);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@ -178,9 +178,7 @@ class WechatPay
|
||||
try {
|
||||
$app = $this->createApp();
|
||||
|
||||
$options = [
|
||||
"notify_url " => env('DOMAIN_NAME_DEV') . $this->config['refund_notify_url'],
|
||||
];
|
||||
$options['notify_url'] = env('DOMAIN_NAME_DEV') . $this->config['refund_notify_url'];
|
||||
|
||||
$response = $app->getClient()->postJson("v3/refund/domestic/refunds", $options);
|
||||
if ($response->isFailed()) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user