diff --git a/app/controller/IndexController.php b/app/controller/IndexController.php index b8b4205..7bee3a4 100644 --- a/app/controller/IndexController.php +++ b/app/controller/IndexController.php @@ -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; diff --git a/app/controller/PayController.php b/app/controller/PayController.php index a09e3d9..9dbff0b 100644 --- a/app/controller/PayController.php +++ b/app/controller/PayController.php @@ -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 { diff --git a/app/controller/PayManageController.php b/app/controller/PayManageController.php index eacd3da..12e224f 100644 --- a/app/controller/PayManageController.php +++ b/app/controller/PayManageController.php @@ -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(); } diff --git a/app/model/Order.php b/app/model/Order.php index 46480cf..0b26a12 100644 --- a/app/model/Order.php +++ b/app/model/Order.php @@ -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')]; diff --git a/public/files/wxpay2K103516.jpg b/public/files/wxpay2K103516.jpg new file mode 100644 index 0000000..6e391c8 Binary files /dev/null and b/public/files/wxpay2K103516.jpg differ diff --git a/route/app.php b/route/app.php index 310bfe3..bfac610 100644 --- a/route/app.php +++ b/route/app.php @@ -16,6 +16,8 @@ Route::rule('checkOrder/[:pid]/[:sign]', 'Pay/checkOrder'); Route::rule('payHeart', 'Pay/payHeart'); // 监听收款通知 Route::rule('checkPayResult', 'Pay/checkPayResult'); +// 监听微信/支付宝收款通知 +Route::rule('mpayNotify', 'Pay/mpayNotify'); // 验证支付结果 Route::rule('validatePayResult', 'Pay/validatePayResult'); diff --git a/runtime/order.json b/runtime/order.json index 51b4235..d1bee53 100644 --- a/runtime/order.json +++ b/runtime/order.json @@ -1 +1 @@ -{"code":0,"msg":"没有新订单"} \ No newline at end of file +{"code":1,"msg":"\u67092\u4e2a\u65b0\u8ba2\u5355","orders":[{"id":36348,"pid":1001,"aid":46,"cid":39,"patt":1},{"id":36350,"pid":1001,"aid":1,"cid":1,"patt":1}]} \ No newline at end of file diff --git a/view/pay/console.html b/view/pay/console.html index 0552c9a..4cab60c 100644 --- a/view/pay/console.html +++ b/view/pay/console.html @@ -152,6 +152,7 @@