更新订单回调通知逻辑

This commit is contained in:
技术老胡 2025-01-18 10:57:16 +08:00
parent 2515515182
commit f9c804c1e5
2 changed files with 27 additions and 15 deletions

View File

@ -97,7 +97,12 @@ class PayController
$sign = self::getSign($notify, $user_key);
$notify['sign'] = $sign;
// 跳转通知URL
$res_return_url = $act_order->return_url . '?' . http_build_query($notify);
$res_return_url = '';
if (strpos($act_order->return_url, '?')) {
$res_return_url = $act_order->return_url . '&' . http_build_query($notify);
} else {
$res_return_url = $act_order->return_url . '?' . http_build_query($notify);
}
// 响应消息
$data['order_id'] = $act_order->order_id;
$data['passtime'] = $passtime > 0 ? $passtime : 0;
@ -187,7 +192,13 @@ class PayController
$sign = self::getSign($notify, $user_key);
$notify['sign'] = $sign;
// 异步通知
$res_notify = self::getHttpResponse($order->notify_url . '?' . http_build_query($notify));
$notify_url = '';
if (strpos($order->notify_url, '?')) {
$notify_url = $order->notify_url . '&' . http_build_query($notify);
} else {
$notify_url = $order->notify_url . '?' . http_build_query($notify);
}
$res_notify = self::getHttpResponse($notify_url);
if ($res_notify === 'success') {
return ['order' => $order->order_id, 'code' => 1, 'msg' => 'notify success'];
} else {
@ -314,7 +325,8 @@ class PayController
'sign_type' => 'MD5',
];
// 添加扩展参数
$notify = array_merge($notify, unserialize($param->param));
// $notify = array_merge($notify, unserialize($param->param));
$notify['param'] = unserialize($param->param);
return $notify;
}
// 请求外部资源

View File

@ -42,7 +42,7 @@ class Order extends BaseModel
// 设备类型
'device' => isset($data['device']) ? $data['device'] : '',
// 业务扩展参数
'param' => serialize(self::getParams($data)),
'param' => serialize(isset($data['param']) ? $data['param'] : ''),
// 等待/过期0, 支付成功1
'state' => 0,
// 开启监听1, 关闭监听0
@ -148,17 +148,17 @@ class Order extends BaseModel
return $channel;
}
// 获取扩展参数数组
private static function getParams(array $data): array
{
$keys = ['pid', 'type', 'out_trade_no', 'notify_url', 'return_url', 'name', 'money', 'sign', 'sign_type'];
$params = [];
foreach ($data as $key => $value) {
if (!in_array($key, $keys)) {
$params[$key] = $value;
}
}
return $params;
}
// private static function getParams(array $data): array
// {
// $keys = ['pid', 'type', 'out_trade_no', 'notify_url', 'return_url', 'name', 'money', 'sign', 'sign_type'];
// $params = [];
// foreach ($data as $key => $value) {
// if (!in_array($key, $keys)) {
// $params[$key] = $value;
// }
// }
// return $params;
// }
// 检查金额
private static function checkMoney($money, $type, $aid, $cid): float
{