H5活动页、中间页、临时广告页面等

moment_share.html 8.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. <!DOCTYPE html>
  2. <html lang="zh" style="font-size: 365.867px;">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  5. <meta content="yes" name="apple-mobile-web-app-capable">
  6. <meta name="viewport"
  7. content="width=device-width, initial-scale=1.0, maximum-scale=1.0,minimum-scale=1.0,user-scalable=0">
  8. <meta http-equiv="X-UA-Compatible" content="IE=8">
  9. <meta http-equiv="Expires" content="0">
  10. <meta http-equiv="Pragma" content="no-cache">
  11. <meta http-equiv="Cache-control" content="no-cache">
  12. <meta http-equiv="Cache" content="no-cache">
  13. <link rel="stylesheet" type="text/css" href="./static/public_css.css">
  14. <script type="text/javascript" src="./static/public.js"></script>
  15. <script type="text/javascript" src="./static/nanoid.js"></script>
  16. <script type="text/javascript" src="./static/jquery-2.1.0.js"></script>
  17. <!-- <script src="https://cdn.bootcdn.net/ajax/libs/vue/2.7.9/vue.js"></script> -->
  18. <script src="https://cdn.bootcdn.net/ajax/libs/vue/2.7.9/vue.min.js"></script>
  19. <script src="http://res.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
  20. <title></title>
  21. <style>
  22. .container {
  23. background-color: #000;
  24. min-height: 100vh;
  25. box-sizing: border-box;
  26. position: relative;
  27. }
  28. .container .tips-wrap {
  29. position: fixed;
  30. bottom: 50vh;
  31. width: 100%;
  32. z-index: 100;
  33. display: flex;
  34. justify-content: center;
  35. align-items: center;
  36. }
  37. .container .tips-wrap .tips {
  38. background-color: rgba(40, 40, 40, 0.8);
  39. color: aliceblue;
  40. font-size: 0.13rem;
  41. padding: 0.1rem;
  42. border-radius: 0.08rem;
  43. }
  44. .container .video-wrap {
  45. width: 100%;
  46. height: 100vh;
  47. display: flex;
  48. align-items: center;
  49. justify-content: center;
  50. }
  51. </style>
  52. </head>
  53. <body>
  54. <div id="app" class="container">
  55. <!-- S toast提示语 -->
  56. <div class="tips-wrap" v-show="isShowMsg">
  57. <span class="tips">{{ msg }}</span>
  58. </div>
  59. <!-- E toast提示语 -->
  60. <div class="video-wrap">
  61. <video v-if="videoUrl" ref="videoRef" x5-playsinline="true" playsinline="true" webkit-playsinline="true"
  62. x-webkit-airplay="true" x5-video-orientation="portraint" :src="videoUrl" muted autoplay controls
  63. controlslist="nodownload" style="width:100%;height:auto;object-fit: fill;">
  64. </video>
  65. </div>
  66. </div>
  67. <script>
  68. var app = new Vue({
  69. el: '#app',
  70. data() {
  71. return {
  72. isShowMsg: false,
  73. msg: '',
  74. videoUrl: '',
  75. shareInfo: {
  76. title: '',
  77. link: '',
  78. desc: '',
  79. imgUrl: '',
  80. },
  81. }
  82. },
  83. watch: {
  84. isShowMsg(isShow) {
  85. if (isShow) {
  86. setTimeout(() => {
  87. this.isShowMsg = false;
  88. }, 2000);
  89. }
  90. },
  91. },
  92. mounted() {
  93. console.log('mounted => ',)
  94. this.handleSetSign()
  95. },
  96. methods: {
  97. handleSetSign() {
  98. const _this = this
  99. $.ajax({
  100. url: "http://tbkadmin.wenxingshuju.com/getSignPackage",
  101. type: "GET",
  102. dataType: 'json',
  103. data: {},
  104. success: (res) => {
  105. console.log('res => ', res)
  106. wx.config({
  107. debug: false,// 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。true为调用开启
  108. appId: res.appId,//appid// 必填,公众号的唯一标识
  109. timestamp: res.timestamp, // 必填,生成签名的时间戳
  110. nonceStr: res.nonceStr,// 必填,生成签名的随机串
  111. signature: res.signature,// 必填,签名,
  112. jsApiList: [
  113. 'updateAppMessageShareData',//朋友圈
  114. 'updateTimelineShareData',//微信朋友
  115. ]
  116. });
  117. _this.handleGetPageInfo()
  118. },
  119. error: (err) => {
  120. console.log('err => ', err)
  121. }
  122. });
  123. },
  124. handleGetPageInfo() {
  125. const _this = this
  126. $.ajax({
  127. url: "http://tbkadmin.wenxingshuju.com/getShareContent",
  128. type: "GET",
  129. dataType: 'json',
  130. data: {},
  131. success: (res) => {
  132. console.log('res => ', res)
  133. _this.videoUrl = res.videoUrl
  134. _this.shareInfo.title = res.title
  135. _this.shareInfo.link = res.link
  136. _this.shareInfo.desc = res.desc
  137. _this.shareInfo.imgUrl = res.imgUrl
  138. _this.handleSetPageTitle(res.title)
  139. _this.handleSetWxShare()
  140. },
  141. error: (err) => {
  142. console.log('err => ', err)
  143. }
  144. });
  145. },
  146. handleSetWxShare() {
  147. const { title, link, desc, imgUrl } = this.shareInfo
  148. const _this = this
  149. wx.ready(function () {
  150. // 分享到朋友圈
  151. wx.updateTimelineShareData({
  152. title: title, // 分享标题
  153. link: link, // 分享链接
  154. desc: desc, // 分享描述
  155. imgUrl: imgUrl, // 分享图标的URL
  156. success: function () {
  157. // 设置成功
  158. console.log('分享到朋友圈成功 => title ', title);
  159. console.log('分享到朋友圈成功 => link ', link);
  160. console.log('分享到朋友圈成功 => desc ', desc);
  161. console.log('分享到朋友圈成功 => imgUrl ', imgUrl);
  162. },
  163. cancel: function (err) {
  164. // 设置失败
  165. console.log('分享到朋友圈失败');
  166. _this.handleShowToastMsg(err)
  167. }
  168. });
  169. // 分享给朋友
  170. wx.updateAppMessageShareData({
  171. title: title, // 分享标题
  172. desc: desc, // 分享描述
  173. link: link, // 分享链接
  174. imgUrl: imgUrl, // 分享图标的URL
  175. success: function () {
  176. // 设置成功
  177. console.log('分享给朋友成功 => title ', title);
  178. console.log('分享给朋友成功 => desc ', desc);
  179. console.log('分享给朋友成功 => link ', link);
  180. console.log('分享给朋友成功 => imgUrl ', imgUrl);
  181. },
  182. cancel: function (err) {
  183. // 设置失败
  184. console.log('分享给朋友失败');
  185. _this.handleShowToastMsg(err)
  186. }
  187. });
  188. });
  189. wx.error(function (error) {
  190. // config信息验证失败会执行error函数,如签名过期导致验证失败,具体错误信息可以打开config的debug模式查看,也可以在返回的res参数中查看,对于SPA可以在这里更新签名
  191. console.log("wx.error", error);
  192. });
  193. },
  194. // toast提示
  195. handleShowToastMsg(msg) {
  196. this.msg = msg
  197. this.isShowMsg = true
  198. },
  199. // 设置title
  200. handleSetPageTitle(title) {
  201. document.title = title
  202. },
  203. doPlay() {
  204. try {
  205. const _this = this
  206. WeixinJSBridge.invoke("getNetworkType", {}, function (e) {
  207. const videoHtml = _this.$refs.videoRef
  208. videoHtml.play();
  209. });
  210. } catch (error) {
  211. console.log(error)
  212. }
  213. },
  214. handleSetIosAutoPlay() {
  215. try {
  216. if (WeixinJSBridge) {
  217. doPlay();
  218. } else {
  219. document.addEventListener(
  220. "WeixinJSBridgeReady",
  221. function () {
  222. doPlay();
  223. },
  224. false
  225. );
  226. }
  227. } catch (error) {
  228. console.log(error)
  229. }
  230. },
  231. handleSetAndroidAutoPlay() {
  232. const ua = navigator.userAgent;
  233. const isAndroid = ua.indexOf("Android") > -1 || ua.indexOf("Linux") > -1;
  234. const isWeixin = ua.indexOf("MicroMessenger") > 0;
  235. const _this = this
  236. if (isAndroid && isWeixin) {
  237. document.addEventListener(
  238. "touchstart",
  239. function () {
  240. const videoHtml = _this.$refs.videoRef
  241. videoHtml.play();
  242. },
  243. false
  244. );
  245. }
  246. },
  247. },
  248. })
  249. </script>
  250. </body>
  251. </html>