mirror of
				https://gitee.com/technical-laohu/mpay.git
				synced 2025-11-04 16:53:44 +08:00 
			
		
		
		
	码支付更新
This commit is contained in:
		@@ -27,9 +27,9 @@ class IndexController
 | 
				
			|||||||
        if ($action === 'mpay') {
 | 
					        if ($action === 'mpay') {
 | 
				
			||||||
            $data = json_decode($info['data'], true);
 | 
					            $data = json_decode($info['data'], true);
 | 
				
			||||||
            $config = \think\facade\Config::load("payconfig/{$data['pid']}_{$data['aid']}", 'payconfig');
 | 
					            $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);
 | 
					            $Payclient = new $payclient_path($info, $config);
 | 
				
			||||||
            $res = $Payclient->notify($info);
 | 
					            $res = $Payclient->notify();
 | 
				
			||||||
            return $res;
 | 
					            return $res;
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
            return 202;
 | 
					            return 202;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -90,11 +90,12 @@ class PayController
 | 
				
			|||||||
        if ($order_id) {
 | 
					        if ($order_id) {
 | 
				
			||||||
            $act_order = Order::where('order_id', $order_id)->find();
 | 
					            $act_order = Order::where('order_id', $order_id)->find();
 | 
				
			||||||
            if ($act_order) {
 | 
					            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());
 | 
					                View::assign($act_order->toArray());
 | 
				
			||||||
                $passtime = strtotime($act_order->close_time) - time();
 | 
					                $passtime = strtotime($act_order->close_time) - time();
 | 
				
			||||||
                View::assign('passtime', $passtime > 0 ? $passtime : 0);
 | 
					                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();
 | 
					                return View::fetch();
 | 
				
			||||||
            } else {
 | 
					            } else {
 | 
				
			||||||
                return '订单不存在';
 | 
					                return '订单不存在';
 | 
				
			||||||
@@ -329,6 +330,22 @@ class PayController
 | 
				
			|||||||
            return json($info);
 | 
					            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
 | 
					    private static function getSign(array $param = [], string $key = ''): string
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -63,6 +63,7 @@ class PayManageController extends BaseController
 | 
				
			|||||||
            'qrcode' => $channel->qrcode,
 | 
					            'qrcode' => $channel->qrcode,
 | 
				
			||||||
            'last_time' => $channel->last_time,
 | 
					            'last_time' => $channel->last_time,
 | 
				
			||||||
            'state' => $channel->state,
 | 
					            'state' => $channel->state,
 | 
				
			||||||
 | 
					            'type' => $channel->type,
 | 
				
			||||||
        ]);
 | 
					        ]);
 | 
				
			||||||
        return View::fetch();
 | 
					        return View::fetch();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -119,12 +119,23 @@ class Order extends BaseModel
 | 
				
			|||||||
        $channel_infos = PayChannel::whereIn('account_id', $aids)->where('state', 1)->order('last_time', 'asc')->select();
 | 
					        $channel_infos = PayChannel::whereIn('account_id', $aids)->where('state', 1)->order('last_time', 'asc')->select();
 | 
				
			||||||
        if (!$channel_infos || !$aids) return [];
 | 
					        if (!$channel_infos || !$aids) return [];
 | 
				
			||||||
        // 微信/支付宝收款处理
 | 
					        // 微信/支付宝收款处理
 | 
				
			||||||
        $patt_wx = '/^wxpay/i';
 | 
					 | 
				
			||||||
        $patt_ali = '/^alipay/i';
 | 
					 | 
				
			||||||
        foreach ($channel_infos as $key => $value) {
 | 
					        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);
 | 
					        $patt = PayAccount::find($channel_info->account_id);
 | 
				
			||||||
        $channel = ['aid' => $channel_info->account_id, 'cid' => $channel_info->id, 'patt' => $patt->getData('pattern')];
 | 
					        $channel = ['aid' => $channel_info->account_id, 'cid' => $channel_info->id, 'patt' => $patt->getData('pattern')];
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										
											BIN
										
									
								
								public/files/wxpay2K103516.jpg
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								public/files/wxpay2K103516.jpg
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| 
		 After Width: | Height: | Size: 47 KiB  | 
@@ -16,6 +16,8 @@ Route::rule('checkOrder/[:pid]/[:sign]', 'Pay/checkOrder');
 | 
				
			|||||||
