仰望星辰工作室

better-staridc-MNBT

Z zfhsh first commit 2 个月前
1<?php
2/**
3 * qmzl_domain - 用户端支付页
4 *
5 * 下单后跳转到本页(index.php?_r=/qmzl/pay&order={上游订单ID}),
6 * 路由处理器已校验订单归属并传入 $order / $order_id / $order_valid。
7 * 前端调用 /qmzl/api/pay 发起支付并渲染三方返回的 HTML(自动提交表单 / 二维码),
8 * 同时轮询 /qmzl/api/pay_status 直到支付完成。
9 */
10if (!defined('IN_CRONLITE')) exit;
11$order = $order ?? null;
12$orderId = (int)($order_id ?? 0);
13$orderValid = !empty($order_valid);
14$qzCss = qmzl_asset_url('qmzl.css');
15$qzJs = qmzl_asset_url('qmzl.js');
16$qzMdi = mnbt_asset_url('css/materialdesignicons.min.css');
17$qzJq = mnbt_asset_url('js/jquery.min.js');
18$qzApi = qmzl_url(qmzl_route_prefix() . '/api');
19$qzDomUrl = qmzl_url(qmzl_route_prefix() . '/domains');
20$qzIdxUrl = qmzl_url(qmzl_route_prefix());
21$orderDomain = is_array($order) ? (string)($order['domain'] ?? '') : '';
22$orderAmount = is_array($order) ? (string)($order['amount'] ?? '0.00') : '0.00';
23$orderGateway = is_array($order) ? (string)($order['gateway'] ?? '') : '';
24?>
25<!DOCTYPE html>
26<html lang="zh-CN">
27<head>
28<meta charset="UTF-8">
29<meta name="viewport" content="width=device-width, initial-scale=1.0">
30<title>域名支付 - 域名服务</title>
31<link rel="stylesheet" href="<?= htmlspecialchars($qzMdi, ENT_QUOTES, 'UTF-8') ?>">
32<link rel="stylesheet" href="<?= htmlspecialchars($qzCss, ENT_QUOTES, 'UTF-8') ?>">
33<style>
34body { margin: 0; background: var(--qz-bg); color: var(--qz-text); font: 14px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif; -webkit-font-smoothing: antialiased; padding: 24px 16px 48px; }
35#qz-pay-html { display: flex; justify-content: center; margin-top: 8px; }
36#qz-pay-html form, #qz-pay-html .qr-wrap { width: 100%; max-width: 380px; margin: 0 auto; text-align: center; }
37#qz-pay-html img.qr { width: 240px; height: 240px; border: 1px solid var(--qz-border); border-radius: 12px; }
38#qz-pay-html .btn-pay-link { display: inline-block; margin-top: 16px; }
39.spin { display: inline-block; animation: qzSpin 1s linear infinite; }
40@keyframes qzSpin { to { transform: rotate(360deg); } }
41.qz-nav { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; }
42.qz-nav a { display: inline-block; padding: 6px 14px; border-radius: 20px; font-size: 13px; background: #fff; border: 1px solid var(--qz-border); color: var(--qz-text-2); text-decoration: none; transition: all .15s; }
43.qz-nav a:hover { border-color: var(--qz-brand); color: var(--qz-brand); }
44</style>
45</head>
46<body>
47<div class="qz-wrap" style="max-width:720px;">
48
49 <div class="qz-head">
50 <h1>域名支付</h1>
51 <p>订单 <span class="qz-monospace" id="qz-order-id"><?= (int)$orderId ?></span> · 域名 <span class="qz-monospace" id="qz-domain"><?= htmlspecialchars($orderDomain, ENT_QUOTES, 'UTF-8') ?></span></p>
52 <div class="qz-nav" style="margin-top:12px;">
53 <a href="<?= htmlspecialchars($qzIdxUrl, ENT_QUOTES, 'UTF-8') ?>">域名注册</a>
54 <a href="<?= htmlspecialchars($qzDomUrl, ENT_QUOTES, 'UTF-8') ?>">我的域名</a>
55 </div>
56 </div>
57
58 <div class="qz-card">
59 <div class="qz-card-body">
60 <!-- 加载中 -->
61 <div id="qz-loading" style="text-align:center;padding:36px 0;color:var(--qz-text-3);">
62 <span class="spin mdi mdi-loading" style="font-size:28px;"></span>
63 <div style="margin-top:10px;">正在创建支付订单...</div>
64 </div>
65
66 <!-- 支付内容 -->
67 <div id="qz-pay-html" style="display:none;"></div>
68
69 <!-- 支付失败 -->
70 <div id="qz-error" style="display:none;text-align:center;padding:24px 0;">
71 <div style="font-size:40px;color:var(--qz-danger);"><span class="mdi mdi-alert-circle-outline"></span></div>
72 <div style="margin:10px 0 18px;color:var(--qz-text-2);" id="qz-error-msg"></div>
73 <button type="button" class="qz-btn" id="qz-btn-retry"><span class="mdi mdi-refresh"></span> 重试</button>
74 <a class="qz-btn qz-btn--ghost" style="margin-left:8px;" href="<?= htmlspecialchars($qzDomUrl, ENT_QUOTES, 'UTF-8') ?>">我的域名</a>
75 </div>
76
77 <!-- 已支付 -->
78 <div id="qz-paid" style="display:none;text-align:center;padding:24px 0;">
79 <div style="font-size:44px;color:var(--qz-success);"><span class="mdi mdi-check-circle"></span></div>
80 <div style="margin:10px 0 4px;font-size:17px;font-weight:600;">支付成功</div>
81 <div style="color:var(--qz-text-2);margin-bottom:20px;">域名注册处理中,稍后可在“我的域名”中查看</div>
82 <a class="qz-btn" href="<?= htmlspecialchars($qzDomUrl, ENT_QUOTES, 'UTF-8') ?>"><span class="mdi mdi-earth"></span> 查看我的域名</a>
83 </div>
84 </div>
85 </div>
86
87 <div class="qz-card">
88 <div class="qz-card-head"><h3>订单信息</h3></div>
89 <div class="qz-card-body">
90 <table class="qz-table">
91 <tr><th style="width:130px;">域名</th><td class="qz-monospace"><?= htmlspecialchars($orderDomain ?: '-', ENT_QUOTES, 'UTF-8') ?></td></tr>
92 <tr><th>金额</th><td style="color:var(--qz-brand);font-weight:700;">¥<?= htmlspecialchars($orderAmount ?: '0.00', ENT_QUOTES, 'UTF-8') ?></td></tr>
93 <tr><th>状态</th><td id="qz-order-status">-</td></tr>
94 </table>
95 </div>
96 </div>
97
98</div>
99
100<script src="<?= htmlspecialchars($qzJq, ENT_QUOTES, 'UTF-8') ?>"></script>
101<script src="<?= htmlspecialchars($qzJs, ENT_QUOTES, 'UTF-8') ?>"></script>
102<script>
103$(function () {
104 var QZ_API = <?= json_encode($qzApi, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) ?>;
105 var ORDER_ID = <?= (int)$orderId ?>;
106 var GATEWAY = <?= json_encode($orderGateway, JSON_UNESCAPED_UNICODE) ?>;
107 var ORDER_VALID = <?= $orderValid ? 'true' : 'false' ?>;
108 var pollTimer = null;
109
110 function setStatus(txt) { $('#qz-order-status').html(txt); }
111 setStatus('<span class="qz-badge qz-badge--yellow">待支付</span>');
112
113 function renderPaidHtml(html) {
114 $('#qz-loading').hide();
115 var $wrap = $('#qz-pay-html');
116 $wrap.show().html(html);
117
118 // 自动提交支付表单(跳转到三方网关)
119 var $form = $wrap.find('form').first();
120 if ($form.length) {
121 var btn = '<div style="margin-top:14px;"><a class="qz-btn" id="qz-open-gateway" href="javascript:void(0)">若未自动跳转,点击此处进入支付</a></div>';
122 $wrap.append(btn);
123 setTimeout(function () {
124 try { $form.submit(); } catch (e) {}
125 }, 300);
126 $('#qz-open-gateway').on('click', function () {
127 try { $form.submit(); } catch (e) {}
128 });
129 }
130
131 // 二维码 / 图片
132 if ($wrap.find('img').length) {
133 $wrap.find('img').addClass('qr');
134 var tip = '<div class="qz-muted" style="margin-top:12px;">请使用' + (GATEWAY || '支付工具') + '扫码完成支付,支付完成后将自动确认</div>';
135 $wrap.append(tip);
136 }
137
138 startPoll();
139 }
140
141 function startPoll() {
142 if (pollTimer) clearInterval(pollTimer);
143 pollTimer = setInterval(function () {
144 QZ.post(QZ_API + '/pay_status', { order_id: ORDER_ID }, function (res) {
145 if (res.data && res.data.paid) {
146 clearInterval(pollTimer);
147 onPaid();
148 }
149 }, function () {});
150 }, 2500);
151 }
152
153 function onPaid() {
154 $('#qz-pay-html').hide();
155 $('#qz-paid').show();
156 setStatus('<span class="qz-badge qz-badge--green">已支付</span>');
157 }
158
159 function initPay() {
160 QZ.post(QZ_API + '/pay', { order_id: ORDER_ID, gateway: GATEWAY }, function (res) {
161 if (res.data && res.data.code === 'Paid') { onPaid(); return; }
162 var html = (res.data && res.data.html) || '';
163 if (!html) { onPaid(); return; }
164 renderPaidHtml(html);
165 }, function (msg) {
166 $('#qz-loading').hide();
167 $('#qz-error').show();
168 $('#qz-error-msg').text(msg || '发起支付失败');
169 });
170 }
171
172 $('#qz-btn-retry').on('click', function () {
173 $('#qz-error').hide();
174 $('#qz-loading').show();
175 $('#qz-pay-html').hide();
176 initPay();
177 });
178
179 if (!ORDER_VALID) {
180 $('#qz-loading').hide();
181 $('#qz-error').show();
182 $('#qz-error-msg').text('订单不存在或不属于当前账号');
183 setStatus('<span class="qz-badge qz-badge--gray">无效</span>');
184 return;
185 }
186 initPay();
187});
188</script>
189</body>
190</html>