index.html 4.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <!DOCTYPE html>
  2. <html lang="">
  3. <head>
  4. <meta charset="utf-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width,initial-scale=1.0">
  7. <link rel="icon" href="<%= BASE_URL %>favicon.ico">
  8. <title>
  9. <%= htmlWebpackPlugin.options.title %>
  10. </title>
  11. <!-- <script src="//cdn.jsdelivr.net/npm/eruda"></script>
  12. <script>
  13. eruda.init();
  14. </script> -->
  15. </head>
  16. <body>
  17. <noscript>
  18. <strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled.
  19. Please enable it to continue.</strong>
  20. </noscript>
  21. <div id="app"></div>
  22. <!-- built files will be auto injected -->
  23. <script>
  24. loadScript("http://res.wx.qq.com/open/js/jweixin-1.6.0.js?v=" + Date.now(), function () {
  25. fetch("https://import.smcic.net/weixin/share?url=" + encodeURIComponent(location.href.split("#")[0])).then(res => {
  26. return res.json()
  27. }).then(res => {
  28. let data = res || {};
  29. wx.config({
  30. debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
  31. appId: data.appid, // 必填,公众号的唯一标识
  32. timestamp: data.timestamp, // 必填,生成签名的时间戳
  33. nonceStr: data.nonceStr, // 必填,生成签名的随机串
  34. signature: data.signature, // 必填,签名
  35. jsApiList: [
  36. "updateAppMessageShareData",
  37. "updateTimelineShareData",
  38. "onMenuShareAppMessage",
  39. "onMenuShareTimeline",
  40. "onMenuShareQQ",
  41. "onMenuShareQZone",
  42. ], // 必填,需要使用的JS接口列表
  43. });
  44. wx.error(function (err) {
  45. console.log("err=>", err.errMsg);
  46. });
  47. wx.ready(function (res) {
  48. let title = "许个心愿吧 万一成真了呢"
  49. document.title = title
  50. //需在用户可能点击分享按钮前就先调用
  51. wx.updateAppMessageShareData({
  52. title: title, // 分享标题
  53. desc: "你负责建设美好 我负责实现愿望", // 分享描述
  54. link: location.href.split("?")[0] + "?v=" + Date.now(), // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
  55. imgUrl: "https://djweb.smcic.net/wish/shanjian1.jpg", // 分享图标
  56. });
  57. wx.updateTimelineShareData({
  58. title: title, // 分享标题
  59. link: location.href.split("?")[0] + "?v=" + Date.now(), // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
  60. imgUrl: "https://djweb.smcic.net/wish/shanjian1.jpg", // 分享图标
  61. });
  62. });
  63. })
  64. });
  65. // 创建script标签
  66. function loadScript(url, callback) {
  67. let script = document.createElement("script");
  68. if (script.readyState) {
  69. // IE
  70. script.onreadystatechange = function () {
  71. if (
  72. script.readyState === "loaded" ||
  73. script.readyState === "complete"
  74. ) {
  75. script.onreadystatechange = null;
  76. callback();
  77. }
  78. };
  79. } else {
  80. // 其他浏览器
  81. script.onload = function () {
  82. callback();
  83. };
  84. }
  85. script.src = url;
  86. document.getElementsByTagName("head")[0].appendChild(script);
  87. }
  88. </script>
  89. </body>
  90. </html>