harryYao 2 years ago
commit
df11ef059d
2 changed files with 116 additions and 0 deletions
  1. 7 0
      readme.md
  2. 109 0
      wxpay.html

+ 7 - 0
readme.md

@@ -0,0 +1,7 @@
+# AI 降临派静态站点
+
+放一些中转页面,广告页面,支付页面等。
+
+
+1. wxpay.html
+   微信支付页面

+ 109 - 0
wxpay.html

@@ -0,0 +1,109 @@
+<!DOCTYPE html>
+<html lang="en">
+  <head>
+    <meta charset="UTF-8" />
+    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
+    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
+    <title>充值</title>
+    <style></style>
+  </head>
+  <body></body>
+  <script src="http://res2.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
+  <script>
+    let appId = ""; //公众号ID,由商户传入
+    let timeStamp = ""; //时间戳,自1970年以来的秒数
+    let nonceStr = ""; //随机串
+    let package = "";
+    let signType = ""; //微信签名方式:
+    let paySign = ""; //微信签名
+    if (location.search) {
+      ajax(
+        "https://api.huiyaohuyu.com/pay/getOrder" + location.search,
+        (res) => {
+          let data = JSON.parse(res).data.pay_info;
+          appId = data.appId;
+          timeStamp = data.timeStamp;
+          nonceStr = data.nonceStr;
+          package = data.package;
+          signType = data.signType;
+          paySign = data.paySign;
+          if (typeof WeixinJSBridge == "undefined") {
+            if (document.addEventListener) {
+              document.addEventListener(
+                "WeixinJSBridgeReady",
+                onBridgeReady,
+                false
+              );
+            } else if (document.attachEvent) {
+              document.attachEvent("WeixinJSBridgeReady", onBridgeReady);
+              document.attachEvent("onWeixinJSBridgeReady", onBridgeReady);
+            }
+          } else {
+            onBridgeReady();
+          }
+        }
+      );
+    }
+
+    function ajax(url, callback) {
+      let xhr = new XMLHttpRequest();
+      xhr.open("GET", url);
+      xhr.onreadystatechange = function () {
+        if (xhr.readyState == 4) {
+          if (xhr.status == 200 || xhr.status == 304) {
+            callback(xhr.responseText);
+          } else {
+            alert("支付失败");
+            closePage();
+          }
+        }
+      };
+      xhr.send();
+    }
+
+    function onBridgeReady() {
+      WeixinJSBridge.invoke(
+        "getBrandWCPayRequest",
+        {
+          appId: appId, //公众号ID,由商户传入
+          timeStamp: timeStamp, //时间戳,自1970年以来的秒数
+          nonceStr: nonceStr, //随机串
+          package: package,
+          signType: signType, //微信签名方式:
+          paySign: paySign, //微信签名
+        },
+        function (res) {
+          if (res.err_msg == "get_brand_wcpay_request:ok") {
+            // 使用以上方式判断前端返回,微信团队郑重提示:
+            //res.err_msg将在用户支付成功后返回ok,但并不保证它绝对可靠。
+            alert("支付成功");
+          }
+          closePage();
+        }
+      );
+    }
+
+    function closePage() {
+      var userAgent = navigator.userAgent;
+      if (
+        userAgent.indexOf("Firefox") != -1 ||
+        userAgent.indexOf("Chrome") != -1
+      ) {
+        // Firefox或Chrome中关闭
+
+        window.location.href = "about:blank";
+      } else {
+        window.opener = null;
+
+        window.open("", "_self");
+
+        window.close();
+      }
+
+      if (WeixinJSBridge) {
+        // 微信中关闭
+        wx.closeWindow();
+      }
+    }
+  </script>
+</html>