samlax12 commited on
Commit
d9732c8
·
verified ·
1 Parent(s): 8f92a2e

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +96 -114
index.html CHANGED
@@ -4,6 +4,8 @@
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
6
  <title>收款</title>
 
 
7
  <style>
8
  * {
9
  margin: 0;
@@ -259,33 +261,22 @@
259
  transform: translateY(-1px);
260
  }
261
 
262
- /* 二维码显示区域 */
263
- .qr-container {
264
  display: none;
265
- text-align: center;
266
- padding: 20px;
267
- }
268
-
269
- .qr-code-image {
270
- width: 200px;
271
- height: 200px;
272
- margin: 0 auto 20px;
273
- padding: 10px;
274
- background-color: white;
275
- border-radius: 10px;
276
- box-shadow: 0 2px 10px rgba(0,0,0,0.1);
277
  }
278
 
279
- .qr-code-image img {
280
- width: 100%;
281
- height: 100%;
282
- display: block;
 
283
  }
284
 
285
- .payment-tips {
286
- font-size: 14px;
287
- color: #666;
288
- line-height: 1.6;
289
  }
290
 
291
  /* 响应式优化 */
@@ -365,48 +356,35 @@
365
  <!-- 支付处理覆盖层 -->
366
  <div class="payment-overlay" id="paymentOverlay">
367
  <div class="payment-processing">
368
- <!-- 初始加载状态 -->
369
  <div id="loadingState">
370
  <div class="loading-spinner"></div>
371
  <div class="payment-message">正在处理支付请求...</div>
372
- <div class="payment-submessage">正在检测您的支付环境</div>
373
  </div>
374
 
375
- <!-- 二维码支付状态 -->
376
- <div id="qrState" class="qr-container">
377
- <div class="payment-message">请使用微信扫码支付</div>
378
- <div class="qr-code-image">
379
- <!-- 在这里放置您的收款二维码图片 -->
380
- <img src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200' viewBox='0 0 200 200'%3E%3Crect width='200' height='200' fill='%23f0f0f0'/%3E%3Ctext x='100' y='100' text-anchor='middle' dy='.3em' font-size='14' fill='%23999'%3E请替换为二维码%3C/text%3E%3C/svg%3E" alt="支付二维码" id="paymentQR">
381
- </div>
382
- <div class="payment-tips">
383
- 金额:¥<span id="qrAmount">0.00</span><br>
384
- 请在微信中扫描上方二维码完成支付
385
- </div>
386
  <div class="payment-actions">
387
- <button class="action-button primary" onclick="confirmPayment()">我已完成支付</button>
388
- <button class="action-button secondary" onclick="cancelPayment()">取消</button>
389
- </div>
390
- </div>
391
-
392
- <!-- 微信内支付提示 -->
393
- <div id="wechatState" style="display: none;">
394
- <div class="payment-message">正在跳转到微信支付...</div>
395
- <div class="payment-submessage">请稍候,系统正在为您处理</div>
396
- <div class="payment-actions" style="margin-top: 20px;">
397
  <button class="action-button secondary" onclick="cancelPayment()">取消</button>
398
  </div>
399
  </div>
400
  </div>
401
  </div>
402
 
 
 
 
 
403
  <script>
404
  // 配置项
405
  const CONFIG = {
406
- // 微信支付链接(从二维码解析得到的)
407
- wechatPayUrl: 'wxp://f2f0uaoKZnUqDIp6w1BYLiXrLJjIntTdVoaTLkQhX8vsZfw',
408
- // 备用二维码图片路径(请替换为您的实际二维码图片文件名)
409
- qrCodeImagePath: 'wechat-qr.jpg' // 例如:如果您的二维码文件名是 wechat-qr.jpg
410
  };
411
 
412
  let selectedItems = new Set();
@@ -454,80 +432,92 @@
454
  total += parseFloat(amount) * (itemQuantities[amount] || 1);
455
  });
456
  document.getElementById('totalAmount').textContent = total.toFixed(2);
457
-
458
- // 更新二维码显示中的金额
459
- const qrAmountElement = document.getElementById('qrAmount');
460
- if (qrAmountElement) {
461
- qrAmountElement.textContent = total.toFixed(2);
462
- }
463
  }
464
 
465
- // 检测是否在微信内
466
- function isWechat() {
467
- const ua = navigator.userAgent.toLowerCase();
468
- return ua.indexOf('micromessenger') !== -1;
469
- }
470
-
471
- // 检测是否为移动设备
472
- function isMobile() {
473
- return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
474
  }
