WXtrialInterface.html 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title></title>
  6. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  7. <meta name="x5-orientation" content="portrait" />
  8. <meta name="screen-orientation" content="portrait" />
  9. <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
  10. <meta name="apple-mobile-web-app-capable" content="yes">
  11. <!-- 删除苹果默认的工具栏和菜单栏 -->
  12. <meta name="apple-mobile-web-app-status-bar-style" content="black">
  13. <!-- 设置苹果工具栏颜? -->
  14. <meta name="format-detection" content="telphone=no, email=no">
  15. <!-- 忽略页面中的数字识别为电话,忽略email识别 -->
  16. <!-- 启用360浏览器的极速模?(webkit) -->
  17. <meta name="renderer" content="webkit">
  18. <!-- 针对手持设备优化,主要是针对一些老的不识别viewport的浏览器,比如黑? -->
  19. <meta name="HandheldFriendly" content="true">
  20. <!-- 微软的老式浏览? -->
  21. <meta name="MobileOptimized" content="320">
  22. <!-- 不能旋转,问题出在这 -->
  23. <!-- UC强制全屏 -->
  24. <meta name="full-screen" content="yes">
  25. <!-- QQ强制全屏 -->
  26. <meta name="x5-fullscreen" content="true">
  27. <!-- UC应用模式 -->
  28. <meta name="browsermode" content="application">
  29. <!-- QQ应用模式 -->
  30. <meta name="x5-page-mode" content="app">
  31. <!-- windows phone 点击无高? -->
  32. <meta name="msapplication-tap-highlight" content="no">
  33. <link rel="stylesheet" type="text/css" href="css/WXtrialInterface.css" />
  34. <link rel="stylesheet" href="https://cdn.bootcss.com/weui/1.1.3/style/weui.min.css" />
  35. <link rel="stylesheet" href="https://cdn.bootcss.com/jquery-weui/1.2.1/css/jquery-weui.min.css" />
  36. <style>
  37. .try-use-wrap, .buy-phone-wrap, .look-wrap{
  38. width: 100%;
  39. height: 100%;
  40. position: fixed;
  41. top: 0;
  42. left: 0;
  43. z-index: 9999;
  44. background: rgba(0, 0, 0, 0.5);
  45. display: none;
  46. }
  47. .try-use-container {
  48. width: 80%;
  49. height: 409px;
  50. position: absolute;
  51. top: 50%;
  52. left: 50%;
  53. transform: translate(-50%, -50%);
  54. background-color: #FFFFFF;
  55. border-radius: 0.66em;
  56. }
  57. .time-close-wrap {
  58. width: 5.46em;
  59. height: 2em;
  60. line-height: 2em;
  61. text-align: center;
  62. position: absolute;
  63. top: 0.24em;
  64. right: 0.3em;
  65. background: rgba(0, 0, 0, 0.49);
  66. border-radius: 1.26em;
  67. font-size: 12px;
  68. color: #FFFFFF;
  69. }
  70. .bug-wrap {
  71. width: 90%;
  72. height: 115px;
  73. background: #FFFFFF;
  74. border-radius: 10px;
  75. position: absolute;
  76. top: 50%;
  77. left: 50%;
  78. transform: translate(-50%, -50%);
  79. }
  80. .bug-title {
  81. text-align: center;
  82. margin: 25px 0;
  83. font-size: 18px;
  84. font-weight: 600;
  85. color: #333333;
  86. }
  87. .btn-list {
  88. width: 100%;
  89. height: 44px;
  90. line-height: 44px;
  91. border-top: 1px solid rgba(238, 238, 238, 1);
  92. position: absolute;
  93. bottom: 0;
  94. left: 0;
  95. display: flex;
  96. align-items: center;
  97. }
  98. .btn {
  99. flex: 1;
  100. text-align: center;
  101. }
  102. .cannel-btn {
  103. font-size: 18px;
  104. color: #666666;
  105. }
  106. .go-bug {
  107. font-size: 18px;
  108. color: #3B7FFF;
  109. border-left: 1px solid rgba(238, 238, 238, 1);
  110. }
  111. </style>
  112. </head>
  113. <body class="scroll h-player" style="overscroll-behavior: contain;">
  114. <div class="container" id="player">
  115. <div class="muted" id="btnMuted">
  116. <div class="control-right-img" data-id="1">
  117. <img src="../static/img/xuanfu_icon.png">
  118. </div>
  119. </div>
  120. <div id="wine">
  121. <video id="playerVideo" muted="muted" x5-video-orientation="landscape" playsinline="true" autoplay="true"
  122. webkit-playsinline="true" x5-playsinline="true" x5-video-player-type="h5" x5-video-player-fullscreen="false"
  123. style="pointer-events: none;object-fit: fill;width: 100%;height:100%"></video>
  124. <div id="box"></div>
  125. <audio preload="auto" autoplay controls poster="images/loader-thumb.jpg" id="audioPlayer"
  126. style="position: absolute;top: 0;width: 0;height: 0;"></audio>
  127. </div>
  128. <div class="leftmains">
  129. <div class="PictureQualityMain">
  130. <div class="PictureQuality" data-id="4">高清</div>
  131. <div class="PictureQuality avit" data-id="3">标清</div>
  132. <div class="PictureQuality" data-id="2">极速</div>
  133. </div>
  134. <div class="operation">
  135. <div class="upload" id="showsuss" data-text="uploads">
  136. <img src="../static/img/wx/shangchuan_icon.png">
  137. <div>上传</div>
  138. </div>
  139. <div class="upload" onclick="showShearPlate()" data-text="Shearplate">
  140. <img src="../static/img/wx/jianqieban_icon.png">
  141. <div>剪贴板</div>
  142. </div>
  143. <div class="upload" id="upload" data-text="Signout">
  144. <img src="../static/img/wx/tuichu_icon.png">
  145. <div>退出</div>
  146. </div>
  147. </div>
  148. </div>
  149. <div class="bottommains">
  150. <div class="botmat1">
  151. <div class="botmat1img" data-text="gengduo">
  152. <img src="../static/img/wx/gengduo_icon.png">
  153. </div>
  154. </div>
  155. <div class="botmat1">
  156. <div class="botmat1img" data-text="home">
  157. <img src="../static/img/wx/home_icon.png">
  158. </div>
  159. </div>
  160. <div class="botmat1">
  161. <div class="botmat1img" data-text="return">
  162. <img src="../static/img/wx/fanhui_icon.png">
  163. </div>
  164. </div>
  165. </div>
  166. <img class="loading loading_sceen_pic" />
  167. </div>
  168. <div class="mask">
  169. <div class="box-shear-plate"></div>
  170. <img class="close" onclick="handleClose()" src="img/guanbi_icon@2x.png" alt="">
  171. </div>
  172. <div class="weui-mask_transparent"></div>
  173. <div class="weui-toast weui_loading_toast weui-toast--visible">
  174. <div class="weui_loading"><i class="weui-loading weui-icon_toast"></i></div>
  175. <p class="weui-toast_content">数据加载中</p>
  176. </div>
  177. <div class="try-use-wrap">
  178. <div class="try-use-container">
  179. <video width="100%" height="100%" id="source" muted autoplay="autoplay" loop="loop">
  180. 您的浏览器不支持 video 标签。
  181. </video>
  182. <div class="time-close-wrap"><span class="time-node"></span> 关闭</div>
  183. </div>
  184. </div>
  185. <div class="buy-phone-wrap">
  186. <div class="bug-wrap">
  187. <div class="bug-title">获得极致体验服务请购买云手机</div>
  188. <div class="btn-list">
  189. <div class="btn cannel-btn">取消</div>
  190. <div class="btn go-bug">去购买</div>
  191. </div>
  192. </div>
  193. </div>
  194. <div class="look-wrap">
  195. <div class="bug-wrap">
  196. <div class="bug-title">关闭广告会退出云手机是否继续观看</div>
  197. <div class="btn-list">
  198. <div class="btn cannel-btn cannel-ad-btn">放弃</div>
  199. <div class="btn go-bug looking">继续观看</div>
  200. </div>
  201. </div>
  202. </div>
  203. <body oncontextmenu="Back()">
  204. </body>
  205. <script type="text/javascript" src="https://res.wx.qq.com/open/js/jweixin-1.3.2.js"></script>
  206. <script src="https://lf1-cdn-tos.bytegoofy.com/goofy/developer/jssdk/jssdk-1.0.3.js"></script>
  207. <script type="text/javascript" src="../static/js/jquery-1.11.0.min.js"></script>
  208. <script type="text/javascript" src="helper.js"></script>
  209. <script type="text/javascript" src="pcm-player.js"></script>
  210. <script type="text/javascript" src="https://cdn.bootcss.com/vConsole/3.2.0/vconsole.min.js"></script>
  211. <script src="https://cdn.bootcss.com/jquery-weui/1.2.1/js/jquery-weui.min.js"></script>
  212. <script type="text/javascript" src="WXdraw.js"></script>
  213. <script type="text/javascript" src="jmuxer.js"></script>
  214. <script type="text/javascript" src="spsParser.js"></script>
  215. <script>
  216. var url = window.location.href;
  217. url = url.split('/');
  218. var baseUrl = url[0] + '//' + url[2];
  219. var parameters = GetRequest();
  220. var form = {};
  221. form.token = parameters['token'];
  222. form.userCardId = parameters['userCardId'];
  223. var videoTimer = null, videoTime = 0, adType = 0, sourceType = 0, disconnectionFlag = false, getDate = false;
  224. if (parameters['mealType'] === 'VIP') {
  225. $(".loading_sceen_pic").attr('src', '../static/img/home_bg_VIP.png');
  226. } else if (parameters['mealType'] === 'SVIP') {
  227. $(".loading_sceen_pic").attr('src', '../static/img/home_bg_SVIP.png');
  228. } else if (parameters['mealType'] === 'STAR') {
  229. $(".loading_sceen_pic").attr('src', '../static/img/home_bg_STAR.png');
  230. } else if (parameters['mealType'] === 'STARPRO') {
  231. $(".loading_sceen_pic").attr('src', '../static/img/home_bg_PRO.png');
  232. }
  233. adInit();
  234. var isAudioPlay = false;
  235. if (navigator.userAgent.toLowerCase().includes('toutiaomicroapp')) {
  236. var video = document.getElementById("playerVideo");
  237. video.play();
  238. setTimeout(() => { // 抖音环境需要设置延时,不然会有video默认图显示
  239. $.alert({
  240. title: '提示',
  241. text: '开始使用云手机',
  242. onOK: function () {
  243. setTimeout(() => {
  244. isAudioPlay = true;
  245. }, 1000);
  246. }
  247. });
  248. }, 1000)
  249. } else {
  250. $.alert({
  251. title: '提示',
  252. text: '开始使用云手机',
  253. onOK: function () {
  254. var video = document.getElementById("playerVideo");
  255. video.play();
  256. isAudioPlay = true;
  257. }
  258. });
  259. }
  260. //云机倒计时
  261. let validTime = parameters['validTime'] || 10000;
  262. if (validTime > 32000) {
  263. validTime = 32000
  264. }
  265. let detailTime = validTime * 60 * 1000;
  266. setTimeout(() => {
  267. $('.bug-title').eq(0).text('尊敬的用户您的云手机试用时间已到期');
  268. getDate = true;
  269. $('.buy-phone-wrap').eq(0).show();
  270. }, detailTime)
  271. var topwinHeight = window.screen.height - window.innerHeight + 30; //计算title top 头部
  272. $('#wine').css({
  273. "width": window.screen.width,
  274. "height": window.screen.height - topwinHeight - 20,
  275. "position": "absolute"
  276. });
  277. $('.loading').css({
  278. "width": window.screen.width,
  279. "height": window.screen.height - topwinHeight - 20
  280. });
  281. var winese = document.createElement("wine");
  282. wine.style.top = "-" + winese + 'px';
  283. var isVisuable = true;
  284. var isFeed = true;
  285. var isFinish = false;
  286. var isWaitSps = false;
  287. var myVideo = document.getElementById("playerVideo");
  288. Module = {};
  289. Module.onRuntimeInitialized = function () {
  290. isFinish = true;
  291. }
  292. var isWSS = true;
  293. var ip = parameters["ip"];
  294. var cardToken = parameters["cardToken"];
  295. cardToken = cardToken && decodeURIComponent(cardToken);
  296. var appletPushAddress = parameters["appletPushAddress"];
  297. var socketURL = isWSS ? "wss://" + appletPushAddress + "?cardIp=" + ip + "&token=" + cardToken + "&type=business" : "ws://" + appletPushAddress + "?cardIp=" + ip + "&token=" + cardToken;
  298. var jmuxer = new JMuxer({
  299. node: 'playerVideo',
  300. flushingTime: 33,
  301. fps: 30,
  302. mode: 'video',
  303. debug: false
  304. });
  305. window.onload = function () {
  306. var myPlay = document.getElementById("wine");
  307. myPlay.onkeydown = function (event) {
  308. ExexuteKeyDown(e.keyCode);
  309. }
  310. }
  311. var ws, errorTime = 0;
  312. doConnect();
  313. // 节流
  314. // 设置一个标志
  315. function throttle(fn, delay) {
  316. let flag = true;
  317. errorTime += delay;
  318. return () => {
  319. if (!flag) return;
  320. flag = false;
  321. timer = setTimeout(() => {
  322. fn();
  323. flag = true;
  324. }, delay);
  325. };
  326. }
  327. var intervaler;
  328. function doConnect() {
  329. ws = new WebSocket(socketURL);
  330. ws.binaryType = 'arraybuffer';
  331. intervaler = setInterval(() => {
  332. if (ws.readyState === 1) {
  333. ws.send("ping");
  334. } else {
  335. clearInterval(intervaler);
  336. $.toast("画面异常,请重新进入", "text");
  337. if (navigator.userAgent.toLowerCase().includes('toutiaomicroapp')) {
  338. tt.miniProgram.switchTab({
  339. url: '/pages/home/home'
  340. })
  341. } else {
  342. wx.miniProgram.switchTab({
  343. url: '/pages/home/home'
  344. })
  345. }
  346. }
  347. }, 3000);
  348. ws.addEventListener('open', function (event) {
  349. // sn只要长度满足17位随机数,不需要从后台获取
  350. var verifyBuffer = VerifyCode('RK3923C1201900139', cardToken);
  351. console.log("鉴权报文:" + PrintArry(verifyBuffer));
  352. ws.send(verifyBuffer);
  353. });
  354. ws.addEventListener('error', function (event) {
  355. ws.close();
  356. clearInterval(intervaler);
  357. throttle(doConnect, 100);
  358. if (errorTime > 1000) {
  359. $.toast("画面异常,请重新进入", "text");
  360. wsss.close();
  361. if (navigator.userAgent.toLowerCase().includes('toutiaomicroapp')) {
  362. tt.miniProgram.switchTab({
  363. url: '/pages/home/home'
  364. })
  365. } else {
  366. wx.miniProgram.switchTab({
  367. url: '/pages/home/home'
  368. })
  369. }
  370. }
  371. });
  372. ws.addEventListener('message', function (event) {
  373. var data = ParseProto(event.data); //JAVA服务器转发
  374. if (isAudioPlay) {
  375. $('.weui-mask_transparent').hide();
  376. $('.weui-toast').hide();
  377. $('.loading').hide();
  378. }
  379. var input = new Uint8Array(event.data);
  380. if (data.audio != null && isAudioPlay) { //喂音频
  381. if (input[0] == 0xff) {
  382. if (isFinish) {
  383. decodeAAC(input);
  384. }
  385. }
  386. }
  387. if (data.frameType != undefined && data.frameType != 1 && data.frameType != 6) {
  388. if (data.frameType == 7) {
  389. let info = spsParser(data.video);
  390. if (info.width != myVideo.videoWidth && info.height != myVideo.videoHeight) {
  391. if (myVideo.videoWidth == 0) {
  392. console.log("SPS计算得到宽 %d, 高 %d, 控件宽 %d, %d", info.width, info.height, myVideo.videoWidth, myVideo.videoHeight);
  393. }
  394. }
  395. }
  396. }
  397. if (data.video != null) { //喂视频
  398. if (data.frameType == 0x05 && isVisuable) {
  399. isFeed = true;
  400. }
  401. if (data.frameType == 7 || data.frameType == 8) {
  402. isFeed = true;
  403. isAudioPlay = true;
  404. isWaitSps = false;
  405. }
  406. if (isFeed) {
  407. if (!isWaitSps) {
  408. jmuxer.feed(data);
  409. }
  410. }
  411. }
  412. });
  413. }
  414. var hidden, visibilityChange;
  415. if (typeof document.hidden !== "undefined") { // Opera 12.10 and Firefox 18 and later support
  416. hidden = "hidden";
  417. visibilityChange = "visibilitychange";
  418. } else if (typeof document.msHidden !== "undefined") {
  419. hidden = "msHidden";
  420. visibilityChange = "msvisibilitychange";
  421. } else if (typeof document.webkitHidden !== "undefined") {
  422. hidden = "webkitHidden";
  423. visibilityChange = "webkitvisibilitychange";
  424. }
  425. // 处理页面可见属性的改变
  426. document.addEventListener("visibilitychange", function () {
  427. if (document[hidden]) {
  428. if (navigator.userAgent.toLowerCase().includes('toutiaomicroapp')) {
  429. tt.miniProgram.switchTab({
  430. url: '/pages/home/home'
  431. })
  432. } else if (window.__wxjs_environment === 'miniprogram') {
  433. wx.miniProgram.switchTab({
  434. url: '/pages/home/home'
  435. })
  436. } else {
  437. document.addEventListener('UniAppJSBridgeReady', function () {
  438. uni.navigateTo({
  439. url: '/pages/index/index'
  440. });
  441. })
  442. }
  443. }
  444. }, false);
  445. myVideo.addEventListener('pause', function () {
  446. isFeed = false;
  447. });
  448. var decodeCount = 1;
  449. var player = new PCMPlayer({
  450. encoding: '16bitInt',
  451. channels: 2,
  452. sampleRate: 44100,
  453. flushingTime: 22,
  454. debug: false
  455. });
  456. function handleClose() {
  457. $('.mask').hide();
  458. }
  459. function decodeAAC(data) {
  460. var retPtr = Module._malloc(4 * 5 * 1024); // 接收的数据
  461. var inputPtr = Module._malloc(4 * data.length); // 输入数据
  462. for (var i = 0; i < data.length; i++) {
  463. Module.HEAPU8[(inputPtr) + i] = data[i]; //转换为堆数据
  464. }
  465. var pcmLen = Module._feedData(retPtr, inputPtr, data.length);
  466. if (pcmLen >= 0) {
  467. var pcmData = new Uint8Array(pcmLen);
  468. for (var i = 0; i < pcmLen; i++) {
  469. pcmData[i] = Module.HEAPU8[(retPtr) + i]
  470. }
  471. player.feed(pcmData);
  472. }
  473. decodeCount++;
  474. Module._free(inputPtr);
  475. Module._free(retPtr);
  476. }
  477. //解协议
  478. function ParseProto(data) {
  479. var input = new Uint8Array(data),
  480. duration,
  481. video,
  482. frameType,
  483. audio;
  484. if (input[0] == 0 && input[1] == 0 && input[2] == 0 && input[3] == 1) {
  485. video = input;
  486. duration = 24;
  487. var nalType = input[4] & 0x1f;
  488. frameType = nalType;
  489. if (!isFeed) {
  490. if (nalType == 0x05 && isVisuable) {
  491. isFeed = true;
  492. }
  493. }
  494. } else if (input[0] == 0xff) {
  495. audio = input;
  496. duration = 24;
  497. } else if (input[0] == 0x68) {
  498. if (input[23] == 0x5c) {
  499. console.log("收到消息:" + PrintArry(input));
  500. if (CheckVerifyCode(input)) {
  501. ws.send(ConfigChannel('RK3923C1201900139'));
  502. var checkBuffer = GetScreenState();
  503. ws.send(checkBuffer);
  504. }
  505. else {
  506. $.toast("画面异常,请重新进入", "text");
  507. clearInterval(intervaler);
  508. ws.close();
  509. wsss.close();
  510. if (navigator.userAgent.toLowerCase().includes('toutiaomicroapp')) {
  511. tt.miniProgram.switchTab({
  512. url: '/pages/home/home'
  513. })
  514. } else {
  515. wx.miniProgram.switchTab({
  516. url: '/pages/home/home'
  517. })
  518. }
  519. }
  520. }
  521. if (input[23] == 0x05) { //横竖屏标识
  522. var state = CheckScreenDirection(input.slice(24, 24 + 8));
  523. if (state == 1) {
  524. console.log("安卓卡此时竖屏");
  525. //竖屏处理
  526. resolving = 1;
  527. } else {
  528. console.log("安卓卡此时横屏");
  529. //横屏处理
  530. resolving = 0;
  531. }
  532. }
  533. if (input[23] == 0x0B)//多端登录处理, 数据从索引24开始取, input 是接收到的原始数据
  534. {
  535. var jsonobj = checkMultiLoginInfo(input);
  536. }
  537. }
  538. return {
  539. audio: audio,
  540. video: video,
  541. duration: duration,
  542. frameType: frameType
  543. };
  544. }
  545. function GetRequest() {
  546. var url = location.search; // 获取url中"?"符后的字串
  547. var obj = new Object();
  548. if (url.indexOf("?") != -1) {
  549. var str = url.substr(1);
  550. strs = str.split("&");
  551. for (var i = 0; i < strs.length; i++) {
  552. obj[strs[i].split("=")[0]] = (strs[i].split("=")[1]);
  553. }
  554. }
  555. return obj;
  556. }
  557. function Back() {
  558. ExexuteKeyDown(4);
  559. window.event.returnValue = false;
  560. return false;
  561. }
  562. var form = {};
  563. form.token = parameters['token'];
  564. form.userCardId = parameters['userCardId'];
  565. function array_unique(arr) {
  566. return arr.filter(function (e, i) {
  567. return arr.indexOf(e) === i;
  568. })
  569. }
  570. var cutList = [];
  571. let timer, isFlag = true;
  572. function showShearPlate() {
  573. if (!isControl) {
  574. return
  575. }
  576. stopManyClick(() => {
  577. $('.box-shear-plate').empty();
  578. $.ajax({
  579. url: baseUrl + "/api/public/v5/shear/content",
  580. headers: {
  581. 'Authorization': form.token
  582. },
  583. type: 'get',
  584. dataType: 'json',
  585. success: function (res) {
  586. if (res.status === 0) {
  587. if (res.data.length) {
  588. cutList = array_unique(res.data)
  589. var str = '<div class="title">剪贴板<div onclick="handleClear()" class="btn-clear">清空</div></div><div class="slide-wrapper-content">'
  590. cutList.forEach(function (item) {
  591. str += "<div class='slide-wrapper'><div class='slide-scroll animate-slide-start'><div class='slide-content'><div onclick='handleCopy(\"" + item.content + "\")'>" + item.content + "</div></div><div class='slide-content-button'><button onclick='handleDelete(" + item.id + ")'>删除</button></div></div></div>"
  592. })
  593. str += '</div>'
  594. $('.box-shear-plate').append(str);
  595. } else {
  596. $('.box-shear-plate').append('<img class="empty" src="img/jianqieban_pic@2x.png" alt="" /><div class="empty-txt">剪贴板为空</div>')
  597. }
  598. $('.mask').show();
  599. initSlider();
  600. } else {
  601. $('.box-shear-plate').append('<img class="empty" src="img/jianqieban_pic@2x.png" alt="" /><div class="empty-txt">剪贴板为空</div>')
  602. $('.mask').show();
  603. }
  604. }
  605. })
  606. })
  607. }
  608. //防止提示一秒内重复显示
  609. function stopManyClick(fn) {
  610. if (isFlag) {
  611. fn();
  612. }
  613. isFlag = false;
  614. if (timer) { clearTimeout(timer); }
  615. timer = setTimeout(() => { isFlag = true }, 1500);
  616. }
  617. // 清空剪贴板
  618. function handleClear() {
  619. var ids = '';
  620. cutList.forEach(function (item) {
  621. ids += 'ids=' + item.id + '&'
  622. });
  623. ids = ids.substring(0, ids.lastIndexOf('&'));
  624. $.confirm("确定清空剪贴板?", function () {
  625. $.ajax({
  626. url: baseUrl + "/api/public/v5/shear/content?" + ids,
  627. headers: {
  628. 'Authorization': form.token
  629. },
  630. type: 'DELETE',
  631. dataType: 'json',
  632. success: function (res) {
  633. if (res.status === 0) {
  634. showShearPlate();
  635. } else {
  636. $.toast(res.msg, "text");
  637. }
  638. }
  639. })
  640. });
  641. }
  642. function handleCopy(content) {
  643. var cutting = {
  644. "type": "cutting",
  645. "data": {
  646. "str": content
  647. }
  648. };
  649. wsss.send(JSON.stringify(cutting));
  650. }
  651. // 删除剪贴板
  652. function handleDelete(id) {
  653. $.ajax({
  654. url: baseUrl + "/api/public/v5/shear/content?ids=" + id,
  655. headers: {
  656. 'Authorization': form.token
  657. },
  658. type: 'DELETE',
  659. dataType: 'json',
  660. success: function (res) {
  661. if (res.status === 0) {
  662. showShearPlate();
  663. } else {
  664. $.toast(res.msg, "text");
  665. }
  666. }
  667. })
  668. }
  669. function initSlider() {
  670. //手指滑动多少距离就认为是滑成功
  671. //这个值不能太大,否则影响斜着滑动时,垂直滑动的流畅性,也不能太小,太灵敏也不好
  672. var diffXDistance = 50;
  673. //当前滑动的对象
  674. var currentObject;
  675. //上一次滑动的对象
  676. var lastObject;
  677. //是否可以左右滑动,在上下滑的时候禁止左右滑
  678. var canSlide = true;
  679. //用于记录按下的点
  680. var startPoint;
  681. $(".slide-content").css({
  682. width: $(".slide-wrapper").width()
  683. });
  684. document.body.removeEventListener('touchmove', function (e) {
  685. e.preventDefault()
  686. }, {
  687. passive: false
  688. })
  689. $(".slide-scroll").css({
  690. width: $(".slide-wrapper").width() + $(".slide-content-button").width()
  691. }).on('touchstart', function (e) {
  692. currentObject = this;
  693. startPoint = {
  694. x: e.originalEvent.changedTouches[0].pageX,
  695. y: e.originalEvent.changedTouches[0].pageY
  696. };
  697. }).on('touchmove', function (e) {
  698. //如果是左右滑动,就禁止上下的滑动
  699. //如果是上下的滑动,就禁止左右滑动
  700. if (Math.abs(e.originalEvent.changedTouches[0].pageX - startPoint.x) > Math.abs(e.originalEvent.changedTouches[0].pageY - startPoint.y)) {
  701. event.preventDefault();
  702. } else {
  703. canSlide = false;
  704. }
  705. }).on('touchend', function (e) {
  706. //如果是上下滑动,这里就直接返回了
  707. if (!canSlide) {
  708. canSlide = true;
  709. return true;
  710. }
  711. //点击除当前左滑对象之外的任意其他位置
  712. if (lastObject && currentObject != lastObject) {
  713. //右滑→
  714. $(lastObject).removeClass("animate-slide");
  715. //清空上一个左滑的对象
  716. lastObject = undefined;
  717. }
  718. var diffX = e.originalEvent.changedTouches[0].pageX - startPoint.x;
  719. if (diffX < -diffXDistance) {
  720. //左滑←
  721. $(currentObject).addClass("animate-slide");
  722. if (lastObject && lastObject != currentObject) {
  723. //右滑→
  724. $(lastObject).removeClass("animate-slide");
  725. }
  726. //记录上一个左滑的对象
  727. lastObject = currentObject;
  728. } else if (diffX >= diffXDistance) {
  729. if (currentObject == lastObject) {
  730. //右滑→
  731. $(currentObject).removeClass("animate-slide");
  732. //清空上一个左滑的对象
  733. lastObject = undefined;
  734. }
  735. }
  736. });
  737. }
  738. var btnMuted = document.querySelector("#btnMuted");
  739. btnMuted && (function () {
  740. var setHistory = function (left, top) {
  741. try {
  742. localStorage.setItem("muted-btn-loc", JSON.stringify({
  743. left: left,
  744. top: top
  745. }));
  746. } catch (ex) { }
  747. };
  748. var getHistory = function () {
  749. try {
  750. var value = localStorage.getItem("muted-btn-loc");
  751. if (!value) return null;
  752. value = JSON.parse(value);
  753. if (!value) return null;
  754. return value;
  755. } catch (ex) {
  756. return null
  757. }
  758. };
  759. var fixLoc = function (loc) {
  760. var rect = btnMuted.getBoundingClientRect();
  761. rect = {
  762. top: rect.top,
  763. left: rect.left,
  764. width: rect.width,
  765. height: rect.height
  766. }; //部分低版本浏览器,该属性为只读
  767. if (loc) {
  768. rect.left = loc.left;
  769. rect.top = loc.top;
  770. }
  771. var minX = 0;
  772. var minY = 0;
  773. var docRect = document.documentElement.getBoundingClientRect();
  774. var maxY = docRect.height - rect.height;
  775. var maxX = docRect.width - rect.width;
  776. var left = rect.left;
  777. var top = rect.top;
  778. left = Math.min(left, maxX);
  779. left = Math.max(left, minX);
  780. top = Math.min(top, maxY);
  781. top = Math.max(top, minY);
  782. if (loc || top !== rect.top || left !== rect.left) {
  783. btnMuted.style.cssText += "left:" + left + "px;top:" + top + "px;";
  784. }
  785. }
  786. window.addEventListener("resize", function () {
  787. fixLoc();
  788. });
  789. var touchPoint = {
  790. pageY: 0,
  791. pageX: 0
  792. };
  793. var currentLoc = {
  794. top: 0,
  795. left: 0,
  796. curTop: 0,
  797. curLeft: 0
  798. };
  799. var toMove = false;
  800. var touchmove = function (e) {
  801. e.preventDefault();
  802. var point = e.changedTouches[0];
  803. var top = -touchPoint.pageY + point.pageY;
  804. var left = -touchPoint.pageX + point.pageX;
  805. if (toMove) {
  806. top += currentLoc.top;
  807. left += currentLoc.left;
  808. currentLoc.curLeft = left;
  809. currentLoc.curTop = top;
  810. btnMuted.style.cssText += "left:" + left + "px;top:" + top + "px;";
  811. } else {
  812. if (Math.abs(top) >= 5 || Math.abs(left) >= 5) {
  813. toMove = true;
  814. }
  815. }
  816. };
  817. var touchend = function () {
  818. window.removeEventListener("touchmove", touchmove, {
  819. passive: false
  820. });
  821. window.removeEventListener("touchend", touchend, {
  822. passive: false
  823. });
  824. if (toMove) {
  825. setHistory(currentLoc.curLeft, currentLoc.curTop);
  826. fixLoc();
  827. } else {
  828. //按点击处理
  829. var set = $('.control-right-img').attr("data-id")
  830. if (set == '1') {
  831. $('.control-right-img').attr({
  832. "data-id": "2"
  833. })
  834. $(".leftmains").css({
  835. "right": "0rem"
  836. })
  837. } else {
  838. $('.control-right-img').attr({
  839. "data-id": "1"
  840. })
  841. $(".leftmains").css({
  842. "right": "-4rem"
  843. })
  844. }
  845. }
  846. }
  847. btnMuted.addEventListener("touchstart", function (e) {
  848. e.preventDefault();
  849. toMove = false;
  850. var point = e.changedTouches[0];
  851. touchPoint.pageX = point.pageX;
  852. touchPoint.pageY = point.pageY;
  853. var rect = e.target.getBoundingClientRect();
  854. currentLoc.top = rect.top;
  855. currentLoc.left = rect.left;
  856. window.addEventListener("touchmove", touchmove, {
  857. passive: false
  858. });
  859. window.addEventListener("touchend", touchend, {
  860. passive: false
  861. });
  862. }, {
  863. passive: false
  864. });
  865. var history = getHistory();
  866. if (history) {
  867. fixLoc(history);
  868. }
  869. btnMuted.classList.remove("hide");
  870. })();
  871. $("#upload").on("click", function () {
  872. clearInterval(intervaler);
  873. ws.close();
  874. wsss.close();
  875. if (navigator.userAgent.toLowerCase().includes('toutiaomicroapp')) {
  876. tt.miniProgram.switchTab({
  877. url: '/pages/home/home'
  878. })
  879. } else {
  880. wx.miniProgram.switchTab({
  881. url: '/pages/home/home'
  882. })
  883. }
  884. })
  885. function selectText(x) {
  886. if (document.selection) {
  887. var range = document.body.createTextRange();
  888. range.moveToElementText(x);
  889. range.select();
  890. } else if (window.getSelection) {
  891. var selection = window.getSelection();
  892. var range = document.createRange();
  893. selection.removeAllRanges();
  894. range.selectNodeContents(x);
  895. selection.addRange(range);
  896. }
  897. }
  898. // 激活码广告相关配置
  899. function getConfigByPhoneType() {
  900. return new Promise((resolve, reject) => {
  901. $.ajax({
  902. url: baseUrl + "/api/pay/v5/trialCodeConfig/getConfigByPhoneType",
  903. headers: {
  904. 'Authorization': form.token
  905. },
  906. data: {
  907. userCardId: form.userCardId,
  908. phoneType: form.mealType
  909. },
  910. type: 'get',
  911. dataType: 'json',
  912. success: function (res) {
  913. console.log(res)
  914. let obj = res.data;
  915. if (res.status === 0) {
  916. resolve(obj)
  917. } else {
  918. $.toast(res.msg, "text");
  919. }
  920. }
  921. })
  922. })
  923. }
  924. //列表
  925. function getSetmealList() {
  926. return new Promise((resolve, reject) => {
  927. $.ajax({
  928. url: baseUrl + "/api/resources/v4/freetrial/setmeal/list",
  929. headers: {
  930. 'Authorization': form.token
  931. },
  932. type: 'get',
  933. dataType: 'json',
  934. success: function (res) {
  935. if (res.status === 0) {
  936. let list = res.data;
  937. list.map((item) => {
  938. if (item.phoneType === parameters['mealType']) {
  939. resolve(item)
  940. }
  941. })
  942. } else {
  943. $.toast(res.msg, "text");
  944. }
  945. }
  946. })
  947. })
  948. }
  949. //广告信息
  950. function adInit() {
  951. sourceType = parameters['sourceType'];
  952. if (sourceType == 1) {
  953. getSetmealList().then((res) => {
  954. if (res.pushFlowAdvert === 1) {
  955. getAdList(15);
  956. }
  957. if (res.intervalSwitch === 1) {
  958. let time = res.intervalAdvertDuration * 60 * 1000;
  959. setInterval(() => {
  960. $('.try-use-wrap').eq(0).hide();
  961. getAdList(16);
  962. }, time);
  963. }
  964. })
  965. } else if (sourceType == 2) {
  966. getConfigByPhoneType().then((res) => {
  967. if (res.isDisconnectionTime === 1) {
  968. let time = res.disconnectionTime * 60 * 1000;
  969. setTimeout(() => {
  970. disconnectionFlag = true;
  971. $('.buy-phone-wrap').eq(0).show();
  972. }, time);
  973. }
  974. if (res.isShowAd === 1) {
  975. getAdList(15);
  976. }
  977. if (res.isIntervalPlayAd === 1) {
  978. let time = res.intervalPlayAdTime * 60 * 1000;
  979. setInterval(() => {
  980. $('.try-use-wrap').eq(0).hide();
  981. getAdList(16);
  982. }, time);
  983. }
  984. })
  985. }
  986. }
  987. // 广告接口
  988. function getAdList(type) {
  989. adType = type;
  990. $.ajax({
  991. url: baseUrl + "/api/public/v5/advertising/getAdInfoByAdPlace",
  992. headers: {
  993. 'Authorization': form.token
  994. },
  995. data: JSON.stringify({
  996. adPlace: type,
  997. os: 0
  998. }),
  999. type: 'POST',
  1000. dataType: 'json',
  1001. contentType: "application/json;charset=UTF-8",
  1002. success: function (res) {
  1003. if (res.status === 0) {
  1004. let list = res.data;
  1005. let indexs = Math.floor(Math.random() * list.length);
  1006. videoTime = list[indexs].forcedTime;
  1007. // $('#source').src = list[0].adVideoBase.videoUrl;
  1008. $("#source").attr("src", list[indexs].adVideoBase.videoUrl);//更新url
  1009. $("#source").attr("autoplay", "true");//直接播放
  1010. videoTimer = setInterval(() => {
  1011. if (videoTime > 0) {
  1012. videoTime--;
  1013. $('.time-node').eq(0).text(videoTime + 's');
  1014. } else {
  1015. clearInterval(videoTimer);
  1016. $('.time-node').eq(0).text('');
  1017. }
  1018. }, 1000)
  1019. if (adType === 16 && sourceType == 1) { // 间隔广告和试用才上报
  1020. report(0);
  1021. }
  1022. $('.try-use-wrap').eq(0).show();
  1023. } else {
  1024. $.toast(res.msg, "text");
  1025. }
  1026. }
  1027. })
  1028. }
  1029. //间隔广告上报
  1030. function report(type) {
  1031. $.ajax({
  1032. url: baseUrl + "/api/resources/v1/trial/report",
  1033. headers: {
  1034. 'Authorization': form.token
  1035. },
  1036. data: JSON.stringify({
  1037. userCardId: form.userCardId,
  1038. reportType: type
  1039. }),
  1040. type: 'POST',
  1041. dataType: 'json',
  1042. contentType: "application/json;charset=UTF-8",
  1043. success: function (res) { }
  1044. })
  1045. }
  1046. //关闭广告
  1047. $('.time-close-wrap')[0].addEventListener('click', () => {
  1048. $('.buy-phone-wrap').eq(0).show();
  1049. })
  1050. // 点击取消
  1051. $('.cannel-btn')[0].addEventListener('click', () => {
  1052. $('.buy-phone-wrap').eq(0).hide();
  1053. if (disconnectionFlag || getDate) {//设置了断线时间,取消直接退出
  1054. systemBuriedPoint('激活码-断线-取消');
  1055. wx.miniProgram.switchTab({
  1056. url: '/pages/home/home'
  1057. })
  1058. return
  1059. }
  1060. let pointName = '';
  1061. if (sourceType == 1) {
  1062. pointName = videoTime == 0 ? '免费试用-关闭-取消' : '免费试用-强制关闭-取消';
  1063. } else {
  1064. pointName = videoTime == 0 ? '激活码-关闭-取消' : '激活码-强制关闭-取消';
  1065. }
  1066. systemBuriedPoint(pointName);
  1067. if (videoTime == 0) {
  1068. if (adType === 16 && sourceType == 1) {
  1069. report(1);
  1070. }
  1071. $('.try-use-wrap').eq(0).hide();
  1072. return
  1073. }
  1074. $('.look-wrap').eq(0).show();
  1075. })
  1076. // 点击去购买
  1077. $('.go-bug')[0].addEventListener('click', () => {
  1078. let pointName = '';
  1079. if (disconnectionFlag) {
  1080. pointName = '激活码-断线-去购买';
  1081. } else if (sourceType == 1) {
  1082. pointName = videoTime == 0 ? '免费试用-关闭-去购买' : '免费试用-强制关闭-去购买';
  1083. } else {
  1084. pointName = videoTime == 0 ? '激活码-关闭-去购买' : '激活码-强制关闭-去购买';
  1085. }
  1086. systemBuriedPoint(pointName);
  1087. if (getDate) {
  1088. wx.miniProgram.navigateTo({
  1089. url: '/packageA/order/buy/index'
  1090. })
  1091. } else {
  1092. wx.miniProgram.navigateTo({
  1093. url: '/packageA/order/renew/index?record=' + form.userCardId
  1094. })
  1095. }
  1096. })
  1097. // 放弃
  1098. $('.cannel-ad-btn')[0].addEventListener('click', () => {
  1099. if (sourceType == 1) {
  1100. systemBuriedPoint('免费试用-强制关闭-放弃');
  1101. } else {
  1102. systemBuriedPoint('激活码-强制关闭-放弃');
  1103. }
  1104. wx.miniProgram.switchTab({
  1105. url: '/pages/home/home'
  1106. })
  1107. })
  1108. // 继续观看
  1109. $('.looking')[0].addEventListener('click', () => {
  1110. $('.look-wrap').eq(0).hide();
  1111. if (sourceType == 1) {
  1112. systemBuriedPoint('免费试用-强制关闭-继续观看');
  1113. } else {
  1114. systemBuriedPoint('激活码-强制关闭-继续观看');
  1115. }
  1116. })
  1117. // 埋点
  1118. function systemBuriedPoint(pointName) {
  1119. $.ajax({
  1120. url: baseUrl + "/api/public/v1/systemBuriedPoint/stat",
  1121. headers: {
  1122. 'Authorization': form.token
  1123. },
  1124. type: 'post',
  1125. data: JSON.stringify({
  1126. pointName: pointName
  1127. }),
  1128. contentType: "application/json",
  1129. dataType: 'json',
  1130. success: function (res) { }
  1131. })
  1132. }
  1133. window.onbeforeunload = function () {
  1134. ws.close();
  1135. wsss.close();
  1136. }
  1137. </script>
  1138. <script type="text/javascript" src="aac.js"></script>
  1139. </body>
  1140. </html>