payment-simulator.html 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>支付模拟器</title>
  7. <style>
  8. * {
  9. margin: 0;
  10. padding: 0;
  11. box-sizing: border-box;
  12. }
  13. body {
  14. font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  15. background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  16. min-height: 100vh;
  17. display: flex;
  18. align-items: center;
  19. justify-content: center;
  20. padding: 20px;
  21. }
  22. .container {
  23. background: white;
  24. border-radius: 20px;
  25. padding: 40px;
  26. max-width: 500px;
  27. width: 100%;
  28. box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  29. }
  30. h1 {
  31. text-align: center;
  32. color: #333;
  33. margin-bottom: 30px;
  34. font-size: 28px;
  35. }
  36. .info {
  37. background: #f5f5f5;
  38. padding: 20px;
  39. border-radius: 10px;
  40. margin-bottom: 30px;
  41. }
  42. .info-item {
  43. display: flex;
  44. justify-content: space-between;
  45. margin-bottom: 10px;
  46. font-size: 16px;
  47. }
  48. .info-item:last-child {
  49. margin-bottom: 0;
  50. }
  51. .label {
  52. color: #666;
  53. }
  54. .value {
  55. color: #333;
  56. font-weight: bold;
  57. }
  58. .amount {
  59. color: #ff6b6b;
  60. font-size: 24px;
  61. }
  62. .buttons {
  63. display: flex;
  64. gap: 15px;
  65. }
  66. button {
  67. flex: 1;
  68. padding: 15px;
  69. border: none;
  70. border-radius: 10px;
  71. font-size: 16px;
  72. font-weight: bold;
  73. cursor: pointer;
  74. transition: all 0.3s;
  75. }
  76. .btn-success {
  77. background: #4caf50;
  78. color: white;
  79. }
  80. .btn-success:hover {
  81. background: #45a049;
  82. transform: translateY(-2px);
  83. box-shadow: 0 5px 15px rgba(76, 175, 80, 0.3);
  84. }
  85. .btn-fail {
  86. background: #f44336;
  87. color: white;
  88. }
  89. .btn-fail:hover {
  90. background: #da190b;
  91. transform: translateY(-2px);
  92. box-shadow: 0 5px 15px rgba(244, 67, 54, 0.3);
  93. }
  94. .message {
  95. margin-top: 20px;
  96. padding: 15px;
  97. border-radius: 10px;
  98. text-align: center;
  99. font-weight: bold;
  100. display: none;
  101. }
  102. .message.success {
  103. background: #d4edda;
  104. color: #155724;
  105. display: block;
  106. }
  107. .message.error {
  108. background: #f8d7da;
  109. color: #721c24;
  110. display: block;
  111. }
  112. .note {
  113. margin-top: 20px;
  114. padding: 15px;
  115. background: #fff3cd;
  116. border-radius: 10px;
  117. font-size: 14px;
  118. color: #856404;
  119. }
  120. </style>
  121. </head>
  122. <body>
  123. <div class="container">
  124. <h1>💳 支付模拟器</h1>
  125. <div class="info">
  126. <div class="info-item">
  127. <span class="label">支付单号:</span>
  128. <span class="value" id="paymentId">-</span>
  129. </div>
  130. <div class="info-item">
  131. <span class="label">支付金额:</span>
  132. <span class="value amount" id="amount">¥0.00</span>
  133. </div>
  134. </div>
  135. <div class="buttons">
  136. <button class="btn-success" onclick="simulatePayment('success')">
  137. ✓ 支付成功
  138. </button>
  139. <button class="btn-fail" onclick="simulatePayment('failed')">
  140. ✗ 支付失败
  141. </button>
  142. </div>
  143. <div class="message" id="message"></div>
  144. <div class="note">
  145. <strong>使用说明:</strong><br>
  146. 1. 在主页面点击"去结算"后会显示二维码<br>
  147. 2. 从URL中获取支付单号(paymentId)<br>
  148. 3. 在此页面输入支付单号并点击按钮模拟支付结果<br>
  149. 4. 主页面会自动检测到支付状态并创建订单
  150. </div>
  151. </div>
  152. <script>
  153. const API_BASE_URL = 'http://localhost:8086/api';
  154. // 从URL获取支付信息
  155. function getPaymentInfo() {
  156. const urlParams = new URLSearchParams(window.location.search);
  157. const paymentId = urlParams.get('paymentId');
  158. const amount = urlParams.get('amount');
  159. if (paymentId) {
  160. document.getElementById('paymentId').textContent = paymentId;
  161. }
  162. if (amount) {
  163. document.getElementById('amount').textContent = '¥' + parseFloat(amount).toFixed(2);
  164. }
  165. return { paymentId, amount };
  166. }
  167. // 模拟支付
  168. async function simulatePayment(status) {
  169. const paymentId = document.getElementById('paymentId').textContent;
  170. if (paymentId === '-') {
  171. showMessage('请先从主页面扫描二维码!', 'error');
  172. return;
  173. }
  174. try {
  175. const response = await fetch(`${API_BASE_URL}/payment/simulate?paymentId=${paymentId}&status=${status}`, {
  176. method: 'POST'
  177. });
  178. const result = await response.json();
  179. if (result.code === 200) {
  180. const message = status === 'success' ? '支付成功!订单正在创建中...' : '支付失败!';
  181. showMessage(message, status === 'success' ? 'success' : 'error');
  182. if (status === 'success') {
  183. setTimeout(() => {
  184. window.close();
  185. }, 2000);
  186. }
  187. } else {
  188. showMessage('操作失败:' + result.message, 'error');
  189. }
  190. } catch (error) {
  191. console.error('模拟支付失败:', error);
  192. showMessage('网络错误,请检查后端服务', 'error');
  193. }
  194. }
  195. function showMessage(text, type) {
  196. const messageEl = document.getElementById('message');
  197. messageEl.textContent = text;
  198. messageEl.className = 'message ' + type;
  199. }
  200. // 页面加载时获取支付信息
  201. window.onload = getPaymentInfo;
  202. </script>
  203. </body>
  204. </html>