475
 
476
  // 处理支付
477
- function processPayment() {
478
  const overlay = document.getElementById('paymentOverlay');
479
  const loadingState = document.getElementById('loadingState');
480
- const qrState = document.getElementById('qrState');
481
- const wechatState = document.getElementById('wechatState');
482
 
 
483
  overlay.style.display = 'flex';
 
 
484
 
485
- // 获取当前金额
486
- const currentAmount = document.getElementById('totalAmount').textContent;
487
- document.getElementById('qrAmount').textContent = currentAmount;
488
-
489
- // 模拟加载过程
490
- setTimeout(() => {
491
- loadingState.style.display = 'none';
492
 
493
- if (isWechat()) {
494
- // 在微信内,尝试直接调用支付
495
- wechatState.style.display = 'block';
496
-
497
  // 尝试跳转到微信支付
498
- // 注意:wxp:// 协议通常只能在微信内部使用
499
  setTimeout(() => {
500
- try {
501
- window.location.href = CONFIG.wechatPayUrl;
502
- } catch (e) {
503
- console.error('无法调用微信支付:', e);
504
- // 如果失败,显示二维码
505
- wechatState.style.display = 'none';
506
- qrState.style.display = 'block';
507
- }
508
  }, 1000);
 
 
 
509
  } else {
510
- // 不在微信内,显示二维码
511
- qrState.style.display = 'block';
512
-
513
- // 如果有实际的二维码图片路径,替换占位符
514
- if (CONFIG.qrCodeImagePath && CONFIG.qrCodeImagePath !== 'your-qr-code.jpg') {
515
- document.getElementById('paymentQR').src = CONFIG.qrCodeImagePath;
516
- }
517
  }
518
- }, 1500);
 
 
 
 
 
519
  }
520
 
521
- // 确认支付完成
522
- function confirmPayment() {
523
- const overlay = document.getElementById('paymentOverlay');
524
- overlay.style.display = 'none';
525
-
526
- // 显示支付成功提示
527
- alert('感谢您的支付!如果支付遇到问题,请联系客服。');
528
-
529
- // 可以在这里添加支付成功后的处理逻辑
530
- // 例如:跳转到成功页面、发送支付记录等
531
  }
532
 
533
  // 取消支付
@@ -537,21 +527,13 @@
537
 
538
  // 重置显示状态
539
  document.getElementById('loadingState').style.display = 'block';
540
- document.getElementById('qrState').style.display = 'none';
541
- document.getElementById('wechatState').style.display = 'none';
542
  }
543
 
544
  function goBack() {
545
  window.history.back();
546
  }
547
 
548
- // 点击覆盖层外部区域关闭(仅在显示二维码时)
549
- document.getElementById('paymentOverlay').addEventListener('click', function(event) {
550
- if (event.target === this && document.getElementById('qrState').style.display === 'block') {
551
- cancelPayment();
552
- }
553
- });
554
-
555
  // 初始化页面
556
  updateTotalAmount();
557
  </script>
 
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
6
  <title>收款</title>
7
+ <!-- 引入二维码解析库 -->
8
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/jsQR/1.4.0/jsQR.js"></script>
9
  <style>
10
  * {
11
  margin: 0;
 
261
  transform: translateY(-1px);
262
  }
263
 
264
+ /* 隐藏的canvas用于二维码解析 */
265
+ #qrCanvas {
266
  display: none;
 
 
 
 
 
 
 
 
 
 
 
 
267
  }
268
 
269
+ /* 错误提示样式 */
270
+ .error-state {
271
+ display: none;
272
+ padding: 20px;
273
+ text-align: center;
274
  }
275
 
276
+ .error-icon {
277
+ font-size: 48px;
278
+ color: #f44336;
279
+ margin-bottom: 20px;
280
  }
281
 
282
  /* 响应式优化 */
 
356
  <!-- 支付处理覆盖层 -->
357
  <div class="payment-overlay" id="paymentOverlay">
358
  <div class="payment-processing">
359
+ <!-- 加载状态 -->
360
  <div id="loadingState">
361
  <div class="loading-spinner"></div>
362
  <div class="payment-message">正在处理支付请求...</div>
363
+ <div class="payment-submessage">系统正在识别支付方式</div>
364
  </div>
365
 
366
+ <!-- 错误状态 -->
367
+ <div id="errorState" class="error-state">
368
+ <div class="error-icon">⚠️</div>
369
+ <div class="payment-message">无法完成支付</div>
370
+ <div class="payment-submessage">请确保您已安装微信并重试</div>
 
 
 
 
 
 
371
  <div class="payment-actions">
