退款回调

This commit is contained in:
chenbo 2023-11-21 17:19:34 +08:00
parent 0bba4e2aa6
commit 0e95637a2b
2 changed files with 26 additions and 5 deletions

View File

@ -21,6 +21,7 @@ use app\common\enum\RefundEnum;
use app\common\model\refund\RefundLog;
use app\common\model\refund\RefundRecord;
use app\common\service\pay\WeChatPayService;
use Symfony\Component\HttpClient\HttpClient;
/**
@ -163,4 +164,17 @@ class RefundLogic extends BaseLogic
]);
}
public static function callBusiness($notifyUrl,$param)
{
try {
$requestResponse = HttpClient::create()->request('POST', $notifyUrl, [
'body' => $param
]);
return json_decode($requestResponse->getContent(), true);
} catch (Exception $e) {
self::setError($e->getMessage());
return false;
}
}
}

View File

@ -18,19 +18,16 @@ namespace app\common\service\pay;
use app\common\enum\PayEnum;
use app\common\enum\PayOrderEnum;
use app\common\enum\user\UserTerminalEnum;
use app\common\logic\PaymentLogic;
use app\common\logic\PayNotifyLogic;
use app\common\logic\RefundLogic;
use app\common\model\pay\PayConfig;
use app\common\model\pay\PayOrder;
use app\common\model\recharge\RechargeOrder;
use app\common\model\pay\RefundOrder;
use app\common\model\user\UserAuth;
use app\common\service\wechat\WeChatConfigService;
use app\common\service\wechat\WeChatPayMerchantConfigService;
use EasyWeChat\Pay\Application;
use EasyWeChat\Pay\Message;
use think\Exception;
use think\Log;
/**
@ -279,6 +276,16 @@ class WeChatPayMerchantService extends BasePayService
// 退款通知
$server->handleRefunded(function (Message $message) {
\think\facade\Log::info(['退款回调信息', $message]);
if($message['refund_status'] === 'SUCCESS') {
$refundOrder = RefundOrder::where(['out_trade_no', $message['out_trade_no'], 'refund_sn'=>$message['out_refund_no']])->find();
$refundOrder->refund_status = 1;
$refundOrder->refund_id = $message['refund_id'];
$refundOrder->finish_time = time();
$refundOrder->save();
// 通知业务系统
RefundLogic::callBusiness($refundOrder['business_callback_url'], ['out_trade_no'=>$refundOrder['business_order_sn'], 'transaction_id'=>$message['refund_id'], 'refund_status'=>1]);
}
return true;
});
return $server->serve();