Route::rule('payHeart', 'Pay/payHeart');
 | 
					Route::rule('payHeart', 'Pay/payHeart');
 | 
				
			||||||
// 监听收款通知
 | 
					// 监听收款通知
 | 
				
			||||||
Route::rule('checkPayResult', 'Pay/checkPayResult');
 | 
					Route::rule('checkPayResult', 'Pay/checkPayResult');
 | 
				
			||||||
 | 
					// 监听微信/支付宝收款通知
 | 
				
			||||||
 | 
					Route::rule('mpayNotify', 'Pay/mpayNotify');
 | 
				
			||||||
// 验证支付结果
 | 
					// 验证支付结果
 | 
				
			||||||
Route::rule('validatePayResult', 'Pay/validatePayResult');
 | 
					Route::rule('validatePayResult', 'Pay/validatePayResult');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1 +1 @@
 | 
				
			|||||||
{"code":0,"msg":"没有新订单"}
 | 
					{"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}]}
 | 
				
			||||||
@@ -152,6 +152,7 @@
 | 
				
			|||||||
    <script src="/static/js/awesome-qr.min.js"></script>
 | 
					    <script src="/static/js/awesome-qr.min.js"></script>
 | 
				
			||||||
    <script>
 | 
					    <script>
 | 
				
			||||||
        const payCode = '<?php echo htmlentities($payUrl); ?>';
 | 
					        const payCode = '<?php echo htmlentities($payUrl); ?>';
 | 
				
			||||||
 | 
					        const codeType = '<?php echo htmlentities($code_type); ?>';
 | 
				
			||||||
        const payType = '<?php echo htmlentities($type); ?>';
 | 
					        const payType = '<?php echo htmlentities($type); ?>';
 | 
				
			||||||
        const order = '<?php echo htmlentities($order_id); ?>';
 | 
					        const order = '<?php echo htmlentities($order_id); ?>';
 | 
				
			||||||
        const QR = AwesomeQR.AwesomeQR;
 | 
					        const QR = AwesomeQR.AwesomeQR;
 | 
				
			||||||
@@ -167,7 +168,11 @@
 | 
				
			|||||||
                payTypeText.innerText = '请使用支付宝扫码支付'
 | 
					                payTypeText.innerText = '请使用支付宝扫码支付'
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            // 生成二维码
 | 
					            // 生成二维码
 | 
				
			||||||
            document.getElementById('qrcode').src = await getQrcode(payCode, QR);
 | 
					            if (codeType == 0) {
 | 
				
			||||||
 | 
					                document.getElementById('qrcode').src = await getQrcode(payCode, QR);
 | 
				
			||||||
 | 
					            } else {
 | 
				
			||||||
 | 
					                document.getElementById('qrcode').src = payCode;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
            // 订单过期时间
 | 
					            // 订单过期时间
 | 
				
			||||||
            let passtime = 0;
 | 
					            let passtime = 0;
 | 
				
			||||||
            // 订单状态查询
 | 
					            // 订单状态查询
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -22,6 +22,16 @@
 | 
				
			|||||||
                        <input type="text" name="channel" autocomplete="off" class="layui-input">
 | 
					                        <input type="text" name="channel" autocomplete="off" class="layui-input">
 | 
				
			||||||
                    </div>
 | 
					                    </div>
 | 
				
			||||||
                </div>
 | 
					                </div>
 | 
				
			||||||
 | 
					                <div class="layui-form-item">
 | 
				
			||||||
 | 
					                    <label class="layui-form-label">收款样式</label>
 | 
				
			||||||
 | 
					                    <div class="layui-input-block">
 | 
				
			||||||
 | 
					                        <select name="type">
 | 
				
			||||||
 | 
					                            <option value="">请选择</option>
 | 
				
			||||||
 | 
					                            <option value="0">付款链接</option>
 | 
				
			||||||
 | 
					                            <option value="1">图片地址</option>
 | 
				
			||||||
 | 
					                        </select>
 | 
				
			||||||
 | 
					                    </div>
 | 
				
			||||||
 | 
					                </div>
 | 
				
			||||||
                <div class="layui-form-item">
 | 
					                <div class="layui-form-item">
 | 
				
			||||||
                    <label class="layui-form-label">收款码</label>
 | 
					                    <label class="layui-form-label">收款码</label>
 | 
				
			||||||
                    <div class="layui-input-block">
 | 
					                    <div class="layui-input-block">
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -28,18 +28,28 @@
 | 
				
			|||||||
                        <select class="type" lay-filter="select-type">
 | 
					                        <select class="type" lay-filter="select-type">
 | 
				
			||||||
                            <option value="">请选择</option>
 | 
					                            <option value="">请选择</option>
 | 
				
			||||||
                            <!-- <?php if ($platform == 'wxpay') { ?> -->
 | 
					                            <!-- <?php if ($platform == 'wxpay') { ?> -->
 | 
				
			||||||
                            <option value="wx1">个人码</option>
 | 
					                            <option value="wxpay1">个人码</option>
 | 
				
			||||||
                            <option value="wx2">赞赏码</option>
 | 
					                            <option value="wxpay2">赞赏码</option>
 | 
				
			||||||
                            <option value="wx3">经营码</option>
 | 
					                            <!-- <option value="wxpay3">经营码</option>
 | 
				
			||||||
                            <option value="wx4">商家码</option>
 | 
					                            <option value="wxpay4">商家码</option> -->
 | 
				
			||||||
                            <!-- <?php } ?> -->
 | 
					                            <!-- <?php } ?> -->
 | 
				
			||||||
                            <!-- <?php if ($platform == 'alipay') { ?> -->
 | 
					                            <!-- <?php if ($platform == 'alipay') { ?> -->
 | 
				
			||||||
                            <option value="ali1">个人码</option>
 | 
					                            <option value="alipay1">个人码</option>
 | 
				
			||||||
                            <option value="ali2">经营码</option>
 | 
					                            <option value="alipay2">经营码</option>
 | 
				
			||||||
                            <!-- <?php } ?> -->
 | 
					                            <!-- <?php } ?> -->
 | 
				
			||||||
                        </select>
 | 
					                        </select>
 | 
				
			||||||
                    </div>
 | 
					                    </div>
 | 
				
			||||||
                </div>
 | 
					                </div>
 | 
				
			||||||
 | 
					                <div class="layui-form-item">
 | 
				
			||||||
 | 
					                    <label class="layui-form-label">收款样式</label>
 | 
				
			||||||
 | 
					                    <div class="layui-input-block">
 | 
				
			||||||
 | 
					                        <select name="type">
 | 
				
			||||||
 | 
					                            <option value="">请选择</option>
 | 
				
			||||||
 | 
					                            <option value="0">付款链接</option>
 | 
				
			||||||
 | 
					                            <option value="1">图片地址</option>
 | 
				
			||||||
 | 
					                        </select>
 | 
				
			||||||
 | 
					                    </div>
 | 
				
			||||||
 | 
					                </div>
 | 
				
			||||||
                <div class="layui-form-item">
 | 
					                <div class="layui-form-item">
 | 
				
			||||||
                    <label class="layui-form-label">收款码</label>
 | 
					                    <label class="layui-form-label">收款码</label>
 | 
				
			||||||
                    <div class="layui-input-block">
 | 
					                    <div class="layui-input-block">
 | 
				
			||||||
@@ -76,7 +86,7 @@
 | 
				
			|||||||
            form.on('select(select-type)', function (data) {
 | 
					            form.on('select(select-type)', function (data) {
 | 
				
			||||||
                const value = data.value; // 获得被选中的值
 | 
					                const value = data.value; // 获得被选中的值
 | 
				
			||||||
                const channel = document.querySelector('input[name="channel"]');
 | 
					                const channel = document.querySelector('input[name="channel"]');
 | 
				
			||||||
                channel.value = '<?php echo $account ?>' + value;
 | 
					                channel.value = value + '#<?php echo $account ?>';
 | 
				
			||||||
            });
 | 
					            });
 | 
				
			||||||
            form.on('submit(save)', function (obj) {
 | 
					            form.on('submit(save)', function (obj) {
 | 
				
			||||||
                let field = obj.field;
 | 
					                let field = obj.field;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -39,7 +39,17 @@
 | 
				
			|||||||
                    </div>
 | 
					                    </div>
 | 
				
			||||||
                </div>
 | 
					                </div>
 | 
				
			||||||
                <div class="layui-form-item">
 | 
					                <div class="layui-form-item">
 | 
				
			||||||
                    <label class="layui-form-label">付款链接</label>
 | 
					                    <label class="layui-form-label">收款样式</label>
 | 
				
			||||||
 | 
					                    <div class="layui-input-block">
 | 
				
			||||||
 | 
					                        <select name="type">
 | 
				
			||||||
 | 
					                            <option value="">请选择</option>
 | 
				
			||||||
 | 
					                            <option value="0">付款链接</option>
 | 
				
			||||||
 | 
					                            <option value="1">图片地址</option>
 | 
				
			||||||
 | 
					                        </select>
 | 
				
			||||||
 | 
					                    </div>
 | 
				
			||||||
 | 
					                </div>
 | 
				
			||||||
 | 
					                <div class="layui-form-item">
 | 
				
			||||||
 | 
					                    <label class="layui-form-label">付款地址</label>
 | 
				
			||||||
                    <div class="layui-input-block">
 | 
					                    <div class="layui-input-block">
 | 
				
			||||||
                        <input type="text" name="qrcode" autocomplete="off" lay-affix="upload-drag"
 | 
					                        <input type="text" name="qrcode" autocomplete="off" lay-affix="upload-drag"
 | 
				
			||||||
                            lay-filter="scanning" class="layui-input">
 | 
					                            lay-filter="scanning" class="layui-input">
 | 
				
			||||||
@@ -84,7 +94,8 @@
 | 
				
			|||||||
            form.val('edit-channel', {
 | 
					            form.val('edit-channel', {
 | 
				
			||||||
                "channel": "<?php echo $channel ?>",
 | 
					                "channel": "<?php echo $channel ?>",
 | 
				
			||||||
                "qrcode": "<?php echo $qrcode ?>",
 | 
					                "qrcode": "<?php echo $qrcode ?>",
 | 
				
			||||||
                "state": '<?php echo $state ?>' == 1 ? true : false
 | 
					                "state": '<?php echo $state ?>' == 1 ? true : false,
 | 
				
			||||||
 | 
					                "type": '<?php echo $type ?>'
 | 
				
			||||||
            });
 | 
					            });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            form.on('input-affix(scanning)', function () {
 | 
					            form.on('input-affix(scanning)', function () {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -85,9 +85,9 @@
 | 
				
			|||||||
	<script type="text/html" id="account-checkUrl">
 | 
						<script type="text/html" id="account-checkUrl">
 | 
				
			||||||
			{{# 
 | 
								{{# 
 | 
				
			||||||
				if (d.platform == '微信支付') {
 | 
									if (d.platform == '微信支付') {
 | 
				
			||||||
					return `{"payway":"wxpay","pid":"${d.pid}","aid":"${d.id}","uid":"\{\{UID\}\}","title":"\{\{TITLE\}\}","msg":"\{\{MSG\}\}","time":"\{\{RECEIVE_TIME\}\}","divice":"\{\{DEVICE_NAME\}\}"}`;
 | 
										return `{"pid":"${d.pid}","aid":"${d.id}","uid":"\{\{UID\}\}","title":"\{\{TITLE\}\}","msg":"\{\{MSG\}\}","time":"\{\{RECEIVE_TIME\}\}","divice":"\{\{DEVICE_NAME\}\}"}`;
 | 
				
			||||||
				} else if (d.platform == '支付宝') {
 | 
									} else if (d.platform == '支付宝') {
 | 
				
			||||||
					return `{"payway":"alipay","pid":"${d.pid}","aid":"${d.id}","uid":"\{\{UID\}\}","title":"\{\{TITLE\}\}","msg":"\{\{MSG\}\}","time":"\{\{RECEIVE_TIME\}\}","divice":"\{\{DEVICE_NAME\}\}"}`;
 | 
										return `{"pid":"${d.pid}","aid":"${d.id}","uid":"\{\{UID\}\}","title":"\{\{TITLE\}\}","msg":"\{\{MSG\}\}","time":"\{\{RECEIVE_TIME\}\}","divice":"\{\{DEVICE_NAME\}\}"}`;
 | 
				
			||||||
				} else {
 | 
									} else {
 | 
				
			||||||
					return '<?php echo $domain ?>/checkPayResult?pid=' + d.pid + '&aid=' + d.id;
 | 
										return '<?php echo $domain ?>/checkPayResult?pid=' + d.pid + '&aid=' + d.id;
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user