码支付更新

This commit is contained in:
技术老胡
2024-11-20 16:23:09 +08:00
parent a1707612dc
commit b19e0039f2
12 changed files with 88 additions and 21 deletions

View File

@@ -27,9 +27,9 @@ class IndexController
if ($action === 'mpay') {
$data = json_decode($info['data'], true);
$config = \think\facade\Config::load("payconfig/{$data['pid']}_{$data['aid']}", 'payconfig');
$payclient_path = "\\payclient\\Mpay";
$payclient_path = "\\payclient\\{$config['pay']['payclass']}";
$Payclient = new $payclient_path($info, $config);
$res = $Payclient->notify($info);
$res = $Payclient->notify();
return $res;
} else {
return 202;

View File

@@ -90,11 +90,12 @@ class PayController
if ($order_id) {
$act_order = Order::where('order_id', $order_id)->find();
if ($act_order) {
$qrcode = PayChannel::where('id', $act_order->cid)->value('qrcode');
$channel = PayChannel::where('id', $act_order->cid)->find();
View::assign($act_order->toArray());
$passtime = strtotime($act_order->close_time) - time();
View::assign('passtime', $passtime > 0 ? $passtime : 0);
View::assign('payUrl', $qrcode);
View::assign('payUrl', $channel->qrcode);
View::assign('code_type', $channel->type);
return View::fetch();
} else {
return '订单不存在';
@@ -329,6 +330,22 @@ class PayController
return json($info);
}
}
// 处理微信/支付宝收款通知
public function mpayNotify(Request $request)
{
$info = $request->post();
$action = isset($info['action']) ? $info['action'] : '';
if ($action === 'mpay') {
$data = json_decode($info['data'], true);
$config = \think\facade\Config::load("payconfig/{$data['pid']}_{$data['aid']}", 'payconfig');
$payclient_path = "\\payclient\\{$config['pay']['payclass']}";
$Payclient = new $payclient_path($info, $config, $request->domain());
$Payclient->notify();
return 200;
} else {
return 202;
}
}
// 签名
private static function getSign(array $param = [], string $key = ''): string
{

View File

@@ -63,6 +63,7 @@ class PayManageController extends BaseController
'qrcode' => $channel->qrcode,
'last_time' => $channel->last_time,
'state' => $channel->state,
'type' => $channel->type,
]);
return View::fetch();
}

View File

@@ -119,12 +119,23 @@ class Order extends BaseModel
$channel_infos = PayChannel::whereIn('account_id', $aids)->where('state', 1)->order('last_time', 'asc')->select();
if (!$channel_infos || !$aids) return [];
// 微信/支付宝收款处理
$patt_wx = '/^wxpay/i';
$patt_ali = '/^alipay/i';
foreach ($channel_infos as $key => $value) {
$check_wx = preg_match('/^wxpay\d+#/i', $value->channel);
$check_ali = preg_match('/^alipay\d+#/i', $value->channel);
if ($check_wx && $type === 'wxpay') {
$channel_info = $channel_infos[$key];
break;
} elseif ($check_ali && $type === 'alipay') {
$channel_info = $channel_infos[$key];
break;
} else {
if ($check_wx || $check_ali) {
continue;
}
$channel_info = $channel_infos[$key];
break;
}
}
$channel_info = $channel_infos[0];
// 选取收款通道
$patt = PayAccount::find($channel_info->account_id);
$channel = ['aid' => $channel_info->account_id, 'cid' => $channel_info->id, 'patt' => $patt->getData('pattern')];