wjx 1 year ago
parent
commit
2d6afeb257
2 changed files with 18 additions and 3 deletions
  1. 1 0
      index.html
  2. 17 3
      index.js

+ 1 - 0
index.html

@@ -27,6 +27,7 @@
         </div>
 
         <div class="payBtn" onclick="onBridgeReady()">点击支付</div>
+        <div class="back backNoPay" style="display: none;" onclick="closeHandle()">返回游戏</div>
     </div>
     <div id="tip">
         <div class="content">

+ 17 - 3
index.js

@@ -1,14 +1,20 @@
 const api = 'https://game.84game.cn/sdk'  // 请求地址
 let payParam = ''; appId="";  // 支付参数
 let wechatPayId = "";
+let query = {}
 
 // 关闭
 const closeHandle = () => {
     console.log('关闭')
-    document.addEventListener('WeixinJSBridgeReady', () => {
+    if (query.isGame) {
+        history.go(-2);
+    } else {
+        document.addEventListener('WeixinJSBridgeReady', () => {
+            WeixinJSBridge.call('closeWindow');
+        }, false);
         WeixinJSBridge.call('closeWindow');
-    }, false);
-    WeixinJSBridge.call('closeWindow');
+    }
+    
 }
 
 // 支付
@@ -30,6 +36,9 @@ const onBridgeReady = () => {
                 // closeHandle()
                 // window.location.href = window.location.origin + "/html/wechatPay/paySucc.html";
                 document.getElementById('succ').style.display = 'block'
+                if (query.isGame) {
+                    document.querySelector('.back').innerText = '返回游戏'
+                }
             } else if (res.err_msg == "get_brand_wcpay_request:fail") {
                 document.getElementById('tip').style.display = 'block'
                 document.getElementsByClassName('tipTitle')[0].innerHTML = '该订单已失效,请回复“2”或游戏内重新下单获取最新支付订单';
@@ -52,6 +61,11 @@ window.onload = () => {
         let arr = s.split('=')
         obj[arr[0]] = arr[1]
     })
+    query = obj
+    if (obj.isGame) {
+        document.querySelector('.back').innerText = '返回游戏'
+        document.querySelector('.backNoPay').style.display = 'block'
+    }
     document.getElementById('money').innerHTML = (obj.amount || '8') + '元'
     document.getElementById('title').innerHTML = decodeURIComponent(obj.description) || '购买8元档充值'
     document.getElementById('orderNo').innerHTML = '订单号:' + (obj.orderId || '2023010711541555400125675')