372
+ <button class="action-button secondary" onclick="retryPayment()">重试</button>
 
 
 
 
 
 
 
 
 
373
  <button class="action-button secondary" onclick="cancelPayment()">取消</button>
374
  </div>
375
  </div>
376
  </div>
377
  </div>
378
 
379
+ <!-- 隐藏的元素用于二维码处理 -->
380
+ <canvas id="qrCanvas"></canvas>
381
+ <img id="hiddenQRImage" style="display: none;">
382
+
383
  <script>
384
  // 配置项
385
  const CONFIG = {
386
+ // 二维码图片文件名(与HTML同目录)
387
+ qrCodeImagePath: '微信图片_20250609201923.jpg'
 
 
388
  };
389
 
390
  let selectedItems = new Set();
 
432
  total += parseFloat(amount) * (itemQuantities[amount] || 1);
433
  });
434
  document.getElementById('totalAmount').textContent = total.toFixed(2);
 
 
 
 
 
 
435
  }
436
 
437
+ // 解析二维码图片
438
+ function decodeQRCode(imagePath) {
439
+ return new Promise((resolve, reject) => {
440
+ const img = document.getElementById('hiddenQRImage');
441
+ const canvas = document.getElementById('qrCanvas');
442
+ const ctx = canvas.getContext('2d');
443
+
444
+ img.onload = function() {
445
+ // 设置canvas尺寸
446
+ canvas.width = img.width;
447
+ canvas.height = img.height;
448
+
449
+ // 绘制图片到canvas
450
+ ctx.drawImage(img, 0, 0);
451
+
452
+ // 获取图像数据
453
+ const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
454
+
455
+ // 使用jsQR解析
456
+ const code = jsQR(imageData.data, imageData.width, imageData.height);
457
+
458
+ if (code) {
459
+ resolve(code.data);
460
+ } else {
461
+ reject(new Error('无法识别二维码'));
462
+ }
463
+ };
464
+
465
+ img.onerror = function() {
466
+ reject(new Error('无法加载二维码图片'));
467
+ };
468
+
469
+ // 设置图片源
470
+ img.src = imagePath;
471
+ });
472
  }
473
 
474
  // 处理支付
475
+ async function processPayment() {
476
  const overlay = document.getElementById('paymentOverlay');
477
  const loadingState = document.getElementById('loadingState');
478
+ const errorState = document.getElementById('errorState');
 
479
 
480
+ // 显示加载状态
481
  overlay.style.display = 'flex';
482
+ loadingState.style.display = 'block';
483
+ errorState.style.display = 'none';
484
 
485
+ try {
486
+ // 解析二维码
487
+ const qrData = await decodeQRCode(CONFIG.qrCodeImagePath);
488
+ console.log('二维码解析结果:', qrData);
 
 
 
489
 
490
+ // 检查是否为微信支付链接
491
+ if (qrData.startsWith('wxp://')) {
 
 
492
  // 尝试跳转到微信支付
 
493
  setTimeout(() => {
494
+ window.location.href = qrData;
495
+
496
+ // 设置超时检查
497
+ setTimeout(() => {
498
+ // 如果3秒后页面还在,说明跳转失败
499
+ loadingState.style.display = 'none';
500
+ errorState.style.display = 'block';
501
+ }, 3000);
502
  }, 1000);
503
+ } else if (qrData.includes('weixin://') || qrData.includes('https://wx.tenpay.com')) {
504
+ // 其他微信相关链接
505
+ window.location.href = qrData;
506
  } else {
507
+ // 不是微信支付链接
508
+ throw new Error('非微信支付二维码');
 
 
 
 
 
509
  }
510
+ } catch (error) {
511
+ console.error('处理支付时出错:', error);
512
+ // 显示错误状态
513
+ loadingState.style.display = 'none';
514
+ errorState.style.display = 'block';
515
+ }
516
  }
517
 
518
+ // 重试支付
519
+ function retryPayment() {
520
+ processPayment();
 
 
 
 
 
 
 
521
  }
522
 
523
  // 取消支付
 
527
 
528
  // 重置显示状态
529
  document.getElementById('loadingState').style.display = 'block';
530
+ document.getElementById('errorState').style.display = 'none';
 
531
  }
532
 
533
  function goBack() {
534
  window.history.back();
535
  }
536
 
 
 
 
 
 
 
 
537
  // 初始化页面
538
  updateTotalAmount();
539
  </script>