index.html 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  7. <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
  8. <title>Document</title>
  9. </head>
  10. <body>
  11. <div id="div">123</div>
  12. <button onclick="pay()">支付</button>
  13. </body>
  14. <script>
  15. const pay = async () => {
  16. WeixinJSBridge.invoke(
  17. 'getBrandWCPayRequest', {
  18. "appId":"wxb558057b16b95dd5",
  19. "timeStamp":"1525749068",
  20. "nonceStr":"LWm32hoWaAZ0zBZh",
  21. "package":"prepay_id=wx08111107238333432f16f39e3492244899",
  22. "signType":"MD5",
  23. "paySign":"347C9BB74842B310FFA6B5EE0B0E0AA1",
  24. "timestamp":"1525749068"
  25. },
  26. function(res){
  27. if(res.err_msg == "get_brand_wcpay_request:ok" ) {} // 使用以上方式判断前端返回,微信团队郑重提示:res.err_msg将在用户支付成功后返回 ok,但并不保证它绝对可靠。
  28. }
  29. );
  30. if (typeof WeixinJSBridge == "undefined"){
  31. if( document.addEventListener ){
  32. document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
  33. }else if (document.attachEvent){
  34. document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
  35. document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
  36. }
  37. }else{
  38. onBridgeReady();
  39. }
  40. }
  41. </script>
  42. </html>